3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertFalse;
5 import static org.testng.Assert.assertTrue;
7 import jalview.gui.JvOptionPane;
9 import org.testng.annotations.BeforeClass;
10 import org.testng.annotations.Test;
11 public class SparseCountTest
14 @BeforeClass(alwaysRun = true)
15 public void setUpJvOptionPane()
17 JvOptionPane.setInteractiveMode(false);
18 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
21 @Test(groups = "Functional")
24 SparseCount p = new SparseCount(8);
29 assertEquals(p.size(), 2);
30 assertEquals(p.get('a'), 4);
31 assertEquals(p.get('b'), -2);
34 @Test(groups = "Functional")
37 SparseCount p = new SparseCount(8);
41 assertEquals(p.size(), 2);
42 assertEquals(p.get('a'), 3);
43 assertEquals(p.get('b'), 4);
47 * Test handling overflow of short by switching to counting ints
49 @Test(groups = "Functional")
50 public void testOverflow()
52 SparseCount p = new SparseCount(8);
53 p.put('a', Short.MAX_VALUE - 1);
55 assertFalse(p.isUsingInt());
57 assertTrue(p.isUsingInt());
61 * Test handling underflow of short by switching to counting ints
63 @Test(groups = "Functional")
64 public void testUnderflow()
66 SparseCount p = new SparseCount(8);
67 p.put('a', Short.MIN_VALUE + 1);
69 assertFalse(p.isUsingInt());
71 assertTrue(p.isUsingInt());
74 @Test(groups = "Functional")
75 public void testKeyAt_ValueAt()
77 SparseCount p = new SparseCount(8);
81 assertEquals(p.size(), 3);
82 assertEquals(p.keyAt(0), 'K');
83 assertEquals(p.valueAt(0), 9);
84 assertEquals(p.keyAt(1), 'R');
85 assertEquals(p.valueAt(1), 6);
86 assertEquals(p.keyAt(2), 'W');
87 assertEquals(p.valueAt(2), 12);