3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertFalse;
5 import static org.testng.Assert.assertTrue;
7 import org.testng.annotations.Test;
8 public class SparseCountTest
10 @Test(groups = "Functional")
13 SparseCount p = new SparseCount(8);
18 assertEquals(p.size(), 2);
19 assertEquals(p.get('a'), 4);
20 assertEquals(p.get('b'), -2);
23 @Test(groups = "Functional")
26 SparseCount p = new SparseCount(8);
30 assertEquals(p.size(), 2);
31 assertEquals(p.get('a'), 3);
32 assertEquals(p.get('b'), 4);
36 * Test handling overflow of short by switching to counting ints
38 @Test(groups = "Functional")
39 public void testOverflow()
41 SparseCount p = new SparseCount(8);
42 p.put('a', Short.MAX_VALUE - 1);
44 assertFalse(p.isUsingInt());
46 assertTrue(p.isUsingInt());
50 * Test handling underflow of short by switching to counting ints
52 @Test(groups = "Functional")
53 public void testUnderflow()
55 SparseCount p = new SparseCount(8);
56 p.put('a', Short.MIN_VALUE + 1);
58 assertFalse(p.isUsingInt());
60 assertTrue(p.isUsingInt());
63 @Test(groups = "Functional")
64 public void testKeyAt_ValueAt()
66 SparseCount p = new SparseCount(8);
70 assertEquals(p.size(), 3);
71 assertEquals(p.keyAt(0), 'K');
72 assertEquals(p.valueAt(0), 9);
73 assertEquals(p.keyAt(1), 'R');
74 assertEquals(p.valueAt(1), 6);
75 assertEquals(p.keyAt(2), 'W');
76 assertEquals(p.valueAt(2), 12);