JAL-2326 added setup method for JvOptionPane in all Jalveiw test classes to enable...
[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 jalview.gui.JvOptionPane;
7
8 import org.testng.annotations.BeforeClass;
9 import org.testng.annotations.Test;
10
11 public class SparseShortArrayTest
12 {
13
14   @BeforeClass(alwaysRun = true)
15   public void setUpJvOptionPane()
16   {
17     JvOptionPane.setInteractiveMode(false);
18     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
19   }
20
21   @Test(groups = "Functional")
22   public void testPut()
23   {
24     SparseShortArray counter = new SparseShortArray();
25
26     /*
27      * either key or value may be in the range of short
28      */
29     counter.put(Short.MAX_VALUE, Short.MIN_VALUE);
30     counter.put(Short.MIN_VALUE, Short.MAX_VALUE);
31
32     // put a too large value
33     try
34     {
35       counter.put(0, Short.MAX_VALUE + 1);
36       fail("Expected exception");
37     } catch (ArithmeticException e)
38     {
39       // expected;
40     }
41
42     // put a too small value
43     try
44     {
45       counter.put(1, Short.MIN_VALUE - 1);
46       fail("Expected exception");
47     } catch (ArithmeticException e)
48     {
49       // expected;
50     }
51
52     // put a too large key
53     try
54     {
55       counter.put(Short.MAX_VALUE + 1, 0);
56       fail("Expected exception");
57     } catch (ArithmeticException e)
58     {
59       // expected;
60     }
61
62     // put a too small key
63     try
64     {
65       counter.put(Short.MIN_VALUE - 1, 2);
66       fail("Expected exception");
67     } catch (ArithmeticException e)
68     {
69       // expected;
70     }
71   }
72
73   @Test(groups = "Functional")
74   public void testAdd()
75   {
76     SparseShortArray counter = new SparseShortArray();
77   
78     assertEquals(counter.add('P', 2), 2);
79     assertEquals(counter.add('P', 3), 5);
80     counter.put('Q', 7);
81     assertEquals(counter.add('Q', 4), 11);
82
83     // increment giving overflow
84     counter.put('x', Short.MAX_VALUE);
85     try
86     {
87       counter.add('x', 1);
88       fail("Expected exception");
89     } catch (ArithmeticException e)
90     {
91       // expected;
92     }
93   
94     // decrement giving underflow
95     counter.put('y', Short.MIN_VALUE);
96     try
97     {
98       counter.add('y', -1);
99       fail("Expected exception");
100     } catch (ArithmeticException e)
101     {
102       // expected;
103     }
104   }
105 }