1 package jalview.ext.android;
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.fail;
6 import jalview.gui.JvOptionPane;
8 import org.testng.annotations.BeforeClass;
9 import org.testng.annotations.Test;
12 * Tests for SparseIntArray. Unlike SparseShortArray, SparseIntArray does not throw
13 * any exception for overflow.
15 public class SparseIntArrayTest
18 @BeforeClass(alwaysRun = true)
19 public void setUpJvOptionPane()
21 JvOptionPane.setInteractiveMode(false);
22 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
25 @Test(groups = "Functional")
28 SparseIntArray counter = new SparseIntArray();
31 * either key or value may be in the range of int
33 counter.put(Integer.MAX_VALUE, Integer.MIN_VALUE);
34 counter.put(Integer.MIN_VALUE, Integer.MAX_VALUE);
35 assertEquals(counter.get(Integer.MAX_VALUE), Integer.MIN_VALUE);
36 assertEquals(counter.get(Integer.MIN_VALUE), Integer.MAX_VALUE);
39 @Test(groups = "Functional")
42 SparseIntArray counter = new SparseIntArray();
44 assertEquals(counter.add('P', 2), 2);
45 assertEquals(counter.add('P', 3), 5);
47 assertEquals(counter.add('Q', 4), 11);
49 counter.put('x', Integer.MAX_VALUE);
53 fail("expected exception");
54 } catch (ArithmeticException e)
59 counter.put('y', Integer.MIN_VALUE);
63 fail("expected exception");
64 } catch (ArithmeticException e)
70 @Test(groups = "Functional")
71 public void testCheckOverflow()
73 // things that don't overflow:
74 SparseIntArray.checkOverflow(Integer.MAX_VALUE, 0);
75 SparseIntArray.checkOverflow(Integer.MAX_VALUE, -1);
76 SparseIntArray.checkOverflow(Integer.MAX_VALUE, Integer.MIN_VALUE);
77 SparseIntArray.checkOverflow(Integer.MAX_VALUE, -Integer.MAX_VALUE);
78 SparseIntArray.checkOverflow(0, -Integer.MAX_VALUE);
79 SparseIntArray.checkOverflow(0, Integer.MIN_VALUE);
80 SparseIntArray.checkOverflow(Integer.MIN_VALUE, 0);
81 SparseIntArray.checkOverflow(Integer.MIN_VALUE, 1);
82 SparseIntArray.checkOverflow(Integer.MIN_VALUE, Integer.MAX_VALUE);
87 SparseIntArray.checkOverflow(Integer.MAX_VALUE, 1);
88 fail("expected exception");
89 } catch (ArithmeticException e)
95 SparseIntArray.checkOverflow(Integer.MAX_VALUE - 1, 2);
96 fail("expected exception");
97 } catch (ArithmeticException e)
103 SparseIntArray.checkOverflow(1, Integer.MAX_VALUE);
104 fail("expected exception");
105 } catch (ArithmeticException e)
111 SparseIntArray.checkOverflow(Integer.MIN_VALUE, -1);
112 fail("expected exception");
113 } catch (ArithmeticException e)
119 SparseIntArray.checkOverflow(Integer.MIN_VALUE + 1, -2);
120 fail("expected exception");
121 } catch (ArithmeticException e)
127 SparseIntArray.checkOverflow(-1, Integer.MIN_VALUE);
128 fail("expected exception");
129 } catch (ArithmeticException e)