Clover icon

Coverage Report

  1. Project Clover database Fri Dec 6 2024 13:47:14 GMT
  2. Package jalview.ext.android

File SparseIntArrayTest.java

 

Code metrics

0
47
4
1
155
104
12
0.26
11.75
4
3

Classes

Class Line # Actions
SparseIntArrayTest 35 47 12
0.8431372684.3%
 

Contributing tests

This file is covered by 3 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.ext.android;
22   
23    import static org.testng.Assert.assertEquals;
24    import static org.testng.Assert.fail;
25   
26    import jalview.gui.JvOptionPane;
27   
28    import org.testng.annotations.BeforeClass;
29    import org.testng.annotations.Test;
30   
31    /*
32    * Tests for SparseIntArray. Unlike SparseShortArray, SparseIntArray does not throw
33    * any exception for overflow.
34    */
 
35    public class SparseIntArrayTest
36    {
37   
 
38  1 toggle @BeforeClass(alwaysRun = true)
39    public void setUpJvOptionPane()
40    {
41  1 JvOptionPane.setInteractiveMode(false);
42  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
43    }
44   
 
45  1 toggle @Test(groups = "Functional")
46    public void testPut()
47    {
48  1 SparseIntArray counter = new SparseIntArray();
49   
50    /*
51    * either key or value may be in the range of int
52    */
53  1 counter.put(Integer.MAX_VALUE, Integer.MIN_VALUE);
54  1 counter.put(Integer.MIN_VALUE, Integer.MAX_VALUE);
55  1 assertEquals(counter.get(Integer.MAX_VALUE), Integer.MIN_VALUE);
56  1 assertEquals(counter.get(Integer.MIN_VALUE), Integer.MAX_VALUE);
57    }
58   
 
59  1 toggle @Test(groups = "Functional")
60    public void testAdd()
61    {
62  1 SparseIntArray counter = new SparseIntArray();
63   
64  1 assertEquals(counter.add('P', 2), 2);
65  1 assertEquals(counter.add('P', 3), 5);
66  1 counter.put('Q', 7);
67  1 assertEquals(counter.add('Q', 4), 11);
68   
69  1 counter.put('x', Integer.MAX_VALUE);
70  1 try
71    {
72  1 counter.add('x', 1);
73  0 fail("expected exception");
74    } catch (ArithmeticException e)
75    {
76    // expected
77    }
78   
79  1 counter.put('y', Integer.MIN_VALUE);
80  1 try
81    {
82  1 counter.add('y', -1);
83  0 fail("expected exception");
84    } catch (ArithmeticException e)
85    {
86    // expected
87    }
88    }
89   
 
90  1 toggle @Test(groups = "Functional")
91    public void testCheckOverflow()
92    {
93    // things that don't overflow:
94  1 SparseIntArray.checkOverflow(Integer.MAX_VALUE, 0);
95  1 SparseIntArray.checkOverflow(Integer.MAX_VALUE, -1);
96  1 SparseIntArray.checkOverflow(Integer.MAX_VALUE, Integer.MIN_VALUE);
97  1 SparseIntArray.checkOverflow(Integer.MAX_VALUE, -Integer.MAX_VALUE);
98  1 SparseIntArray.checkOverflow(0, -Integer.MAX_VALUE);
99  1 SparseIntArray.checkOverflow(0, Integer.MIN_VALUE);
100  1 SparseIntArray.checkOverflow(Integer.MIN_VALUE, 0);
101  1 SparseIntArray.checkOverflow(Integer.MIN_VALUE, 1);
102  1 SparseIntArray.checkOverflow(Integer.MIN_VALUE, Integer.MAX_VALUE);
103   
104    // and some that do
105  1 try
106    {
107  1 SparseIntArray.checkOverflow(Integer.MAX_VALUE, 1);
108  0 fail("expected exception");
109    } catch (ArithmeticException e)
110    {
111    // expected
112    }
113  1 try
114    {
115  1 SparseIntArray.checkOverflow(Integer.MAX_VALUE - 1, 2);
116  0 fail("expected exception");
117    } catch (ArithmeticException e)
118    {
119    // expected
120    }
121  1 try
122    {
123  1 SparseIntArray.checkOverflow(1, Integer.MAX_VALUE);
124  0 fail("expected exception");
125    } catch (ArithmeticException e)
126    {
127    // expected
128    }
129  1 try
130    {
131  1 SparseIntArray.checkOverflow(Integer.MIN_VALUE, -1);
132  0 fail("expected exception");
133    } catch (ArithmeticException e)
134    {
135    // expected
136    }
137  1 try
138    {
139  1 SparseIntArray.checkOverflow(Integer.MIN_VALUE + 1, -2);
140  0 fail("expected exception");
141    } catch (ArithmeticException e)
142    {
143    // expected
144    }
145  1 try
146    {
147  1 SparseIntArray.checkOverflow(-1, Integer.MIN_VALUE);
148  0 fail("expected exception");
149    } catch (ArithmeticException e)
150    {
151    // expected
152    }
153    }
154   
155    }