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;
11 public class SparseShortArrayTest
14 @BeforeClass(alwaysRun = true)
15 public void setUpJvOptionPane()
17 JvOptionPane.setInteractiveMode(false);
18 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
21 @Test(groups = "Functional")
24 SparseShortArray counter = new SparseShortArray();
27 * either key or value may be in the range of short
29 counter.put(Short.MAX_VALUE, Short.MIN_VALUE);
30 counter.put(Short.MIN_VALUE, Short.MAX_VALUE);
32 // put a too large value
35 counter.put(0, Short.MAX_VALUE + 1);
36 fail("Expected exception");
37 } catch (ArithmeticException e)
42 // put a too small value
45 counter.put(1, Short.MIN_VALUE - 1);
46 fail("Expected exception");
47 } catch (ArithmeticException e)
52 // put a too large key
55 counter.put(Short.MAX_VALUE + 1, 0);
56 fail("Expected exception");
57 } catch (ArithmeticException e)
62 // put a too small key
65 counter.put(Short.MIN_VALUE - 1, 2);
66 fail("Expected exception");
67 } catch (ArithmeticException e)
73 @Test(groups = "Functional")
76 SparseShortArray counter = new SparseShortArray();
78 assertEquals(counter.add('P', 2), 2);
79 assertEquals(counter.add('P', 3), 5);
81 assertEquals(counter.add('Q', 4), 11);
83 // increment giving overflow
84 counter.put('x', Short.MAX_VALUE);
88 fail("Expected exception");
89 } catch (ArithmeticException e)
94 // decrement giving underflow
95 counter.put('y', Short.MIN_VALUE);
99 fail("Expected exception");
100 } catch (ArithmeticException e)