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 org.testng.annotations.Test;
29 * Tests for SparseIntArray. Unlike SparseShortArray, SparseIntArray does not throw
30 * any exception for overflow.
32 public class SparseIntArrayTest
34 @Test(groups = "Functional")
37 SparseIntArray counter = new SparseIntArray();
40 * either key or value may be in the range of int
42 counter.put(Integer.MAX_VALUE, Integer.MIN_VALUE);
43 counter.put(Integer.MIN_VALUE, Integer.MAX_VALUE);
44 assertEquals(counter.get(Integer.MAX_VALUE), Integer.MIN_VALUE);
45 assertEquals(counter.get(Integer.MIN_VALUE), Integer.MAX_VALUE);
48 @Test(groups = "Functional")
51 SparseIntArray counter = new SparseIntArray();
53 assertEquals(counter.add('P', 2), 2);
54 assertEquals(counter.add('P', 3), 5);
56 assertEquals(counter.add('Q', 4), 11);
58 counter.put('x', Integer.MAX_VALUE);
62 fail("expected exception");
63 } catch (ArithmeticException e)
68 counter.put('y', Integer.MIN_VALUE);
72 fail("expected exception");
73 } catch (ArithmeticException e)
79 @Test(groups = "Functional")
80 public void testCheckOverflow()
82 // things that don't overflow:
83 SparseIntArray.checkOverflow(Integer.MAX_VALUE, 0);
84 SparseIntArray.checkOverflow(Integer.MAX_VALUE, -1);
85 SparseIntArray.checkOverflow(Integer.MAX_VALUE, Integer.MIN_VALUE);
86 SparseIntArray.checkOverflow(Integer.MAX_VALUE, -Integer.MAX_VALUE);
87 SparseIntArray.checkOverflow(0, -Integer.MAX_VALUE);
88 SparseIntArray.checkOverflow(0, Integer.MIN_VALUE);
89 SparseIntArray.checkOverflow(Integer.MIN_VALUE, 0);
90 SparseIntArray.checkOverflow(Integer.MIN_VALUE, 1);
91 SparseIntArray.checkOverflow(Integer.MIN_VALUE, Integer.MAX_VALUE);
96 SparseIntArray.checkOverflow(Integer.MAX_VALUE, 1);
97 fail("expected exception");
98 } catch (ArithmeticException e)
104 SparseIntArray.checkOverflow(Integer.MAX_VALUE - 1, 2);
105 fail("expected exception");
106 } catch (ArithmeticException e)
112 SparseIntArray.checkOverflow(1, Integer.MAX_VALUE);
113 fail("expected exception");
114 } catch (ArithmeticException e)
120 SparseIntArray.checkOverflow(Integer.MIN_VALUE, -1);
121 fail("expected exception");
122 } catch (ArithmeticException e)
128 SparseIntArray.checkOverflow(Integer.MIN_VALUE + 1, -2);
129 fail("expected exception");
130 } catch (ArithmeticException e)
136 SparseIntArray.checkOverflow(-1, Integer.MIN_VALUE);
137 fail("expected exception");
138 } catch (ArithmeticException e)