JAL-2325 update release date to next Tuesday
[jalview.git] / test / jalview / ext / android / SparseShortArrayTest.java
1 package jalview.ext.android;
2
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.fail;
5
6 import org.testng.annotations.Test;
7
8 public class SparseShortArrayTest
9 {
10   @Test(groups = "Functional")
11   public void testPut()
12   {
13     SparseShortArray counter = new SparseShortArray();
14
15     /*
16      * either key or value may be in the range of short
17      */
18     counter.put(Short.MAX_VALUE, Short.MIN_VALUE);
19     counter.put(Short.MIN_VALUE, Short.MAX_VALUE);
20
21     // put a too large value
22     try
23     {
24       counter.put(0, Short.MAX_VALUE + 1);
25       fail("Expected exception");
26     } catch (ArithmeticException e)
27     {
28       // expected;
29     }
30
31     // put a too small value
32     try
33     {
34       counter.put(1, Short.MIN_VALUE - 1);
35       fail("Expected exception");
36     } catch (ArithmeticException e)
37     {
38       // expected;
39     }
40
41     // put a too large key
42     try
43     {
44       counter.put(Short.MAX_VALUE + 1, 0);
45       fail("Expected exception");
46     } catch (ArithmeticException e)
47     {
48       // expected;
49     }
50
51     // put a too small key
52     try
53     {
54       counter.put(Short.MIN_VALUE - 1, 2);
55       fail("Expected exception");
56     } catch (ArithmeticException e)
57     {
58       // expected;
59     }
60   }
61
62   @Test(groups = "Functional")
63   public void testAdd()
64   {
65     SparseShortArray counter = new SparseShortArray();
66   
67     assertEquals(counter.add('P', 2), 2);
68     assertEquals(counter.add('P', 3), 5);
69     counter.put('Q', 7);
70     assertEquals(counter.add('Q', 4), 11);
71
72     // increment giving overflow
73     counter.put('x', Short.MAX_VALUE);
74     try
75     {
76       counter.add('x', 1);
77       fail("Expected exception");
78     } catch (ArithmeticException e)
79     {
80       // expected;
81     }
82   
83     // decrement giving underflow
84     counter.put('y', Short.MIN_VALUE);
85     try
86     {
87       counter.add('y', -1);
88       fail("Expected exception");
89     } catch (ArithmeticException e)
90     {
91       // expected;
92     }
93   }
94 }