1313import static org .junit .jupiter .api .Assertions .assertEquals ;
1414import static org .junit .jupiter .api .Assertions .fail ;
1515import static org .junit .jupiter .api .Assertions .assertIterableEquals ;
16+ import static org .junit .jupiter .api .Assertions .assertTrue ;
1617
1718public class BigArrayListTest
1819{
@@ -27,7 +28,7 @@ public class BigArrayListTest
2728 private static int maxActions ;
2829
2930 private static Random random ;
30- private BigArrayList <Integer > bigArrayList ;
31+ private BigArrayList <Integer > actualMonte ;
3132
3233 @ BeforeAll
3334 static void setUp () throws Exception
@@ -47,9 +48,9 @@ static void setUp() throws Exception
4748 @ AfterEach
4849 protected void tearDown () throws Exception
4950 {
50- if (bigArrayList != null )
51+ if (actualMonte != null )
5152 {
52- bigArrayList .clearMemory ();
53+ actualMonte .clearMemory ();
5354 }
5455 }
5556
@@ -68,7 +69,7 @@ public void testBigArrayList()
6869 int cacheBlocks = random .nextInt (maxCacheBlocks - minCacheBlocks ) + minCacheBlocks ;
6970 int actions = random .nextInt (maxActions -minActions ) + minActions ;
7071
71- bigArrayList = new BigArrayList <Integer >(blockSize , cacheBlocks );
72+ actualMonte = new BigArrayList <Integer >(blockSize , cacheBlocks );
7273 List <Integer > arrayList = new ArrayList <>();
7374
7475 for (int j =0 ; j <actions ; j ++)
@@ -81,18 +82,18 @@ public void testBigArrayList()
8182
8283 int num1 = random .nextInt ();
8384 arrayList .add (num1 );
84- bigArrayList .add (num1 );
85+ actualMonte .add (num1 );
8586
8687 //add another if it is early
8788 if (j < actions /2 )
8889 {
8990 int num2 = random .nextInt ();
9091 arrayList .add (num2 );
91- bigArrayList .add (num2 );
92+ actualMonte .add (num2 );
9293 }
9394
9495 String errorMessage = "(ADD) Sizes not equal: test run iteration = " + i + ", action number = " + j ;
95- assertEquals ((long )arrayList .size (), bigArrayList .size (), errorMessage );
96+ assertEquals ((long )arrayList .size (), actualMonte .size (), errorMessage );
9697 }
9798 else if (action == 1 )
9899 {
@@ -103,14 +104,14 @@ else if(action == 1)
103104 int getIndex = random .nextInt (listSize );
104105
105106 long number1 = arrayList .get (getIndex );
106- long number2 = bigArrayList .get (getIndex );
107+ long number2 = actualMonte .get (getIndex );
107108
108109 String errorMessage = "(GET) Elements not equal: test run iteration = " + i + ", action number = " + j +
109110 ", ArrayList element = " + number1 + ", BigArrayList element = " + number2 + ", index = " + getIndex ;
110111 assertEquals (number1 , number2 , errorMessage );
111112
112113 String errorMessage2 = "(GET) Sizes not equal: test run iteration = " + i + ", action number = " + j ;
113- assertEquals (arrayList .size (), bigArrayList .size (), errorMessage2 );
114+ assertEquals (arrayList .size (), actualMonte .size (), errorMessage2 );
114115 }
115116 else if (action == 2 )
116117 {
@@ -122,11 +123,11 @@ else if(action == 2)
122123 int randomNumber = random .nextInt ();
123124
124125 arrayList .set (setIndex , randomNumber );
125- bigArrayList .set (setIndex , randomNumber );
126+ actualMonte .set (setIndex , randomNumber );
126127
127128
128129 String errorMessage2 = "(SET) Sizes not equal: test run iteration = " + i + ", action number = " + j + ", index = " + setIndex ;
129- assertEquals (arrayList .size (), bigArrayList .size (), errorMessage2 );
130+ assertEquals (arrayList .size (), actualMonte .size (), errorMessage2 );
130131 }
131132 else if (action == 3 )
132133 {
@@ -137,29 +138,29 @@ else if(action == 3)
137138 int removeIndex = random .nextInt (listSize );
138139
139140 int number1 = arrayList .remove (removeIndex );
140- int number2 = bigArrayList .remove (removeIndex );
141+ int number2 = actualMonte .remove (removeIndex );
141142
142143 String errorMessage = "(REMOVE) Elements not equal: test run iteration = " + i + ", action number = " + j +
143144 ", ArrayList element = " + number1 + ", BigArrayList element = " + number2 + ", index = " + removeIndex ;
144145 assertEquals (number1 , number2 , errorMessage );
145146
146147 String errorMessage2 = "(REMOVE) Sizes not equal: test run iteration = " + i + ", action number = " + j ;
147- assertEquals (arrayList .size (), bigArrayList .size (), errorMessage2 );
148+ assertEquals (arrayList .size (), actualMonte .size (), errorMessage2 );
148149
149150 if (j > actions /2 && arrayList .size () > 0 )
150151 {
151152 int listSize2 = arrayList .size ();
152153 int removeIndex2 = random .nextInt (listSize2 );
153154
154155 int number1_2 = arrayList .remove (removeIndex2 );
155- int number2_2 = bigArrayList .remove (removeIndex2 );
156+ int number2_2 = actualMonte .remove (removeIndex2 );
156157
157158 String errorMessage3 = "(REMOVE) Elements not equal: test run iteration = " + i + ", action number = " + j +
158159 ", ArrayList element = " + number1_2 + ", BigArrayList element = " + number2_2 + ", index = " + removeIndex ;
159160 assertEquals (number1 , number2 , errorMessage3 );
160161
161162 String errorMessage4 = "(REMOVE) Sizes not equal: test run iteration = " + i + ", action number = " + j ;
162- assertEquals (arrayList .size (), bigArrayList .size (), errorMessage4 );
163+ assertEquals (arrayList .size (), actualMonte .size (), errorMessage4 );
163164 }
164165 }
165166
@@ -181,7 +182,7 @@ else if(action == 3)
181182 for (int j =0 ; j <arrayList .size (); j ++)
182183 {
183184 int number1 = arrayList .get (j );
184- int number2 = bigArrayList .get (j );
185+ int number2 = actualMonte .get (j );
185186
186187 String errorMessage = "(Elements not equal: test run iteration = " + i +
187188 ", ArrayList element = " + number1 + ", BigArrayList element = " + number2 + ", index = " + j ;
@@ -193,7 +194,7 @@ else if(action == 3)
193194
194195 try
195196 {
196- bigArrayList = BigArrayList .sort (bigArrayList );
197+ actualMonte = BigArrayList .sort (actualMonte );
197198 }
198199 catch (IOException e )
199200 {
@@ -203,7 +204,7 @@ else if(action == 3)
203204
204205 try
205206 {
206- bigArrayList .clearMemory ();
207+ actualMonte .clearMemory ();
207208 }
208209 catch (IOException e )
209210 {
@@ -213,7 +214,7 @@ else if(action == 3)
213214 for (int j =0 ; j <arrayList .size (); j ++)
214215 {
215216 int number1 = arrayList .get (j );
216- int number2 = bigArrayList .get (j );
217+ int number2 = actualMonte .get (j );
217218
218219 String errorMessage = "(Elements not equal after sorting: test run iteration = " + i +
219220 ", ArrayList element = " + number1 + ", BigArrayList element = " + number2 + ", index = " + j ;
@@ -228,22 +229,94 @@ else if(action == 3)
228229 @ Test
229230 public void testIterator () {
230231
231- bigArrayList = new BigArrayList <Integer >();
232+ BigArrayList < Integer > bal = new BigArrayList <>();
232233
233234 for (int i = 0 ; i < 10000 ; i ++) {
234- bigArrayList .add (random .nextInt ());
235+ bal .add (random .nextInt ());
235236 }
236237
237238 List <Integer > expected = new ArrayList <>();
238- for (int i = 0 ; i < bigArrayList .size (); i ++) {
239- expected .add (bigArrayList .get (i ));
239+ for (int i = 0 ; i < bal .size (); i ++) {
240+ expected .add (bal .get (i ));
240241 }
241242
242243 List <Integer > actual = new ArrayList <>();
243- for (int i : bigArrayList ) {
244+ for (int i : bal ) {
244245 actual .add (i );
245246 }
246247
247248 assertIterableEquals (expected , actual );
249+ try {
250+ bal .clearMemory ();
251+ } catch (IOException e ) {
252+ e .printStackTrace ();
253+ }
254+ }
255+
256+ @ Test
257+ public void testAddAll () {
258+ BigArrayList <Integer > actual = new BigArrayList <>();
259+ List <Integer > expected = new ArrayList <>();
260+
261+ for (int i = 0 ; i < 1000 ; i ++) {
262+ int randomInt = random .nextInt ();
263+ actual .add (randomInt );
264+ expected .add (randomInt );
265+ }
266+
267+ List <Integer > toAdd = new ArrayList <>();
268+
269+ for (int i = 0 ; i < 1000 ; i ++) {
270+ int randomInt = random .nextInt ();
271+ toAdd .add (randomInt );
272+ }
273+
274+ actual .addAll (toAdd );
275+ expected .addAll (toAdd );
276+
277+ assertIterableEquals (expected , actual );
278+ try {
279+ actual .clearMemory ();
280+ } catch (IOException e ) {
281+ e .printStackTrace ();
282+ }
283+ }
284+
285+ @ Test
286+ public void testClear () {
287+ BigArrayList <Integer > actual = new BigArrayList <>();
288+ List <Integer > expected = new ArrayList <>();
289+
290+ for (int i = 0 ; i < 1000 ; i ++) {
291+ int randomInt = random .nextInt ();
292+ actual .add (randomInt );
293+ expected .add (randomInt );
294+ }
295+
296+ actual .clear ();
297+ expected .clear ();
298+
299+ assertTrue (actual .isLive ());
300+ assertTrue (actual .isEmpty ());
301+ }
302+
303+ @ Test
304+ public void testEquals () {
305+ BigArrayList <Integer > actual = new BigArrayList <>();
306+ BigArrayList <Integer > expected = new BigArrayList <>();
307+ for (int i = 0 ; i < 1000 ; i ++) {
308+ int randomInt = random .nextInt ();
309+ actual .add (randomInt );
310+ expected .add (randomInt );
311+ }
312+
313+ assertEquals (expected , actual );
314+
315+ try {
316+ actual .clearMemory ();
317+ expected .clearMemory ();
318+ } catch (IOException e ) {
319+ e .printStackTrace ();
320+ }
248321 }
249322}
0 commit comments