1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 package org.eclipse.jgit.util;
45
46 import static org.junit.Assert.assertEquals;
47 import static org.junit.Assert.assertTrue;
48 import static org.junit.Assert.fail;
49
50 import org.junit.Test;
51
52 public class IntListTest {
53 @Test
54 public void testEmpty_DefaultCapacity() {
55 final IntList i = new IntList();
56 assertEquals(0, i.size());
57 try {
58 i.get(0);
59 fail("Accepted 0 index on empty list");
60 } catch (ArrayIndexOutOfBoundsException e) {
61 assertTrue(true);
62 }
63 }
64
65 @Test
66 public void testEmpty_SpecificCapacity() {
67 final IntList i = new IntList(5);
68 assertEquals(0, i.size());
69 try {
70 i.get(0);
71 fail("Accepted 0 index on empty list");
72 } catch (ArrayIndexOutOfBoundsException e) {
73 assertTrue(true);
74 }
75 }
76
77 @Test
78 public void testAdd_SmallGroup() {
79 final IntList i = new IntList();
80 final int n = 5;
81 for (int v = 0; v < n; v++)
82 i.add(10 + v);
83 assertEquals(n, i.size());
84
85 for (int v = 0; v < n; v++)
86 assertEquals(10 + v, i.get(v));
87 try {
88 i.get(n);
89 fail("Accepted out of bound index on list");
90 } catch (ArrayIndexOutOfBoundsException e) {
91 assertTrue(true);
92 }
93 }
94
95 @Test
96 public void testAdd_ZeroCapacity() {
97 final IntList i = new IntList(0);
98 assertEquals(0, i.size());
99 i.add(1);
100 assertEquals(1, i.get(0));
101 }
102
103 @Test
104 public void testAdd_LargeGroup() {
105 final IntList i = new IntList();
106 final int n = 500;
107 for (int v = 0; v < n; v++)
108 i.add(10 + v);
109 assertEquals(n, i.size());
110
111 for (int v = 0; v < n; v++)
112 assertEquals(10 + v, i.get(v));
113 try {
114 i.get(n);
115 fail("Accepted out of bound index on list");
116 } catch (ArrayIndexOutOfBoundsException e) {
117 assertTrue(true);
118 }
119 }
120
121 @Test
122 public void testFillTo0() {
123 final IntList i = new IntList();
124 i.fillTo(0, Integer.MIN_VALUE);
125 assertEquals(0, i.size());
126 }
127
128 @Test
129 public void testFillTo1() {
130 final IntList i = new IntList();
131 i.fillTo(1, Integer.MIN_VALUE);
132 assertEquals(1, i.size());
133 i.add(0);
134 assertEquals(Integer.MIN_VALUE, i.get(0));
135 assertEquals(0, i.get(1));
136 }
137
138 @Test
139 public void testFillTo100() {
140 final IntList i = new IntList();
141 i.fillTo(100, Integer.MIN_VALUE);
142 assertEquals(100, i.size());
143 i.add(3);
144 assertEquals(Integer.MIN_VALUE, i.get(99));
145 assertEquals(3, i.get(100));
146 }
147
148 @Test
149 public void testClear() {
150 final IntList i = new IntList();
151 final int n = 5;
152 for (int v = 0; v < n; v++)
153 i.add(10 + v);
154 assertEquals(n, i.size());
155
156 i.clear();
157 assertEquals(0, i.size());
158 try {
159 i.get(0);
160 fail("Accepted 0 index on empty list");
161 } catch (ArrayIndexOutOfBoundsException e) {
162 assertTrue(true);
163 }
164 }
165
166 @Test
167 public void testSet() {
168 final IntList i = new IntList();
169 i.add(1);
170 assertEquals(1, i.size());
171 assertEquals(1, i.get(0));
172
173 i.set(0, 5);
174 assertEquals(5, i.get(0));
175
176 try {
177 i.set(5, 5);
178 fail("accepted set of 5 beyond end of list");
179 } catch (ArrayIndexOutOfBoundsException e){
180 assertTrue(true);
181 }
182
183 i.set(1, 2);
184 assertEquals(2, i.size());
185 assertEquals(2, i.get(1));
186 }
187
188 @Test
189 public void testToString() {
190 final IntList i = new IntList();
191 i.add(1);
192 assertEquals("[1]", i.toString());
193 i.add(13);
194 i.add(5);
195 assertEquals("[1, 13, 5]", i.toString());
196 }
197
198 }