|
@@ -1,11 +1,17 @@
|
1
|
1
|
import junit.framework.Assert;
|
2
|
2
|
import org.junit.Test;
|
3
|
3
|
|
|
4
|
+import java.util.Arrays;
|
|
5
|
+
|
4
|
6
|
import static org.junit.Assert.*;
|
5
|
7
|
|
6
|
8
|
public class ArrazTest {
|
7
|
9
|
|
8
|
|
- int[] spiffyHandyIntArray = new int[] {4,5,102,6,-7,12,-32,92,8};
|
|
10
|
+ private int[] spiffyHandyIntArray = new int[] {4,5,102,6,-7,12,-32,92,8};
|
|
11
|
+
|
|
12
|
+ private double[] spiffyHandyDoubleArray = new double[] {1.0, 0.5, 3.6, 38.4, 17.3, 62.0, 9.0, 3.375, 0, 3.14159};
|
|
13
|
+
|
|
14
|
+ Arraz whySoDifficult = new Arraz();
|
9
|
15
|
|
10
|
16
|
@Test
|
11
|
17
|
public void sumValuesOfArray() {
|
|
@@ -15,4 +21,84 @@ public class ArrazTest {
|
15
|
21
|
Assert.assertEquals(sum, Arraz.sumValuesOfArray(spiffyHandyIntArray));
|
16
|
22
|
|
17
|
23
|
}
|
|
24
|
+
|
|
25
|
+ @Test
|
|
26
|
+ public void sumDoublesOfArray() {
|
|
27
|
+
|
|
28
|
+ double sum = 138.31659000000002;
|
|
29
|
+
|
|
30
|
+ Assert.assertEquals(sum, Arraz.sumDoublesOfArray(spiffyHandyDoubleArray));
|
|
31
|
+
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+ @Test
|
|
35
|
+ public void averageOfArray() {
|
|
36
|
+
|
|
37
|
+ int average = 21;
|
|
38
|
+
|
|
39
|
+ Assert.assertEquals(average, Arraz.averageOfArray(spiffyHandyIntArray));
|
|
40
|
+
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ @Test
|
|
44
|
+ public void doubleAverageOfArray() {
|
|
45
|
+
|
|
46
|
+ double average = 13.831659000000002;
|
|
47
|
+
|
|
48
|
+ Assert.assertEquals(average, Arraz.doubleAverageOfArray(spiffyHandyDoubleArray));
|
|
49
|
+
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ @Test
|
|
53
|
+ public void containsValue() {
|
|
54
|
+
|
|
55
|
+ Assert.assertTrue(Arraz.containsValue(spiffyHandyIntArray, 102));
|
|
56
|
+ Assert.assertFalse(Arraz.containsValue(spiffyHandyIntArray, 103));
|
|
57
|
+
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+ @Test
|
|
62
|
+ public void reverseArray() {
|
|
63
|
+
|
|
64
|
+ int[] expected = new int[] {8, 92, -32, 12, -7, 6, 102, 5, 4};
|
|
65
|
+
|
|
66
|
+ Assert.assertEquals(Arrays.toString(expected), Arrays.toString(Arraz.reverseArray(spiffyHandyIntArray)));
|
|
67
|
+
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ @Test
|
|
71
|
+ public void getOddEvensOfArray() {
|
|
72
|
+
|
|
73
|
+ OddEven result = new OddEven(2, 7);
|
|
74
|
+
|
|
75
|
+ Assert.assertEquals(result.odds, Arraz.getOddEvensOfArray(spiffyHandyIntArray).odds);
|
|
76
|
+ Assert.assertEquals(result.evens, Arraz.getOddEvensOfArray(spiffyHandyIntArray).evens);
|
|
77
|
+
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+ @Test
|
|
81
|
+ @SuppressWarnings("unchecked")
|
|
82
|
+ public void findIndexOf() {
|
|
83
|
+
|
|
84
|
+ //Given
|
|
85
|
+ int expected = 4;
|
|
86
|
+ int expectedtwo = -1;
|
|
87
|
+ int val = -7;
|
|
88
|
+ int valtwo = 123456789;
|
|
89
|
+ Integer[] damnedObjects = new Integer[] {4,5,102,6,-7,12,-32,92,8};
|
|
90
|
+
|
|
91
|
+ //Assert
|
|
92
|
+ Assert.assertEquals(expected, whySoDifficult.findIndexOf(damnedObjects, val));
|
|
93
|
+ Assert.assertEquals(expectedtwo, whySoDifficult.findIndexOf(damnedObjects, valtwo));
|
|
94
|
+
|
|
95
|
+ }
|
|
96
|
+
|
|
97
|
+ @Test
|
|
98
|
+ public void copyArrayByIterator() {
|
|
99
|
+ }
|
|
100
|
+
|
|
101
|
+ @Test
|
|
102
|
+ public void copyArrayByLoop() {
|
|
103
|
+ }
|
18
|
104
|
}
|