Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 17:01:39 GMT
  2. Package jalview.util

File SparseCountTest.java

 

Code metrics

0
40
6
1
111
74
6
0.15
6.67
6
1

Classes

Class Line # Actions
SparseCountTest 32 40 6
0.00%
 

Contributing tests

No tests hitting this source file were found.

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   
 
32    public class SparseCountTest
33    {
34   
 
35  0 toggle @BeforeClass(alwaysRun = true)
36    public void setUpJvOptionPane()
37    {
38  0 JvOptionPane.setInteractiveMode(false);
39  0 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
40    }
41   
 
42  0 toggle @Test(groups = "Functional")
43    public void testAdd()
44    {
45  0 SparseCount p = new SparseCount(8);
46  0 p.add('a', 1);
47  0 p.add('b', 2);
48  0 p.add('a', 3);
49  0 p.add('b', -4);
50  0 assertEquals(p.size(), 2);
51  0 assertEquals(p.get('a'), 4);
52  0 assertEquals(p.get('b'), -2);
53    }
54   
 
55  0 toggle @Test(groups = "Functional")
56    public void testPut()
57    {
58  0 SparseCount p = new SparseCount(8);
59  0 p.put('a', 3);
60  0 p.add('b', 2);
61  0 p.put('b', 4);
62  0 assertEquals(p.size(), 2);
63  0 assertEquals(p.get('a'), 3);
64  0 assertEquals(p.get('b'), 4);
65    }
66   
67    /**
68    * Test handling overflow of short by switching to counting ints
69    */
 
70  0 toggle @Test(groups = "Functional")
71    public void testOverflow()
72    {
73  0 SparseCount p = new SparseCount(8);
74  0 p.put('a', Short.MAX_VALUE - 1);
75  0 p.add('a', 1);
76  0 assertFalse(p.isUsingInt());
77  0 p.add('a', 1);
78  0 assertTrue(p.isUsingInt());
79    }
80   
81    /**
82    * Test handling underflow of short by switching to counting ints
83    */
 
84  0 toggle @Test(groups = "Functional")
85    public void testUnderflow()
86    {
87  0 SparseCount p = new SparseCount(8);
88  0 p.put('a', Short.MIN_VALUE + 1);
89  0 p.add('a', -1);
90  0 assertFalse(p.isUsingInt());
91  0 p.add('a', -1);
92  0 assertTrue(p.isUsingInt());
93    }
94   
 
95  0 toggle @Test(groups = "Functional")
96    public void testKeyAt_ValueAt()
97    {
98  0 SparseCount p = new SparseCount(8);
99  0 p.put('W', 12);
100  0 p.put('K', 9);
101  0 p.put('R', 6);
102  0 assertEquals(p.size(), 3);
103  0 assertEquals(p.keyAt(0), 'K');
104  0 assertEquals(p.valueAt(0), 9);
105  0 assertEquals(p.keyAt(1), 'R');
106  0 assertEquals(p.valueAt(1), 6);
107  0 assertEquals(p.keyAt(2), 'W');
108  0 assertEquals(p.valueAt(2), 12);
109    }
110   
111    }