1 package jalview.ext.android;
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.fail;
6 import org.testng.annotations.Test;
9 * Tests for SparseIntArray. Unlike SparseShortArray, SparseIntArray does not throw
10 * any exception for overflow.
12 public class SparseIntArrayTest
14 @Test(groups = "Functional")
17 SparseIntArray counter = new SparseIntArray();
20 * either key or value may be in the range of int
22 counter.put(Integer.MAX_VALUE, Integer.MIN_VALUE);
23 counter.put(Integer.MIN_VALUE, Integer.MAX_VALUE);
24 assertEquals(counter.get(Integer.MAX_VALUE), Integer.MIN_VALUE);
25 assertEquals(counter.get(Integer.MIN_VALUE), Integer.MAX_VALUE);
28 @Test(groups = "Functional")
31 SparseIntArray counter = new SparseIntArray();
33 assertEquals(counter.add('P', 2), 2);
34 assertEquals(counter.add('P', 3), 5);
36 assertEquals(counter.add('Q', 4), 11);
38 counter.put('x', Integer.MAX_VALUE);
42 fail("expected exception");
43 } catch (ArithmeticException e)
48 counter.put('y', Integer.MIN_VALUE);
52 fail("expected exception");
53 } catch (ArithmeticException e)
59 @Test(groups = "Functional")
60 public void testCheckOverflow()
62 // things that don't overflow:
63 SparseIntArray.checkOverflow(Integer.MAX_VALUE, 0);
64 SparseIntArray.checkOverflow(Integer.MAX_VALUE, -1);
65 SparseIntArray.checkOverflow(Integer.MAX_VALUE, Integer.MIN_VALUE);
66 SparseIntArray.checkOverflow(Integer.MAX_VALUE, -Integer.MAX_VALUE);
67 SparseIntArray.checkOverflow(0, -Integer.MAX_VALUE);
68 SparseIntArray.checkOverflow(0, Integer.MIN_VALUE);
69 SparseIntArray.checkOverflow(Integer.MIN_VALUE, 0);
70 SparseIntArray.checkOverflow(Integer.MIN_VALUE, 1);
71 SparseIntArray.checkOverflow(Integer.MIN_VALUE, Integer.MAX_VALUE);
76 SparseIntArray.checkOverflow(Integer.MAX_VALUE, 1);
77 fail("expected exception");
78 } catch (ArithmeticException e)
84 SparseIntArray.checkOverflow(Integer.MAX_VALUE - 1, 2);
85 fail("expected exception");
86 } catch (ArithmeticException e)
92 SparseIntArray.checkOverflow(1, Integer.MAX_VALUE);
93 fail("expected exception");
94 } catch (ArithmeticException e)
100 SparseIntArray.checkOverflow(Integer.MIN_VALUE, -1);
101 fail("expected exception");
102 } catch (ArithmeticException e)
108 SparseIntArray.checkOverflow(Integer.MIN_VALUE + 1, -2);
109 fail("expected exception");
110 } catch (ArithmeticException e)
116 SparseIntArray.checkOverflow(-1, Integer.MIN_VALUE);
117 fail("expected exception");
118 } catch (ArithmeticException e)