|
22 | 22 |
|
23 | 23 | import static org.junit.Assert.assertArrayEquals; |
24 | 24 | import static org.junit.Assert.assertEquals; |
| 25 | +import static org.junit.Assert.fail; |
25 | 26 |
|
26 | 27 | public abstract class IntListTestSuite { |
27 | 28 | protected IntList actual; |
@@ -50,6 +51,22 @@ public void testElements() { |
50 | 51 | } |
51 | 52 | } |
52 | 53 |
|
| 54 | + @Test |
| 55 | + public void testGetAtMinusOne() { |
| 56 | + try { |
| 57 | + actual.get(-1); |
| 58 | + fail(); |
| 59 | + } catch (IndexOutOfBoundsException ignored) { } |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + public void testGetAtLength() { |
| 64 | + try { |
| 65 | + actual.get(expected.length); |
| 66 | + fail(); |
| 67 | + } catch (IndexOutOfBoundsException ignored) { } |
| 68 | + } |
| 69 | + |
53 | 70 | @Test |
54 | 71 | public void testCopyFull() { |
55 | 72 | int[] array = new int[expected.length]; |
@@ -90,13 +107,38 @@ public void testCopyAtEnd() { |
90 | 107 | assertArrayEquals(copiedChunk, expected); |
91 | 108 | } |
92 | 109 |
|
| 110 | + @Test |
| 111 | + public void testCopyToNullArray() { |
| 112 | + try { |
| 113 | + actual.copyTo(null, 0); |
| 114 | + fail(); |
| 115 | + } catch (NullPointerException ignored) { } |
| 116 | + } |
| 117 | + |
| 118 | + @Test |
| 119 | + public void testCopyToSmallArray() { |
| 120 | + if (expected.length == 0) { |
| 121 | + return; |
| 122 | + } |
| 123 | + |
| 124 | + try { |
| 125 | + int[] array = new int[expected.length / 2]; |
| 126 | + actual.copyTo(array, 0); |
| 127 | + fail(); |
| 128 | + } catch (ArrayIndexOutOfBoundsException ignored) { } |
| 129 | + } |
| 130 | + |
93 | 131 | private static void testSubList(IntList subList, int[] expected) { |
94 | 132 | SubListTestSuite suite = new SubListTestSuite(subList, expected); |
95 | 133 | suite.testSize(); |
96 | 134 | suite.testElements(); |
| 135 | + suite.testGetAtMinusOne(); |
| 136 | + suite.testGetAtLength(); |
97 | 137 | suite.testCopyFull(); |
98 | 138 | suite.testCopyAtStart(); |
99 | 139 | suite.testCopyAtEnd(); |
| 140 | + suite.testCopyToNullArray(); |
| 141 | + suite.testCopyToSmallArray(); |
100 | 142 | suite.testToArray(); |
101 | 143 | suite.testEquals(); |
102 | 144 | } |
|
0 commit comments