PageRenderTime 16ms CodeModel.GetById 11ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/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 */
16package org.diffkit.common.tst
17
18
19
20
21import org.apache.commons.collections.bidimap.TreeBidiMap 
22import org.diffkit.common.DKCountingBag 
23
24import groovy.util.GroovyTestCase;
25
26
27/**
28 * @author jpanico
29 */
30public class TestCountingBag extends GroovyTestCase {
31      
32   
33   public void testCount(){
34      DKCountingBag target = []
35      assert target.getCount(null) == 0
36      def key1 = 'key1'
37      def key2 = 'key2'
38      def key3 = 'aaaa'
39      assert target.getCount(key1)== 0
40      
41      target.add(key1)
42      assert target.getCount(key1) == 1
43      assert target.getCount(key2)== 0
44      assert target.totalCount() == 1
45      
46      target.add(key1,2)
47      assert target.getCount(key1) == 3
48      assert target.getCount(key2)== 0
49      assert target.totalCount() == 3
50      
51      target.add(key2,5)
52      assert target.getCount(key1) == 3
53      assert target.getCount(key2)== 5
54      assert target.totalCount() == 8
55      
56      target.add(key3)
57      assert target.getCount(key1) == 3
58      assert target.getCount(key2)== 5
59      assert target.getCount(key3)== 1
60      assert target.totalCount() == 9
61      
62      Iterator iterator = target.iterator()
63      assert iterator.next() == key2
64      assert iterator.next() == key1
65      assert iterator.next() == key3
66   }
67}