Tariq Hook 6 years ago
parent
commit
b2e20fd406

+ 10
- 0
src/main/java/io/zipcoder/ArrayDrills.java View File

73
     public Integer[] biggerTwo(Integer[] a, Integer[] b){
73
     public Integer[] biggerTwo(Integer[] a, Integer[] b){
74
         return null;
74
         return null;
75
     }
75
     }
76
+
77
+    /**
78
+     * Given an array of ints of odd length, return a new array length 3 containing the elements from the middle of the array.
79
+     * The array length will be at least 3.
80
+     * example : midThree([1, 2, 3, 4, 5]); // Should return [2, 3, 4]
81
+     *           midThree([8, 6, 7, 5, 3, 0, 9]); // Should return [7, 5, 3]
82
+     */
83
+    public Integer[] midThree(Integer[] nums){
84
+        return null;
85
+    }
76
 }
86
 }

+ 25
- 0
src/test/java/io/zipcoder/ArrayDrillsTest.java View File

1
 package io.zipcoder;
1
 package io.zipcoder;
2
 
2
 
3
+import com.sun.tools.corba.se.idl.InterfaceGen;
3
 import org.junit.Assert;
4
 import org.junit.Assert;
4
 import org.junit.Before;
5
 import org.junit.Before;
5
 import org.junit.Test;
6
 import org.junit.Test;
182
         Integer[] actual = arrayDrills.biggerTwo(inputArray1, inputArray2);
183
         Integer[] actual = arrayDrills.biggerTwo(inputArray1, inputArray2);
183
         Assert.assertArrayEquals(expected, actual);
184
         Assert.assertArrayEquals(expected, actual);
184
     }
185
     }
186
+
187
+    @Test
188
+    public void midThree1(){
189
+        Integer[] inputArray = {1, 2, 3};
190
+        Integer[] expected = {1, 2, 3};
191
+        Integer[] actual = arrayDrills.midThree(inputArray);
192
+        Assert.assertArrayEquals(expected, actual);
193
+    }
194
+
195
+    @Test
196
+    public void midThree2(){
197
+        Integer[] inputArray = {1, 2, 3, 4, 5};
198
+        Integer[] expected = {2, 3, 4};
199
+        Integer[] actual = arrayDrills.midThree(inputArray);
200
+        Assert.assertArrayEquals(expected, actual);
201
+    }
202
+
203
+    @Test
204
+    public void midThree3(){
205
+        Integer[] inputArray = {8, 6, 7, 5, 3, 0, 9};
206
+        Integer[] expected = {7, 5,3};
207
+        Integer[] actual = arrayDrills.midThree(inputArray);
208
+        Assert.assertArrayEquals(expected, actual);
209
+    }
185
 }
210
 }