|
@@ -1,5 +1,320 @@
|
1
|
|
-import static org.junit.Assert.*;
|
|
1
|
+import help.OddEven;
|
|
2
|
+import org.junit.Assert;
|
|
3
|
+import org.junit.Test;
|
|
4
|
+
|
|
5
|
+import java.util.List;
|
2
|
6
|
|
3
|
7
|
public class ArrazTest {
|
|
8
|
+ Arraz test = new Arraz();
|
|
9
|
+
|
|
10
|
+ @Test
|
|
11
|
+ public void testSumOfArray_int1(){
|
|
12
|
+ Assert.assertEquals(10, test.sumValuesOfArray(new int[]{4, 3, 2, 1}));
|
|
13
|
+ }
|
|
14
|
+
|
|
15
|
+ @Test
|
|
16
|
+ public void testSumOfArray_int2(){
|
|
17
|
+ Assert.assertEquals(-15, test.sumValuesOfArray(new int[]{-5,20,-30}));
|
|
18
|
+ }
|
|
19
|
+
|
|
20
|
+ @Test
|
|
21
|
+ public void testSumOfArray_double1(){
|
|
22
|
+ Assert.assertEquals(10.5, test.sumDoubleofArray(new double[]{4.0,3,2,1.5}),.1);
|
|
23
|
+ }
|
|
24
|
+
|
|
25
|
+ @Test
|
|
26
|
+ public void testSumOfArray_double2(){
|
|
27
|
+ Assert.assertEquals(0, test.sumDoubleofArray(new double[]{-5.0,20,-15.0}),.1);
|
|
28
|
+ }
|
|
29
|
+
|
|
30
|
+ @Test
|
|
31
|
+ public void testAverageOfArray_int1(){
|
|
32
|
+ Assert.assertEquals(7, test.averageOfArray(new int[]{3,20,-1}));
|
|
33
|
+ }
|
|
34
|
+
|
|
35
|
+ @Test
|
|
36
|
+ public void testAverageOfArray_int2(){
|
|
37
|
+ Assert.assertEquals(29, test.averageOfArray(new int[]{12,50,15,39}));
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+ @Test
|
|
41
|
+ public void testDoubleAverageOfArray_double1(){
|
|
42
|
+ Assert.assertEquals(1.0, test.doubleAverageOfArray(new double[]{3,-5,5.0}),.1);
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ @Test
|
|
46
|
+ public void testDoubleAverageOfArray_double2(){
|
|
47
|
+ Assert.assertEquals(12, test.doubleAverageOfArray(new double[]{12,4,20,12}),.1);
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+ @Test
|
|
51
|
+ public void testContainsValue1(){
|
|
52
|
+ Assert.assertTrue(test.containsValue(new int[]{1,2,3,4},3));
|
|
53
|
+ }
|
|
54
|
+
|
|
55
|
+ @Test
|
|
56
|
+ public void testContainsValue2(){
|
|
57
|
+ Assert.assertFalse(test.containsValue(new int[]{1,2,3,4},5));
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ @Test
|
|
61
|
+ public void testOddEven1(){
|
|
62
|
+ OddEven oe = test.oddEven(new int[]{1,2,3,4,5});
|
|
63
|
+ Assert.assertEquals(3,oe.getOdd());
|
|
64
|
+ }
|
|
65
|
+
|
|
66
|
+ @Test
|
|
67
|
+ public void testOddEven2(){
|
|
68
|
+ OddEven oe = test.oddEven(new int[]{1,2,3,4,5});
|
|
69
|
+ Assert.assertEquals(2,oe.getEven());
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ @Test
|
|
73
|
+ public void testFindIndexOf1(){
|
|
74
|
+ Assert.assertEquals(2, test.findIndexOf(new Integer[]{1,2,3,4,5},3));
|
|
75
|
+ }
|
|
76
|
+
|
|
77
|
+ @Test
|
|
78
|
+ public void testFindIndexOf2(){
|
|
79
|
+ Assert.assertEquals(-1, test.findIndexOf(new Integer[]{1,2,3,4,5},6));
|
|
80
|
+ }
|
|
81
|
+
|
|
82
|
+ @Test
|
|
83
|
+ public void testCopyArrayByIterator1(){
|
|
84
|
+ Integer[] a = {1,2,3};
|
|
85
|
+ Integer[] b = test.copyArrayByIterator(a);
|
|
86
|
+ Assert.assertEquals(1, b[0]);
|
|
87
|
+ }
|
|
88
|
+
|
|
89
|
+ @Test
|
|
90
|
+ public void testCopyArrayByIterator2(){
|
|
91
|
+ Integer[] a = {1,2,4};
|
|
92
|
+ Integer[] b = test.copyArrayByIterator(a);
|
|
93
|
+ Assert.assertEquals(4, b[2]);
|
|
94
|
+ }
|
|
95
|
+
|
|
96
|
+ @Test
|
|
97
|
+ public void testCopyArrayByLoop(){
|
|
98
|
+ int[] a = {1,2,3};
|
|
99
|
+ int[] b = test.copyArrayByLoop(a);
|
|
100
|
+ Assert.assertEquals(1, b[0]);
|
|
101
|
+ }
|
|
102
|
+
|
|
103
|
+ @Test
|
|
104
|
+ public void testCopyArrayByLoop2(){
|
|
105
|
+ int[] a = {1,2,3};
|
|
106
|
+ int[] b = test.copyArrayByLoop(a);
|
|
107
|
+ Assert.assertEquals(3, b[2]);
|
|
108
|
+ }
|
|
109
|
+
|
|
110
|
+ @Test
|
|
111
|
+ public void testRemoveElementFromArray1(){
|
|
112
|
+ Integer[] a = {1,2,3};
|
|
113
|
+ Integer[] b = test.removeElementFromArray(a,2);
|
|
114
|
+ Assert.assertEquals(3,b[1]);
|
|
115
|
+ }
|
|
116
|
+
|
|
117
|
+ @Test
|
|
118
|
+ public void testRemoveElementFromArray2(){
|
|
119
|
+ Integer[] a = {1,2,3,4,5,6,7};
|
|
120
|
+ Integer[] b = test.removeElementFromArray(a,4);
|
|
121
|
+ Assert.assertEquals(5,b[3]);
|
|
122
|
+ }
|
|
123
|
+
|
|
124
|
+ @Test
|
|
125
|
+ public void testRemoveDupesFromArray(){
|
|
126
|
+ Integer[] a = {1,1,2,3,4};
|
|
127
|
+ Integer[] b = test.removeDupesFromArray(a);
|
|
128
|
+ Assert.assertEquals(4,b.length);
|
|
129
|
+ Assert.assertEquals(2,b[1]);
|
|
130
|
+ }
|
|
131
|
+
|
|
132
|
+ @Test
|
|
133
|
+ public void testRemoveDupesFromArray2(){
|
|
134
|
+ Integer[] a = {1,1,2,3,4,4,5,1,6};
|
|
135
|
+ Integer[] b = test.removeDupesFromArray(a);
|
|
136
|
+ Assert.assertEquals(6,b.length);
|
|
137
|
+ Assert.assertEquals(1,b[4]);
|
|
138
|
+ }
|
|
139
|
+
|
|
140
|
+ @Test
|
|
141
|
+ public void testFind2ndLargest1(){
|
|
142
|
+ Double[] d = {1.0,2.0,3.0,4.0};
|
|
143
|
+ Assert.assertEquals(3.0,test.find2ndLargestValueFromArray(d));
|
|
144
|
+ }
|
|
145
|
+
|
|
146
|
+ @Test
|
|
147
|
+ public void testFind2ndLargest2(){
|
|
148
|
+ Double[] d = {1.0,1.0,2.0,2.0,2.0,2.0};
|
|
149
|
+ Assert.assertEquals(1.0,test.find2ndLargestValueFromArray(d));
|
|
150
|
+ }
|
|
151
|
+
|
|
152
|
+ @Test
|
|
153
|
+ public void testMakeArrayList1(){
|
|
154
|
+ Integer[] a = {1,2,3,4};
|
|
155
|
+ List<Integer> b = test.makeArrayListFromArray(a);
|
|
156
|
+ Assert.assertEquals(4,b.size());
|
|
157
|
+ Assert.assertEquals(4,b.get(3));
|
|
158
|
+ }
|
|
159
|
+
|
|
160
|
+ @Test
|
|
161
|
+ public void testMakeArrayList2(){
|
|
162
|
+ Integer[] a = {1,2,3,4,6};
|
|
163
|
+ List<Integer> b = test.makeArrayListFromArray(a);
|
|
164
|
+ Assert.assertEquals(5,b.size());
|
|
165
|
+ Assert.assertEquals(6,b.get(4));
|
|
166
|
+ }
|
|
167
|
+
|
|
168
|
+ @Test
|
|
169
|
+ public void testCheck2ArraysForEqual1(){
|
|
170
|
+ Integer[] a = {1,2,3,4};
|
|
171
|
+ Integer[] b = {1,2,3,4};
|
|
172
|
+ Assert.assertTrue(test.check2ArraysForEqual(a,b));
|
|
173
|
+ }
|
|
174
|
+
|
|
175
|
+ @Test
|
|
176
|
+ public void testCheck2ArraysForEqual2(){
|
|
177
|
+ Integer[] a = {1,2,3,4};
|
|
178
|
+ Integer[] b = {1,2,3,5};
|
|
179
|
+ Assert.assertFalse(test.check2ArraysForEqual(a,b));
|
|
180
|
+ }
|
|
181
|
+
|
|
182
|
+ @Test
|
|
183
|
+ public void testHas65and77_1(){
|
|
184
|
+ Integer[] a = {1,2,3,4,65};
|
|
185
|
+ Integer[] b = {1,2,3,4,77};
|
|
186
|
+ Integer[] c = {1,2,3,4};
|
|
187
|
+ Assert.assertFalse(test.arrayHas65and77(a));
|
|
188
|
+ Assert.assertFalse(test.arrayHas65and77(b));
|
|
189
|
+ Assert.assertFalse(test.arrayHas65and77(c));
|
|
190
|
+ }
|
|
191
|
+
|
|
192
|
+ @Test
|
|
193
|
+ public void testHas65and77_2(){
|
|
194
|
+ Integer[] a = {1,2,3,4,65,77};
|
|
195
|
+ Assert.assertTrue(test.arrayHas65and77(a));
|
|
196
|
+ }
|
|
197
|
+
|
|
198
|
+ @Test
|
|
199
|
+ public void testTotalofTensIs30_1(){
|
|
200
|
+ Integer[] a = {1,2,10,10,10,10};
|
|
201
|
+ Integer[] b = {1,2,10,10};
|
|
202
|
+ Assert.assertFalse(test.theTotalofTensIs30(a));
|
|
203
|
+ Assert.assertFalse(test.theTotalofTensIs30(b));
|
|
204
|
+ }
|
|
205
|
+
|
|
206
|
+ @Test
|
|
207
|
+ public void testTotalofTensIs30_2(){
|
|
208
|
+ Integer[] a = {1,2,10,10,10};
|
|
209
|
+ Integer[] b = {10,2,10,10};
|
|
210
|
+ Assert.assertTrue(test.theTotalofTensIs30(a));
|
|
211
|
+ Assert.assertTrue(test.theTotalofTensIs30(b));
|
|
212
|
+ }
|
|
213
|
+
|
|
214
|
+ @Test
|
|
215
|
+ public void testFindTwoSmallest1(){
|
|
216
|
+ Integer[] a = {1,2,3,4,5};
|
|
217
|
+ Integer[] b = test.findTwoSmallest(a);
|
|
218
|
+
|
|
219
|
+ Assert.assertEquals(1,b[0]);
|
|
220
|
+ Assert.assertEquals(2,b[1]);
|
|
221
|
+ }
|
|
222
|
+
|
|
223
|
+ @Test
|
|
224
|
+ public void testFindTwoSmallest2(){
|
|
225
|
+ Integer[] a = {1,1,1,2,2,3,4,5};
|
|
226
|
+ Integer[] b = test.findTwoSmallest(a);
|
|
227
|
+
|
|
228
|
+ Assert.assertEquals(1,b[0]);
|
|
229
|
+ Assert.assertEquals(2,b[1]);
|
|
230
|
+ }
|
|
231
|
+
|
|
232
|
+ @Test
|
|
233
|
+ public void testMakeMeACopyPlease1(){
|
|
234
|
+ Integer[] a = {1,2,3,4};
|
|
235
|
+ Integer[] b = {4,3,2,1};
|
|
236
|
+
|
|
237
|
+ Assert.assertEquals(b,test.makeMeACopyPlease(a));
|
|
238
|
+ }
|
|
239
|
+
|
|
240
|
+ @Test
|
|
241
|
+ public void testMakeMeACopyPlease2(){
|
|
242
|
+ Integer[] a = {1,2,3,4,5,1,1};
|
|
243
|
+ Integer[] b = {1,1,5,4,3,2,1};
|
|
244
|
+
|
|
245
|
+ Assert.assertEquals(b,test.makeMeACopyPlease(a));
|
|
246
|
+ }
|
|
247
|
+
|
|
248
|
+ @Test
|
|
249
|
+ public void testRemoveLastItemAndCopy1(){
|
|
250
|
+ Integer[] a = {1,2,3,4,5};
|
|
251
|
+ Integer[] b = {1,2,3,4};
|
|
252
|
+
|
|
253
|
+ Assert.assertEquals(b,test.removeLastItemAndCopy(a));
|
|
254
|
+ }
|
|
255
|
+
|
|
256
|
+ @Test
|
|
257
|
+ public void testRemoveLastItemAndCopy2(){
|
|
258
|
+ Integer[] a = {1,2,3,4,5,6};
|
|
259
|
+ Integer[] b = {1,2,3,4,5};
|
|
260
|
+
|
|
261
|
+ Assert.assertEquals(b,test.removeLastItemAndCopy(a));
|
|
262
|
+ }
|
|
263
|
+
|
|
264
|
+ @Test
|
|
265
|
+ public void testRemoveFirstItemAndCopy1(){
|
|
266
|
+ Integer[] a = {1,2,3,4,5};
|
|
267
|
+ Integer[] b = {2,3,4,5};
|
|
268
|
+
|
|
269
|
+ Assert.assertEquals(b,test.removeFirstItemAndCopy(a));
|
|
270
|
+ }
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+ @Test
|
|
274
|
+ public void testInsertAtStartAndCopy1(){
|
|
275
|
+ Integer[] a = {1,2,3,4,5,6};
|
|
276
|
+ Integer[] b = {5,1,2,3,4,5,6};
|
|
277
|
+
|
|
278
|
+ Assert.assertEquals(b,test.insertAtStartAndCopy(a,5));
|
|
279
|
+ }
|
|
280
|
+
|
|
281
|
+ @Test
|
|
282
|
+ public void testInsertAtStartAndCopy2(){
|
|
283
|
+ Integer[] a = {1,2,3,4,5,6};
|
|
284
|
+ Integer[] b = {6,1,2,3,4,5,6};
|
|
285
|
+
|
|
286
|
+ Assert.assertEquals(b,test.insertAtStartAndCopy(a,6));
|
|
287
|
+ }
|
|
288
|
+
|
|
289
|
+ @Test
|
|
290
|
+ public void testInsertAtEndAndCopy1(){
|
|
291
|
+ Integer[] a = {1,2,3,4,5,6};
|
|
292
|
+ Integer[] b = {1,2,3,4,5,6,12};
|
|
293
|
+
|
|
294
|
+ Assert.assertEquals(b,test.insertAtEndAndCopy(a,12));
|
|
295
|
+ }
|
|
296
|
+
|
|
297
|
+ @Test
|
|
298
|
+ public void testInsertAtEndAndCopy2(){
|
|
299
|
+ Integer[] a = {1,2,6};
|
|
300
|
+ Integer[] b = {1,2,6,13};
|
|
301
|
+
|
|
302
|
+ Assert.assertEquals(b,test.insertAtEndAndCopy(a,13));
|
|
303
|
+ }
|
|
304
|
+
|
|
305
|
+ @Test
|
|
306
|
+ public void testSortArrayIntoEvensThenOdds1(){
|
|
307
|
+ Integer[] a = {4,5,102,6,-7,12,-32,92,8};
|
|
308
|
+ a = test.sortArrayIntoEvensThenOdds(a);
|
|
309
|
+ Integer[] b = {4,102,6,12,-32,92,8,5,-7};
|
|
310
|
+ Assert.assertEquals(b,test.sortArrayIntoEvensThenOdds(a));
|
|
311
|
+ }
|
4
|
312
|
|
|
313
|
+ @Test
|
|
314
|
+ public void testSortArrayIntoEvensThenOdds2(){
|
|
315
|
+ Integer[] a = {4,5,102,6,-7,12,-32,92,8,29, 15, 105, -8};
|
|
316
|
+ a = test.sortArrayIntoEvensThenOdds(a);
|
|
317
|
+ Integer[] b = {4,102,6,12,-32,92,8,-8,5,-7,29,15,105};
|
|
318
|
+ Assert.assertEquals(b,test.sortArrayIntoEvensThenOdds(a));
|
|
319
|
+ }
|
5
|
320
|
}
|