/tst/org/diffkit/common/tst/TestCountingBag.groovy

http://diffkit.googlecode.com/ · Groovy · 67 lines · 35 code · 14 blank · 18 comment · 12 complexity · 27c8861257a2f702af66fc2f6c1aa4ea MD5 · raw file

  1. /**
  2. * Copyright 2010-2011 Joseph Panico
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.diffkit.common.tst
  17. import org.apache.commons.collections.bidimap.TreeBidiMap
  18. import org.diffkit.common.DKCountingBag
  19. import groovy.util.GroovyTestCase;
  20. /**
  21. * @author jpanico
  22. */
  23. public class TestCountingBag extends GroovyTestCase {
  24. public void testCount(){
  25. DKCountingBag target = []
  26. assert target.getCount(null) == 0
  27. def key1 = 'key1'
  28. def key2 = 'key2'
  29. def key3 = 'aaaa'
  30. assert target.getCount(key1)== 0
  31. target.add(key1)
  32. assert target.getCount(key1) == 1
  33. assert target.getCount(key2)== 0
  34. assert target.totalCount() == 1
  35. target.add(key1,2)
  36. assert target.getCount(key1) == 3
  37. assert target.getCount(key2)== 0
  38. assert target.totalCount() == 3
  39. target.add(key2,5)
  40. assert target.getCount(key1) == 3
  41. assert target.getCount(key2)== 5
  42. assert target.totalCount() == 8
  43. target.add(key3)
  44. assert target.getCount(key1) == 3
  45. assert target.getCount(key2)== 5
  46. assert target.getCount(key3)== 1
  47. assert target.totalCount() == 9
  48. Iterator iterator = target.iterator()
  49. assert iterator.next() == key2
  50. assert iterator.next() == key1
  51. assert iterator.next() == key3
  52. }
  53. }