|
@@ -1,15 +1,18 @@
|
1
|
1
|
import org.junit.Assert;
|
2
|
2
|
import org.junit.Test;
|
3
|
3
|
|
4
|
|
-import static org.junit.Assert.*;
|
|
4
|
+import java.util.ArrayList;
|
|
5
|
+import java.util.List;
|
5
|
6
|
|
6
|
7
|
public class ArrazTest {
|
7
|
8
|
|
|
9
|
+ private Arraz arraz = new Arraz();
|
|
10
|
+
|
8
|
11
|
@Test
|
9
|
12
|
public void testSumValuesOfArrayPostive(){
|
10
|
13
|
int[] arr = new int[] {2, 3, 4, 5, 6, 7};
|
11
|
14
|
|
12
|
|
- int output = Arraz.sumValuesOfArray(arr);
|
|
15
|
+ int output = arraz.sumValuesOfArray(arr);
|
13
|
16
|
|
14
|
17
|
int expected = 27;
|
15
|
18
|
int actual = output;
|
|
@@ -21,7 +24,7 @@ public class ArrazTest {
|
21
|
24
|
public void testSumValuesOfArrayNegative(){
|
22
|
25
|
int[] arr = new int[] {2, -3, 4, 5, 6, 7};
|
23
|
26
|
|
24
|
|
- int output = Arraz.sumValuesOfArray(arr);
|
|
27
|
+ int output = arraz.sumValuesOfArray(arr);
|
25
|
28
|
|
26
|
29
|
int expected = 21;
|
27
|
30
|
int actual = output;
|
|
@@ -34,7 +37,7 @@ public class ArrazTest {
|
34
|
37
|
|
35
|
38
|
double[] arr = new double[] {2.5, .1, 4.2, .2};
|
36
|
39
|
|
37
|
|
- double actual = Arraz.sumDoublesOfArray(arr);
|
|
40
|
+ double actual = arraz.sumDoublesOfArray(arr);
|
38
|
41
|
|
39
|
42
|
double expected = 7;
|
40
|
43
|
|
|
@@ -46,7 +49,7 @@ public class ArrazTest {
|
46
|
49
|
|
47
|
50
|
double[] arr = new double[] {2.5, -.1, 4.2, .2};
|
48
|
51
|
|
49
|
|
- double actual = Arraz.sumDoublesOfArray(arr);
|
|
52
|
+ double actual = arraz.sumDoublesOfArray(arr);
|
50
|
53
|
|
51
|
54
|
double expected = 6.8;
|
52
|
55
|
|
|
@@ -58,7 +61,7 @@ public class ArrazTest {
|
58
|
61
|
|
59
|
62
|
int[] arr = new int[] {1,1,1,1,1,1,1};
|
60
|
63
|
|
61
|
|
- int actual = Arraz.averageOfArray(arr);
|
|
64
|
+ int actual = arraz.averageOfArray(arr);
|
62
|
65
|
|
63
|
66
|
int expected = 1;
|
64
|
67
|
|
|
@@ -70,7 +73,7 @@ public class ArrazTest {
|
70
|
73
|
|
71
|
74
|
int[] arr = new int[] {1,2,34,3,1,1,-122};
|
72
|
75
|
|
73
|
|
- int actual = Arraz.averageOfArray(arr);
|
|
76
|
+ int actual = arraz.averageOfArray(arr);
|
74
|
77
|
|
75
|
78
|
int expected = -11;
|
76
|
79
|
|
|
@@ -81,18 +84,18 @@ public class ArrazTest {
|
81
|
84
|
public void testDoubleAverageOfArray(){
|
82
|
85
|
double[] arr = new double[] {1,1,1,1,1,1,1};
|
83
|
86
|
|
84
|
|
- double actual = Arraz.doubleAverageOfArray(arr);
|
|
87
|
+ double actual = arraz.doubleAverageOfArray(arr);
|
85
|
88
|
|
86
|
89
|
double expected = 1;
|
87
|
90
|
|
88
|
|
- Assert.assertEquals(expected, actual);
|
|
91
|
+ Assert.assertEquals(expected, actual, 0);
|
89
|
92
|
}
|
90
|
93
|
|
91
|
94
|
@Test
|
92
|
95
|
public void testDoubleAverageOfArray2(){
|
93
|
96
|
double[] arr = new double[] {2.4,23.4,43,12,5,2,54,.5};
|
94
|
97
|
|
95
|
|
- double actual = Arraz.doubleAverageOfArray(arr);
|
|
98
|
+ double actual = arraz.doubleAverageOfArray(arr);
|
96
|
99
|
|
97
|
100
|
double expected = 17.7875;
|
98
|
101
|
|
|
@@ -103,18 +106,468 @@ public class ArrazTest {
|
103
|
106
|
public void testContainsValueFalse(){
|
104
|
107
|
int[] arr = new int[] {1,2,3,4,5,6,7,8,9};
|
105
|
108
|
|
106
|
|
- boolean expected = false;
|
107
|
|
- boolean actual = Arraz.containsValue(arr, 10);
|
|
109
|
+ boolean actual = arraz.containsValue(arr, 10);
|
108
|
110
|
|
109
|
|
- Assert.assertEquals(expected, actual);
|
|
111
|
+ Assert.assertFalse(actual);
|
110
|
112
|
}
|
111
|
113
|
|
112
|
114
|
@Test
|
113
|
115
|
public void testContainsValueTrue(){
|
114
|
116
|
int[] arr = new int[] {1,2,3,4,5,6,7,8,9};
|
115
|
117
|
|
116
|
|
- boolean actual = Arraz.containsValue(arr, 5);
|
|
118
|
+ boolean actual = arraz.containsValue(arr, 5);
|
117
|
119
|
|
118
|
120
|
Assert.assertTrue(actual);
|
119
|
121
|
}
|
|
122
|
+
|
|
123
|
+ @Test
|
|
124
|
+ public void testReverseArray1(){
|
|
125
|
+ int[] arr = new int[] {9,8,7,6,5,4,3,2,1};
|
|
126
|
+
|
|
127
|
+ Assert.assertArrayEquals(new int[] {1,2,3,4,5,6,7,8,9}, arraz.reverseArray(arr));
|
|
128
|
+ }
|
|
129
|
+
|
|
130
|
+ @Test
|
|
131
|
+ public void testReverseArray2(){
|
|
132
|
+ int[] arr = new int[] {2,4,53,2,4,56,64,2};
|
|
133
|
+
|
|
134
|
+ int[] expected = new int[] {2,64,56,4,2,53,4,2};
|
|
135
|
+ int[] actual = arraz.reverseArray(arr);
|
|
136
|
+
|
|
137
|
+ Assert.assertArrayEquals(expected, actual);
|
|
138
|
+ }
|
|
139
|
+
|
|
140
|
+ @Test
|
|
141
|
+ public void testOddEven1(){
|
|
142
|
+ int[] arr = new int[] {2,2,2,2,2,1,1,1,1};
|
|
143
|
+
|
|
144
|
+ String expected = "odds: 4 evens: 5";
|
|
145
|
+ String actual = arraz.getOddEvensOfArray(arr);
|
|
146
|
+
|
|
147
|
+ Assert.assertEquals(expected, actual);
|
|
148
|
+ }
|
|
149
|
+
|
|
150
|
+ @Test
|
|
151
|
+ public void testOddEven2(){
|
|
152
|
+ int[] arr = new int[] {1,2,3,4,5,6,7,8,9};
|
|
153
|
+
|
|
154
|
+ String expected = "odds: 5 evens: 4";
|
|
155
|
+ String actual = arraz.getOddEvensOfArray(arr);
|
|
156
|
+
|
|
157
|
+ Assert.assertEquals(expected, actual);
|
|
158
|
+ }
|
|
159
|
+
|
|
160
|
+ @Test
|
|
161
|
+ public void testFindIndexOf1(){
|
|
162
|
+ int[] arr = new int[] {1,2,3,4,5,6,7,8,9};
|
|
163
|
+
|
|
164
|
+ int expected = 1;
|
|
165
|
+ int actual = arraz.findIndexOf(arr, 2);
|
|
166
|
+
|
|
167
|
+ Assert.assertEquals(expected, actual);
|
|
168
|
+ }
|
|
169
|
+
|
|
170
|
+ @Test
|
|
171
|
+ public void testFindIndexOf2(){
|
|
172
|
+ int[] arr = new int[] {2,4,2,4,5,332,22,44,32,1};
|
|
173
|
+
|
|
174
|
+ int expected = -1;
|
|
175
|
+ int actual = arraz.findIndexOf(arr, -332);
|
|
176
|
+
|
|
177
|
+ Assert.assertEquals(expected, actual);
|
|
178
|
+ }
|
|
179
|
+
|
|
180
|
+ @Test
|
|
181
|
+ public void testCopyArrayByLoop1(){
|
|
182
|
+ int[] arr = new int[] {1,2,3,4,5,6,7,8};
|
|
183
|
+
|
|
184
|
+ int[] actual = arraz.copyArrayByLoop(arr);
|
|
185
|
+
|
|
186
|
+ Assert.assertEquals(arr, actual);
|
|
187
|
+ Assert.assertNotNull(actual);
|
|
188
|
+ }
|
|
189
|
+
|
|
190
|
+ @Test
|
|
191
|
+ public void testCopyArrayByLoop2(){
|
|
192
|
+ int[] arr = new int[] {1,2,3,5,543,322,235,4,6674,3};
|
|
193
|
+
|
|
194
|
+ int[] actual = arraz.copyArrayByLoop(arr);
|
|
195
|
+
|
|
196
|
+ Assert.assertEquals(arr, actual);
|
|
197
|
+ Assert.assertNotNull(actual);
|
|
198
|
+ }
|
|
199
|
+
|
|
200
|
+ @Test
|
|
201
|
+ public void testCopyArrayByInterator1(){
|
|
202
|
+
|
|
203
|
+ }
|
|
204
|
+
|
|
205
|
+ @Test
|
|
206
|
+ public void testCopyArrayByInterator2(){
|
|
207
|
+
|
|
208
|
+ }
|
|
209
|
+
|
|
210
|
+ @Test
|
|
211
|
+ public void testRemoveElementFromArray1(){
|
|
212
|
+ int[] arr = new int[]{1,2,3,4,5,6,7,8,9};
|
|
213
|
+
|
|
214
|
+ int[] expected = new int[]{2,3,4,5,6,7,8,9};
|
|
215
|
+ int[] actual = arraz.removeElementFromArray(arr, 1);
|
|
216
|
+
|
|
217
|
+ Assert.assertArrayEquals(expected, actual);
|
|
218
|
+ }
|
|
219
|
+
|
|
220
|
+ @Test
|
|
221
|
+ public void testRemoveElementFromArray2(){
|
|
222
|
+ int[] arr = new int[]{0};
|
|
223
|
+
|
|
224
|
+ int[] expected = new int[]{};
|
|
225
|
+ int[] actual = arraz.removeElementFromArray(arr, 0);
|
|
226
|
+
|
|
227
|
+ Assert.assertArrayEquals(expected, actual);
|
|
228
|
+ Assert.assertEquals(0, actual.length);
|
|
229
|
+ }
|
|
230
|
+
|
|
231
|
+ @Test
|
|
232
|
+ public void testRemoveElementFromArray3(){
|
|
233
|
+ int[] arr = new int[]{};
|
|
234
|
+
|
|
235
|
+ int[] expected = new int[]{-1};
|
|
236
|
+ int[] actual = arraz.removeElementFromArray(arr, 1);
|
|
237
|
+
|
|
238
|
+ Assert.assertArrayEquals(expected, actual);
|
|
239
|
+ }
|
|
240
|
+
|
|
241
|
+ @Test
|
|
242
|
+ public void testInsertIntoArrayAt1(){
|
|
243
|
+ int[] arr = new int[]{1,2,3,4,5,6,7,8,9};
|
|
244
|
+
|
|
245
|
+ int[] expected = new int[]{1,2,3,4,5,6,7,8,9,10};
|
|
246
|
+ int[] actual = arraz.InsertIntoArray(arr, 10);
|
|
247
|
+
|
|
248
|
+ Assert.assertArrayEquals(expected, actual);
|
|
249
|
+ }
|
|
250
|
+
|
|
251
|
+ @Test
|
|
252
|
+ public void testInsertIntoArrayAt2(){
|
|
253
|
+ int[] arr = new int[]{};
|
|
254
|
+
|
|
255
|
+ int[] expected = new int[]{10};
|
|
256
|
+ int[] actual = arraz.InsertIntoArray(arr, 10);
|
|
257
|
+
|
|
258
|
+ Assert.assertArrayEquals(expected, actual);
|
|
259
|
+ }
|
|
260
|
+
|
|
261
|
+ @Test
|
|
262
|
+ public void testFindMaxMinOfArray1(){
|
|
263
|
+ int[] arr = new int[]{1,2,3,4,5,6,7,8,9};
|
|
264
|
+
|
|
265
|
+ String expected = "min: 1 max: 9";
|
|
266
|
+ String actual = arraz.findMaxMinOfArray(arr);
|
|
267
|
+
|
|
268
|
+ Assert.assertEquals(expected, actual);
|
|
269
|
+ }
|
|
270
|
+
|
|
271
|
+ @Test
|
|
272
|
+ public void testFindMaxMinOfArray2(){
|
|
273
|
+ int[] arr = new int[]{-23,3,5,6433,-54};
|
|
274
|
+
|
|
275
|
+ String expected = "min: -54 max: 6433";
|
|
276
|
+ String actual = arraz.findMaxMinOfArray(arr);
|
|
277
|
+
|
|
278
|
+ Assert.assertEquals(expected, actual);
|
|
279
|
+ }
|
|
280
|
+
|
|
281
|
+ @Test
|
|
282
|
+ public void testRemoveDupesFromArray1(){
|
|
283
|
+ int[] arr = new int[]{2,3,44,4,4,65,2};
|
|
284
|
+
|
|
285
|
+ int[] expected = new int[]{3,44,65};
|
|
286
|
+ int[] actual = arraz.removeDupesFromArray(arr);
|
|
287
|
+
|
|
288
|
+ Assert.assertArrayEquals(expected, actual);
|
|
289
|
+ }
|
|
290
|
+
|
|
291
|
+ @Test
|
|
292
|
+ public void testRemoveDupesFromArray2(){
|
|
293
|
+ int[] arr = new int[]{0,1,1,1,1,1,1,1};
|
|
294
|
+
|
|
295
|
+ int[] expected = new int[]{0};
|
|
296
|
+ int[] actual = arraz.removeDupesFromArray(arr);
|
|
297
|
+
|
|
298
|
+ Assert.assertArrayEquals(expected, actual);
|
|
299
|
+ }
|
|
300
|
+
|
|
301
|
+ @Test
|
|
302
|
+ public void testSort1(){
|
|
303
|
+ int[] arr = new int[] {1,2,3,4,5,6,7,8,9};
|
|
304
|
+
|
|
305
|
+ int[] expected = new int[] {1,2,3,4,5,6,7,8,9};
|
|
306
|
+ int[] actual = arraz.sort(arr);
|
|
307
|
+
|
|
308
|
+ Assert.assertArrayEquals(expected, actual);
|
|
309
|
+ }
|
|
310
|
+
|
|
311
|
+ @Test
|
|
312
|
+ public void testSort2(){
|
|
313
|
+ int[] arr = new int[] {1,9,3,4,6,5,7,8,2};
|
|
314
|
+
|
|
315
|
+ int[] expected = new int[] {1,2,3,4,5,6,7,8,9};
|
|
316
|
+ int[] actual = arraz.sort(arr);
|
|
317
|
+
|
|
318
|
+ Assert.assertArrayEquals(expected, actual);
|
|
319
|
+ }
|
|
320
|
+
|
|
321
|
+ @Test
|
|
322
|
+ public void testFind2ndLargestValueFromArray1(){
|
|
323
|
+ int[] arr = new int[] {1,2,3,4,5,6,7,8,9};
|
|
324
|
+
|
|
325
|
+ int expected = 8;
|
|
326
|
+ int actual = arraz.find2ndLargestValueFromArray(arr);
|
|
327
|
+
|
|
328
|
+ Assert.assertEquals(expected, actual);
|
|
329
|
+ }
|
|
330
|
+
|
|
331
|
+ @Test
|
|
332
|
+ public void testFind2ndLargestValueFromArray2(){
|
|
333
|
+ int[] arr = new int[] {2,334,523,232,78,45,8876,23};
|
|
334
|
+
|
|
335
|
+ int expected = 523;
|
|
336
|
+ int actual = arraz.find2ndLargestValueFromArray(arr);
|
|
337
|
+
|
|
338
|
+ Assert.assertEquals(expected, actual);
|
|
339
|
+ }
|
|
340
|
+
|
|
341
|
+ @Test
|
|
342
|
+ public void testMakeMeAnArrayListFromArray1(){
|
|
343
|
+ int[] arr = new int[] {0};
|
|
344
|
+
|
|
345
|
+ List actual = arraz.makeMeAnArrayListFromArray(arr);
|
|
346
|
+
|
|
347
|
+ Assert.assertTrue(actual.contains(0));
|
|
348
|
+ }
|
|
349
|
+
|
|
350
|
+ @Test
|
|
351
|
+ public void testMakeMeAnArrayListFromArra2(){
|
|
352
|
+ int[] arr = new int[] {1,2,3,4,5};
|
|
353
|
+
|
|
354
|
+ List actual = arraz.makeMeAnArrayListFromArray(arr);
|
|
355
|
+
|
|
356
|
+ Assert.assertTrue(actual.contains(1));
|
|
357
|
+ Assert.assertTrue(actual.contains(2));
|
|
358
|
+ Assert.assertTrue(actual.contains(3));
|
|
359
|
+ Assert.assertTrue(actual.contains(4));
|
|
360
|
+ Assert.assertTrue(actual.contains(5));
|
|
361
|
+ }
|
|
362
|
+
|
|
363
|
+ @Test
|
|
364
|
+ public void testMakeMeAnArrayFromArrayList1(){
|
|
365
|
+ List<Integer> given = new ArrayList<Integer>();
|
|
366
|
+ given.add(23);
|
|
367
|
+ given.add(45);
|
|
368
|
+
|
|
369
|
+ Object[] actual = arraz.makeMeAnArrayFromArrayList(given);
|
|
370
|
+
|
|
371
|
+ Assert.assertEquals(2, actual.length);
|
|
372
|
+ }
|
|
373
|
+
|
|
374
|
+ @Test
|
|
375
|
+ public void testMakeMeAnArrayFromArrayList2(){
|
|
376
|
+ List<Integer> given = new ArrayList<Integer>();
|
|
377
|
+ given.add(0);
|
|
378
|
+
|
|
379
|
+ Object[] actual = arraz.makeMeAnArrayFromArrayList(given);
|
|
380
|
+
|
|
381
|
+ Assert.assertEquals(1, actual.length);
|
|
382
|
+ }
|
|
383
|
+
|
|
384
|
+ @Test
|
|
385
|
+ public void testCheck2ArraysForEqual1(){
|
|
386
|
+ int[] arr1 = new int[] {1,2,3,4,5,6,7,8,9};
|
|
387
|
+ int[] arr2 = new int[] {1,2,3,4,5,6,7,8,9};
|
|
388
|
+
|
|
389
|
+ Assert.assertTrue(arraz.check2ArraysForEqual(arr1, arr2));
|
|
390
|
+ }
|
|
391
|
+
|
|
392
|
+ @Test
|
|
393
|
+ public void testCheck2ArraysForEqual2(){
|
|
394
|
+ int[] arr1 = new int[] {1,2,3,4,5,6,7,8,9};
|
|
395
|
+ int[] arr2 = new int[] {1,2,3,5,4,6,7,8,9};
|
|
396
|
+
|
|
397
|
+ Assert.assertFalse(arraz.check2ArraysForEqual(arr1, arr2));
|
|
398
|
+ }
|
|
399
|
+
|
|
400
|
+ @Test
|
|
401
|
+ public void testCheck2ArraysForEqual3(){
|
|
402
|
+ int[] arr1 = new int[] {1,2,3,4,5,6,7,8,9,10};
|
|
403
|
+ int[] arr2 = new int[] {1,2,3,5,4,6,7,8,9};
|
|
404
|
+
|
|
405
|
+ Assert.assertFalse(arraz.check2ArraysForEqual(arr1, arr2));
|
|
406
|
+ }
|
|
407
|
+
|
|
408
|
+ @Test
|
|
409
|
+ public void testAverageArrayWithoutMaxMin1(){
|
|
410
|
+ int[] arr = new int[] {100000,1,1,1,1,1,1,1,1,1,1,-1000};
|
|
411
|
+
|
|
412
|
+ Assert.assertEquals(1, arraz.averageArrayWithoutMaxMin(arr));
|
|
413
|
+ }
|
|
414
|
+
|
|
415
|
+ @Test
|
|
416
|
+ public void testAverageArrayWithoutMaxMin2(){
|
|
417
|
+ int[] arr = new int[] {1,2,3,4,5,6,7,8,9};
|
|
418
|
+
|
|
419
|
+ Assert.assertEquals(5, arraz.averageArrayWithoutMaxMin(arr));
|
|
420
|
+ }
|
|
421
|
+
|
|
422
|
+ @Test
|
|
423
|
+ public void testArrayHas65and771(){
|
|
424
|
+ int[] arr = new int[] {1,2,3,4,5,65,7,8,9};
|
|
425
|
+
|
|
426
|
+ Assert.assertFalse(arraz.arrayHas65and77(arr));
|
|
427
|
+ }
|
|
428
|
+
|
|
429
|
+ @Test
|
|
430
|
+ public void testArrayHas65and772(){
|
|
431
|
+ int[] arr = new int[] {1,2,3,4,5,65,77,8,9};
|
|
432
|
+
|
|
433
|
+ Assert.assertTrue(arraz.arrayHas65and77(arr));
|
|
434
|
+ }
|
|
435
|
+
|
|
436
|
+ @Test
|
|
437
|
+ public void testTheTotalofTensIs301(){
|
|
438
|
+ int[] arr = new int[] {10,10,10};
|
|
439
|
+
|
|
440
|
+ Assert.assertTrue(arraz.theTotalofTensIs30(arr));
|
|
441
|
+ }
|
|
442
|
+
|
|
443
|
+ @Test
|
|
444
|
+ public void testTheTotalofTensIs302(){
|
|
445
|
+ int[] arr = new int[] {10,10};
|
|
446
|
+
|
|
447
|
+ Assert.assertFalse(arraz.theTotalofTensIs30(arr));
|
|
448
|
+ }
|
|
449
|
+
|
|
450
|
+ @Test
|
|
451
|
+ public void testGet2SmallestNumbers1(){
|
|
452
|
+ int[] arr = new int[] {1,2,3,4,5,6,7,8,9};
|
|
453
|
+
|
|
454
|
+ String expected = "smallest: 1, 2nd smallest: 2";
|
|
455
|
+ Assert.assertEquals(expected, arraz.get2SmallestNumbers(arr));
|
|
456
|
+ }
|
|
457
|
+
|
|
458
|
+ @Test
|
|
459
|
+ public void testGet2SmallestNumbers2(){
|
|
460
|
+ int[] arr = new int[] {23,2,55,34664,223,554,22,-1};
|
|
461
|
+
|
|
462
|
+ String expected = "smallest: -1, 2nd smallest: 2";
|
|
463
|
+ Assert.assertEquals(expected, arraz.get2SmallestNumbers(arr));
|
|
464
|
+ }
|
|
465
|
+
|
|
466
|
+ @Test
|
|
467
|
+ public void testMakeMeACopyPlease1(){
|
|
468
|
+ int[] arr = new int[] {1,2,3,4,5,6,7,8,9};
|
|
469
|
+
|
|
470
|
+ int[] expected = new int[] {9,8,7,6,5,4,3,2,1};
|
|
471
|
+ Assert.assertArrayEquals(expected, arraz.makeMeACopyPlease(arr));
|
|
472
|
+ }
|
|
473
|
+
|
|
474
|
+ @Test
|
|
475
|
+ public void testMakeMeACopyPlease2(){
|
|
476
|
+ int[] arr = new int[] {2,3,542,12,55,3,2,45,67};
|
|
477
|
+
|
|
478
|
+ int[] expected = new int[] {67,45,2,3,55,12,542,3,2};
|
|
479
|
+ Assert.assertArrayEquals(expected, arraz.makeMeACopyPlease(arr));
|
|
480
|
+ }
|
|
481
|
+
|
|
482
|
+ @Test
|
|
483
|
+ public void testRemoveLastItemAndCopy1(){
|
|
484
|
+ int[] arr = new int[] {1,2,3,4,5,6,7,8,9};
|
|
485
|
+
|
|
486
|
+ int[] expected = new int[] {1,2,3,4,5,6,7,8};
|
|
487
|
+
|
|
488
|
+ Assert.assertArrayEquals(expected, arraz.removeLastItemAndCopy(arr));
|
|
489
|
+ }
|
|
490
|
+
|
|
491
|
+ @Test
|
|
492
|
+ public void testRemoveLastItemAndCopy2(){
|
|
493
|
+ int[] arr = new int[] {1,2,445,32,3,6,545326,34,6262,73,2634,358,12};
|
|
494
|
+
|
|
495
|
+ int[] expected = new int[] {1,2,445,32,3,6,545326,34,6262,73,2634,358};
|
|
496
|
+
|
|
497
|
+ Assert.assertArrayEquals(expected, arraz.removeLastItemAndCopy(arr));
|
|
498
|
+ }
|
|
499
|
+
|
|
500
|
+ @Test
|
|
501
|
+ public void testRemoveFirstItemAndCopy1(){
|
|
502
|
+ int[] arr = new int[] {1,2,3,4,5,6,7,8,9};
|
|
503
|
+
|
|
504
|
+ int[] output = arraz.removeFirstItemAndCopy(arr);
|
|
505
|
+
|
|
506
|
+ Assert.assertEquals(8, output.length);
|
|
507
|
+ Assert.assertTrue(!arraz.containsValue(output, 1));
|
|
508
|
+ }
|
|
509
|
+
|
|
510
|
+ @Test
|
|
511
|
+ public void testRemoveFirstItemAndCopy2(){
|
|
512
|
+ int[] arr = new int[] {10};
|
|
513
|
+
|
|
514
|
+ int[] output = arraz.removeFirstItemAndCopy(arr);
|
|
515
|
+
|
|
516
|
+ Assert.assertEquals(0, output.length);
|
|
517
|
+ Assert.assertTrue(!arraz.containsValue(output, 10));
|
|
518
|
+ }
|
|
519
|
+
|
|
520
|
+ @Test
|
|
521
|
+ public void testInsertAtStartAndCopy1(){
|
|
522
|
+ int[] arr = new int[] {1,2,3,4,5,6,7,8,9};
|
|
523
|
+
|
|
524
|
+ int[] expected = new int[] {10,1,2,3,4,5,6,7,8,9};
|
|
525
|
+
|
|
526
|
+ Assert.assertArrayEquals(expected, arraz.insertAtStartAndCopy(arr, 10));
|
|
527
|
+ }
|
|
528
|
+
|
|
529
|
+ @Test
|
|
530
|
+ public void testInsertAtStartAndCopy2(){
|
|
531
|
+ int[] arr = new int[] {};
|
|
532
|
+
|
|
533
|
+ int[] expected = new int[] {10};
|
|
534
|
+
|
|
535
|
+ Assert.assertArrayEquals(expected, arraz.insertAtStartAndCopy(arr, 10));
|
|
536
|
+ }
|
|
537
|
+
|
|
538
|
+ @Test
|
|
539
|
+ public void testInsertAtEndAndCopy1(){
|
|
540
|
+ int[] arr = new int[] {1,2,3,4,5,6,7,8,9};
|
|
541
|
+
|
|
542
|
+ int[] expected = new int[] {1,2,3,4,5,6,7,8,9,10};
|
|
543
|
+
|
|
544
|
+ Assert.assertArrayEquals(expected, arraz.insertAtEndAndCopy(arr, 10));
|
|
545
|
+ }
|
|
546
|
+
|
|
547
|
+ @Test
|
|
548
|
+ public void testInsertAtEndAndCopy2(){
|
|
549
|
+ int[] arr = new int[] {};
|
|
550
|
+
|
|
551
|
+ int[] expected = new int[] {10};
|
|
552
|
+
|
|
553
|
+ Assert.assertArrayEquals(expected, arraz.insertAtEndAndCopy(arr, 10));
|
|
554
|
+ }
|
|
555
|
+
|
|
556
|
+ @Test
|
|
557
|
+ public void testSortArrayIntoEvensThenOdds1(){
|
|
558
|
+ int[] arr = new int[] {4,5,102,6,-7,12,-32,92,8};
|
|
559
|
+
|
|
560
|
+ int[] expected = new int[] {-32, 4, 6, 8, 12, 92, 102, -7, 5};
|
|
561
|
+
|
|
562
|
+ Assert.assertArrayEquals(expected, arraz.sortArrayIntoEvensThenOdds(arr));
|
|
563
|
+ }
|
|
564
|
+
|
|
565
|
+ @Test
|
|
566
|
+ public void testSortArrayIntoEvensThenOdds2(){
|
|
567
|
+ int[] arr = new int[] {1,2,3,4,5,6,7,8,9};
|
|
568
|
+
|
|
569
|
+ int[] expected = new int[] {2,4,6,8,1,3,5,7,9};
|
|
570
|
+
|
|
571
|
+ Assert.assertArrayEquals(expected, arraz.sortArrayIntoEvensThenOdds(arr));
|
|
572
|
+ }
|
120
|
573
|
}
|