2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertFalse;
25 import static org.testng.Assert.assertTrue;
27 import jalview.gui.JvOptionPane;
29 import org.testng.annotations.BeforeClass;
30 import org.testng.annotations.Test;
31 public class SparseCountTest
34 @BeforeClass(alwaysRun = true)
35 public void setUpJvOptionPane()
37 JvOptionPane.setInteractiveMode(false);
38 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
41 @Test(groups = "Functional")
44 SparseCount p = new SparseCount(8);
49 assertEquals(p.size(), 2);
50 assertEquals(p.get('a'), 4);
51 assertEquals(p.get('b'), -2);
54 @Test(groups = "Functional")
57 SparseCount p = new SparseCount(8);
61 assertEquals(p.size(), 2);
62 assertEquals(p.get('a'), 3);
63 assertEquals(p.get('b'), 4);
67 * Test handling overflow of short by switching to counting ints
69 @Test(groups = "Functional")
70 public void testOverflow()
72 SparseCount p = new SparseCount(8);
73 p.put('a', Short.MAX_VALUE - 1);
75 assertFalse(p.isUsingInt());
77 assertTrue(p.isUsingInt());
81 * Test handling underflow of short by switching to counting ints
83 @Test(groups = "Functional")
84 public void testUnderflow()
86 SparseCount p = new SparseCount(8);
87 p.put('a', Short.MIN_VALUE + 1);
89 assertFalse(p.isUsingInt());
91 assertTrue(p.isUsingInt());
94 @Test(groups = "Functional")
95 public void testKeyAt_ValueAt()
97 SparseCount p = new SparseCount(8);
101 assertEquals(p.size(), 3);
102 assertEquals(p.keyAt(0), 'K');
103 assertEquals(p.valueAt(0), 9);
104 assertEquals(p.keyAt(1), 'R');
105 assertEquals(p.valueAt(1), 6);
106 assertEquals(p.keyAt(2), 'W');
107 assertEquals(p.valueAt(2), 12);