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.
21 package jalview.ext.android;
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.fail;
26 import jalview.gui.JvOptionPane;
28 import org.testng.annotations.BeforeClass;
29 import org.testng.annotations.Test;
32 * Tests for SparseIntArray. Unlike SparseShortArray, SparseIntArray does not throw
33 * any exception for overflow.
35 public class SparseIntArrayTest
38 @BeforeClass(alwaysRun = true)
39 public void setUpJvOptionPane()
41 JvOptionPane.setInteractiveMode(false);
42 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
45 @Test(groups = "Functional")
48 SparseIntArray counter = new SparseIntArray();
51 * either key or value may be in the range of int
53 counter.put(Integer.MAX_VALUE, Integer.MIN_VALUE);
54 counter.put(Integer.MIN_VALUE, Integer.MAX_VALUE);
55 assertEquals(counter.get(Integer.MAX_VALUE), Integer.MIN_VALUE);
56 assertEquals(counter.get(Integer.MIN_VALUE), Integer.MAX_VALUE);
59 @Test(groups = "Functional")
62 SparseIntArray counter = new SparseIntArray();
64 assertEquals(counter.add('P', 2), 2);
65 assertEquals(counter.add('P', 3), 5);
67 assertEquals(counter.add('Q', 4), 11);
69 counter.put('x', Integer.MAX_VALUE);
73 fail("expected exception");
74 } catch (ArithmeticException e)
79 counter.put('y', Integer.MIN_VALUE);
83 fail("expected exception");
84 } catch (ArithmeticException e)
90 @Test(groups = "Functional")
91 public void testCheckOverflow()
93 // things that don't overflow:
94 SparseIntArray.checkOverflow(Integer.MAX_VALUE, 0);
95 SparseIntArray.checkOverflow(Integer.MAX_VALUE, -1);
96 SparseIntArray.checkOverflow(Integer.MAX_VALUE, Integer.MIN_VALUE);
97 SparseIntArray.checkOverflow(Integer.MAX_VALUE, -Integer.MAX_VALUE);
98 SparseIntArray.checkOverflow(0, -Integer.MAX_VALUE);
99 SparseIntArray.checkOverflow(0, Integer.MIN_VALUE);
100 SparseIntArray.checkOverflow(Integer.MIN_VALUE, 0);
101 SparseIntArray.checkOverflow(Integer.MIN_VALUE, 1);
102 SparseIntArray.checkOverflow(Integer.MIN_VALUE, Integer.MAX_VALUE);
107 SparseIntArray.checkOverflow(Integer.MAX_VALUE, 1);
108 fail("expected exception");
109 } catch (ArithmeticException e)
115 SparseIntArray.checkOverflow(Integer.MAX_VALUE - 1, 2);
116 fail("expected exception");
117 } catch (ArithmeticException e)
123 SparseIntArray.checkOverflow(1, Integer.MAX_VALUE);
124 fail("expected exception");
125 } catch (ArithmeticException e)
131 SparseIntArray.checkOverflow(Integer.MIN_VALUE, -1);
132 fail("expected exception");
133 } catch (ArithmeticException e)
139 SparseIntArray.checkOverflow(Integer.MIN_VALUE + 1, -2);
140 fail("expected exception");
141 } catch (ArithmeticException e)
147 SparseIntArray.checkOverflow(-1, Integer.MIN_VALUE);
148 fail("expected exception");
149 } catch (ArithmeticException e)