Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.util

File SparseCountTest.java

 

Code metrics

0
40
6
1
110
74
6
0.15
6.67
6
1

Classes

Class Line # Actions
SparseCountTest 31 40 6 0
1.0100%
 

Contributing tests

This file is covered by 5 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.util;
22   
23    import static org.testng.Assert.assertEquals;
24    import static org.testng.Assert.assertFalse;
25    import static org.testng.Assert.assertTrue;
26   
27    import jalview.gui.JvOptionPane;
28   
29    import org.testng.annotations.BeforeClass;
30    import org.testng.annotations.Test;
 
31    public class SparseCountTest
32    {
33   
 
34  1 toggle @BeforeClass(alwaysRun = true)
35    public void setUpJvOptionPane()
36    {
37  1 JvOptionPane.setInteractiveMode(false);
38  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
39    }
40   
 
41  1 toggle @Test(groups = "Functional")
42    public void testAdd()
43    {
44  1 SparseCount p = new SparseCount(8);
45  1 p.add('a', 1);
46  1 p.add('b', 2);
47  1 p.add('a', 3);
48  1 p.add('b', -4);
49  1 assertEquals(p.size(), 2);
50  1 assertEquals(p.get('a'), 4);
51  1 assertEquals(p.get('b'), -2);
52    }
53   
 
54  1 toggle @Test(groups = "Functional")
55    public void testPut()
56    {
57  1 SparseCount p = new SparseCount(8);
58  1 p.put('a', 3);
59  1 p.add('b', 2);
60  1 p.put('b', 4);
61  1 assertEquals(p.size(), 2);
62  1 assertEquals(p.get('a'), 3);
63  1 assertEquals(p.get('b'), 4);
64    }
65   
66    /**
67    * Test handling overflow of short by switching to counting ints
68    */
 
69  1 toggle @Test(groups = "Functional")
70    public void testOverflow()
71    {
72  1 SparseCount p = new SparseCount(8);
73  1 p.put('a', Short.MAX_VALUE - 1);
74  1 p.add('a', 1);
75  1 assertFalse(p.isUsingInt());
76  1 p.add('a', 1);
77  1 assertTrue(p.isUsingInt());
78    }
79   
80    /**
81    * Test handling underflow of short by switching to counting ints
82    */
 
83  1 toggle @Test(groups = "Functional")
84    public void testUnderflow()
85    {
86  1 SparseCount p = new SparseCount(8);
87  1 p.put('a', Short.MIN_VALUE + 1);
88  1 p.add('a', -1);
89  1 assertFalse(p.isUsingInt());
90  1 p.add('a', -1);
91  1 assertTrue(p.isUsingInt());
92    }
93   
 
94  1 toggle @Test(groups = "Functional")
95    public void testKeyAt_ValueAt()
96    {
97  1 SparseCount p = new SparseCount(8);
98  1 p.put('W', 12);
99  1 p.put('K', 9);
100  1 p.put('R', 6);
101  1 assertEquals(p.size(), 3);
102  1 assertEquals(p.keyAt(0), 'K');
103  1 assertEquals(p.valueAt(0), 9);
104  1 assertEquals(p.keyAt(1), 'R');
105  1 assertEquals(p.valueAt(1), 6);
106  1 assertEquals(p.keyAt(2), 'W');
107  1 assertEquals(p.valueAt(2), 12);
108    }
109   
110    }