|
@@ -1,5 +1,357 @@
|
|
1
|
+import org.junit.Assert;
|
|
2
|
+import org.junit.Before;
|
|
3
|
+import org.junit.Test;
|
|
4
|
+
|
1
|
5
|
import static org.junit.Assert.*;
|
2
|
6
|
|
3
|
7
|
public class ArrazTest {
|
4
|
8
|
|
|
9
|
+ private Arraz arraz;
|
|
10
|
+ private int[] intArray;
|
|
11
|
+ private int[] intArray2;
|
|
12
|
+ private double[] doubleArray;
|
|
13
|
+ private double[] doubleArray2;
|
|
14
|
+
|
|
15
|
+ @Before
|
|
16
|
+ public void setUp() {
|
|
17
|
+ arraz = new Arraz();
|
|
18
|
+ intArray = new int[]{1, 2, 3, 4, 5};
|
|
19
|
+ intArray2 = new int[]{5, 6, 7, 8, 9, 10};
|
|
20
|
+ doubleArray = new double[]{11, 12, 13, 14, 15};
|
|
21
|
+ doubleArray2 = new double[]{15, 16, 17, 18, 19, 20};
|
|
22
|
+ }
|
|
23
|
+
|
|
24
|
+ @Test
|
|
25
|
+ public void sumValuesOfArray1() {
|
|
26
|
+ int expected = 15;
|
|
27
|
+ int actual = arraz.sumValuesOfArray(intArray);
|
|
28
|
+
|
|
29
|
+ Assert.assertEquals(expected, actual);
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+ @Test
|
|
33
|
+ public void sumValuesOfArray2() {
|
|
34
|
+ int expected = 45;
|
|
35
|
+ int actual = arraz.sumValuesOfArray(intArray2);
|
|
36
|
+
|
|
37
|
+ Assert.assertEquals(expected, actual);
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+ ////////// ////////// //////////
|
|
41
|
+
|
|
42
|
+ @Test
|
|
43
|
+ public void sumDoubleOfArray1() {
|
|
44
|
+ double expected = 65;
|
|
45
|
+ double actual = arraz.sumDoubleOfArray(doubleArray);
|
|
46
|
+
|
|
47
|
+ Assert.assertEquals(expected, actual, 1e-15);
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+ @Test
|
|
51
|
+ public void sumDoubleOfArray2() {
|
|
52
|
+ double expected = 105;
|
|
53
|
+ double actual = arraz.sumDoubleOfArray(doubleArray2);
|
|
54
|
+
|
|
55
|
+ Assert.assertEquals(expected, actual, 1e-15);
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ ////////// ////////// //////////
|
|
59
|
+
|
|
60
|
+ @Test
|
|
61
|
+ public void averageOfArray1() {
|
|
62
|
+ int expected = 3;
|
|
63
|
+ int actual = arraz.averageOfArray(intArray);
|
|
64
|
+
|
|
65
|
+ Assert.assertEquals(expected, actual);
|
|
66
|
+ }
|
|
67
|
+
|
|
68
|
+ @Test
|
|
69
|
+ public void averageOfArray2() {
|
|
70
|
+ int expected = 7;
|
|
71
|
+ int actual = arraz.averageOfArray(intArray2);
|
|
72
|
+
|
|
73
|
+ Assert.assertEquals(expected, actual);
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ ////////// ////////// //////////
|
|
77
|
+
|
|
78
|
+ @Test
|
|
79
|
+ public void doubleAverageOfArray1() {
|
|
80
|
+ double expected = 13;
|
|
81
|
+ double actual = arraz.doubleAverageOfArray(doubleArray);
|
|
82
|
+
|
|
83
|
+ Assert.assertEquals(expected, actual, 1e-15);
|
|
84
|
+ }
|
|
85
|
+
|
|
86
|
+ @Test
|
|
87
|
+ public void doubleAverageOfArray2() {
|
|
88
|
+ double expected = 17.5;
|
|
89
|
+ double actual = arraz.doubleAverageOfArray(doubleArray2);
|
|
90
|
+
|
|
91
|
+ Assert.assertEquals(expected, actual, 1e-15);
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ ////////// ////////// //////////
|
|
95
|
+
|
|
96
|
+ @Test
|
|
97
|
+ public void containsValue1() {
|
|
98
|
+ Assert.assertTrue(arraz.containsValue(intArray, 5));
|
|
99
|
+ Assert.assertTrue(arraz.containsValue(intArray2, 5));
|
|
100
|
+ }
|
|
101
|
+
|
|
102
|
+ @Test
|
|
103
|
+ public void containsValue2() {
|
|
104
|
+ Assert.assertFalse(arraz.containsValue(intArray, 6));
|
|
105
|
+ Assert.assertFalse(arraz.containsValue(intArray2, 4));
|
|
106
|
+ }
|
|
107
|
+
|
|
108
|
+ ////////// ////////// //////////
|
|
109
|
+
|
|
110
|
+ @Test
|
|
111
|
+ public void reverseArray1() {
|
|
112
|
+ int[] expected = {5, 4, 3, 2, 1};
|
|
113
|
+ int[] actual = arraz.reverseArray(intArray);
|
|
114
|
+
|
|
115
|
+ for (int i = 0; i < expected.length; i++) {
|
|
116
|
+ Assert.assertEquals(expected[i], actual[i]);
|
|
117
|
+ }
|
|
118
|
+ }
|
|
119
|
+
|
|
120
|
+ @Test
|
|
121
|
+ public void reverseArray2() {
|
|
122
|
+ int[] expected = {10, 9, 8, 7, 6, 5};
|
|
123
|
+ int[] actual = arraz.reverseArray(intArray2);
|
|
124
|
+
|
|
125
|
+ for (int i = 0; i < expected.length; i++) {
|
|
126
|
+ Assert.assertEquals(expected[i], actual[i]);
|
|
127
|
+ }
|
|
128
|
+ }
|
|
129
|
+
|
|
130
|
+ ////////// ////////// //////////
|
|
131
|
+
|
|
132
|
+ @Test
|
|
133
|
+ public void getOddEvensOfArray1() {
|
|
134
|
+ OddEven expected = new OddEven(3, 2);
|
|
135
|
+ OddEven actual = arraz.getOddEvensOfArray(intArray);
|
|
136
|
+
|
|
137
|
+ Assert.assertEquals(expected.odds, actual.odds);
|
|
138
|
+ Assert.assertEquals(expected.evens, actual.evens);
|
|
139
|
+ }
|
|
140
|
+
|
|
141
|
+ @Test
|
|
142
|
+ public void getOddEvensOfArray2() {
|
|
143
|
+ OddEven expected = new OddEven(3, 3);
|
|
144
|
+ OddEven actual = arraz.getOddEvensOfArray(intArray2);
|
|
145
|
+
|
|
146
|
+ Assert.assertEquals(expected.odds, actual.odds);
|
|
147
|
+ Assert.assertEquals(expected.evens, actual.evens);
|
|
148
|
+ }
|
|
149
|
+
|
|
150
|
+ ////////// ////////// //////////
|
|
151
|
+
|
|
152
|
+ @Test
|
|
153
|
+ public void findIndexOf1() {
|
|
154
|
+ int expected = 3;
|
|
155
|
+ int actual = arraz.findIndexOf(intArray, 4);
|
|
156
|
+
|
|
157
|
+ Assert.assertEquals(expected, actual);
|
|
158
|
+ }
|
|
159
|
+
|
|
160
|
+ @Test
|
|
161
|
+ public void findIndexOf2() {
|
|
162
|
+ int expected = -1;
|
|
163
|
+ int actual = arraz.findIndexOf(intArray2, 1);
|
|
164
|
+
|
|
165
|
+ Assert.assertEquals(expected, actual);
|
|
166
|
+ }
|
|
167
|
+
|
|
168
|
+ ////////// ////////// //////////
|
|
169
|
+
|
|
170
|
+ @Test
|
|
171
|
+ public void createEmptyGenericArray() {
|
|
172
|
+ String[] expected = new String[]{"this", "is", "a", "good", "test"};
|
|
173
|
+ String[] actual = (String[]) arraz.createEmptyGenericArray(expected, expected.length);
|
|
174
|
+ actual[0] = expected[0];
|
|
175
|
+
|
|
176
|
+ Assert.assertEquals(expected.getClass(), actual.getClass());
|
|
177
|
+ Assert.assertEquals(expected[0].getClass(), actual[0].getClass());
|
|
178
|
+ }
|
|
179
|
+
|
|
180
|
+ ////////// ////////// //////////
|
|
181
|
+
|
|
182
|
+ @Test
|
|
183
|
+ public void copyArrayByIterator1() {
|
|
184
|
+ String[] expected = new String[]{"this", "is", "a", "good", "test"};
|
|
185
|
+ String[] actual = (String[]) arraz.copyArrayByIterator(expected);
|
|
186
|
+
|
|
187
|
+ for (int i = 0; i < expected.length; i++) {
|
|
188
|
+ Assert.assertEquals(expected[i], actual[i]);
|
|
189
|
+ }
|
|
190
|
+
|
|
191
|
+ Assert.assertEquals(expected, actual);
|
|
192
|
+ }
|
|
193
|
+
|
|
194
|
+ @Test
|
|
195
|
+ public void copyArrayByIterator2() {
|
|
196
|
+ Integer[] expected = new Integer[]{1, 2, 3, 4, 5};
|
|
197
|
+ Integer[] actual = (Integer[]) arraz.copyArrayByIterator(expected);
|
|
198
|
+
|
|
199
|
+ for (int i = 0; i < expected.length; i++) {
|
|
200
|
+ Assert.assertEquals(expected[i], actual[i]);
|
|
201
|
+ }
|
|
202
|
+
|
|
203
|
+ Assert.assertEquals(expected, actual);
|
|
204
|
+ }
|
|
205
|
+
|
|
206
|
+ ////////// ////////// //////////
|
|
207
|
+
|
|
208
|
+ @Test
|
|
209
|
+ public void copyArrayByLoop1() {
|
|
210
|
+ String[] expected = new String[]{"this", "is", "a", "good", "test"};
|
|
211
|
+ String[] actual = (String[]) arraz.copyArrayByLoop(expected);
|
|
212
|
+
|
|
213
|
+ for (int i = 0; i < expected.length; i++) {
|
|
214
|
+ Assert.assertEquals(expected[i], actual[i]);
|
|
215
|
+ }
|
|
216
|
+
|
|
217
|
+ Assert.assertEquals(expected, actual);
|
|
218
|
+ }
|
|
219
|
+
|
|
220
|
+ @Test
|
|
221
|
+ public void copyArrayByLoop2() {
|
|
222
|
+ Integer[] expected = new Integer[]{1, 2, 3, 4, 5};
|
|
223
|
+ Integer[] actual = (Integer[]) arraz.copyArrayByLoop(expected);
|
|
224
|
+
|
|
225
|
+ for (int i = 0; i < expected.length; i++) {
|
|
226
|
+ Assert.assertEquals(expected[i], actual[i]);
|
|
227
|
+ }
|
|
228
|
+
|
|
229
|
+ Assert.assertEquals(expected, actual);
|
|
230
|
+ }
|
|
231
|
+
|
|
232
|
+ ////////// ////////// //////////
|
|
233
|
+
|
|
234
|
+ @Test
|
|
235
|
+ public void removeElementFromArray1() {
|
|
236
|
+ String[] original = new String[]{"this", "is", "a", "good", "test"};
|
|
237
|
+
|
|
238
|
+ String[] expected = new String[]{"this", "is", "a", "test"};
|
|
239
|
+ String[] actual = (String[]) arraz.removeElementFromArray(original, "good");
|
|
240
|
+
|
|
241
|
+ Assert.assertEquals(expected, actual);
|
|
242
|
+ }
|
|
243
|
+
|
|
244
|
+ @Test
|
|
245
|
+ public void removeElementFromArray2() {
|
|
246
|
+ Integer[] original = new Integer[]{1, 2, 3, 4, 5};
|
|
247
|
+
|
|
248
|
+ Integer[] expected = new Integer[]{1, 2, 4, 5};
|
|
249
|
+ Integer[] actual = (Integer[]) arraz.removeElementFromArray(original, 3);
|
|
250
|
+
|
|
251
|
+ Assert.assertEquals(expected, actual);
|
|
252
|
+ }
|
|
253
|
+
|
|
254
|
+ ////////// ////////// //////////
|
|
255
|
+
|
|
256
|
+ @Test
|
|
257
|
+ public void insertIntoArrayAt1() {
|
|
258
|
+ String[] original = new String[]{"this", "is", "a", "good", "test"};
|
|
259
|
+
|
|
260
|
+ String[] expected = new String[]{"this", "is", "a", "good", "test", "!"};
|
|
261
|
+ String[] actual = (String[]) arraz.insertIntoArrayAt(original, "!", 5);
|
|
262
|
+
|
|
263
|
+ Assert.assertEquals(expected, actual);
|
|
264
|
+ }
|
|
265
|
+
|
|
266
|
+ @Test
|
|
267
|
+ public void insertIntoArrayAt2() {
|
|
268
|
+ Integer[] original = new Integer[]{1, 2, 3, 4, 5};
|
|
269
|
+
|
|
270
|
+ Integer[] expected = new Integer[]{1, 2, 3, 100, 4, 5};
|
|
271
|
+ Integer[] actual = (Integer[]) arraz.insertIntoArrayAt(original, 100, 3);
|
|
272
|
+
|
|
273
|
+ Assert.assertEquals(expected, actual);
|
|
274
|
+ }
|
|
275
|
+
|
|
276
|
+ ////////// ////////// //////////
|
|
277
|
+
|
|
278
|
+ @Test
|
|
279
|
+ public void findMax() {
|
|
280
|
+ int expected = 5;
|
|
281
|
+ int actual = arraz.findMax(intArray);
|
|
282
|
+
|
|
283
|
+ Assert.assertEquals(expected, actual);
|
|
284
|
+ }
|
|
285
|
+
|
|
286
|
+ @Test
|
|
287
|
+ public void findMin() {
|
|
288
|
+ int expected = 1;
|
|
289
|
+ int actual = arraz.findMin(intArray);
|
|
290
|
+
|
|
291
|
+ Assert.assertEquals(expected, actual);
|
|
292
|
+ }
|
|
293
|
+
|
|
294
|
+ ////////// ////////// //////////
|
|
295
|
+
|
|
296
|
+ @Test
|
|
297
|
+ public void findMaxMinOfArray1() {
|
|
298
|
+ MaxMin expected = new MaxMin(5, 1);
|
|
299
|
+ MaxMin actual = arraz.findMaxMinOfArray(intArray);
|
|
300
|
+
|
|
301
|
+ Assert.assertEquals(expected.max, actual.max);
|
|
302
|
+ Assert.assertEquals(expected.min, actual.min);
|
|
303
|
+ }
|
|
304
|
+
|
|
305
|
+ @Test
|
|
306
|
+ public void findMaxMinOfArray2() {
|
|
307
|
+ MaxMin expected = new MaxMin(10, 5);
|
|
308
|
+ MaxMin actual = arraz.findMaxMinOfArray(intArray2);
|
|
309
|
+
|
|
310
|
+ Assert.assertEquals(expected.max, actual.max);
|
|
311
|
+ Assert.assertEquals(expected.min, actual.min);
|
|
312
|
+ }
|
|
313
|
+
|
|
314
|
+ ////////// ////////// //////////
|
|
315
|
+
|
|
316
|
+ @Test
|
|
317
|
+ public void removeDupesFromArray1() {
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+ }
|
|
322
|
+
|
|
323
|
+ @Test
|
|
324
|
+ public void removeDupesFromArray2() {
|
|
325
|
+ }
|
|
326
|
+
|
|
327
|
+ ////////// ////////// //////////
|
|
328
|
+
|
|
329
|
+ @Test
|
|
330
|
+ public void find2ndLargestValueFromArray1() {
|
|
331
|
+ }
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+ @Test
|
|
335
|
+ public void find2ndLargestValueFromArray2() {
|
|
336
|
+ }
|
|
337
|
+
|
|
338
|
+ ////////// ////////// //////////
|
|
339
|
+
|
|
340
|
+ @Test
|
|
341
|
+ public void makeMeAnArrayListFromArray1() {
|
|
342
|
+ }
|
|
343
|
+
|
|
344
|
+ @Test
|
|
345
|
+ public void makeMeAnArrayListFromArray2() {
|
|
346
|
+ }
|
|
347
|
+
|
|
348
|
+ ////////// ////////// //////////
|
|
349
|
+
|
|
350
|
+ @Test
|
|
351
|
+ public void makeMeAnArrayFromArrayList1() {
|
|
352
|
+ }
|
|
353
|
+
|
|
354
|
+ @Test
|
|
355
|
+ public void makeMeAnArrayFromArrayList2() {
|
|
356
|
+ }
|
5
|
357
|
}
|