Tariq Hook 6 年之前
父節點
當前提交
b2e20fd406
共有 2 個檔案被更改,包括 35 行新增0 行删除
  1. 10
    0
      src/main/java/io/zipcoder/ArrayDrills.java
  2. 25
    0
      src/test/java/io/zipcoder/ArrayDrillsTest.java

+ 10
- 0
src/main/java/io/zipcoder/ArrayDrills.java 查看文件

@@ -73,4 +73,14 @@ public class ArrayDrills {
73 73
     public Integer[] biggerTwo(Integer[] a, Integer[] b){
74 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 查看文件

@@ -1,5 +1,6 @@
1 1
 package io.zipcoder;
2 2
 
3
+import com.sun.tools.corba.se.idl.InterfaceGen;
3 4
 import org.junit.Assert;
4 5
 import org.junit.Before;
5 6
 import org.junit.Test;
@@ -182,4 +183,28 @@ public class ArrayDrillsTest {
182 183
         Integer[] actual = arrayDrills.biggerTwo(inputArray1, inputArray2);
183 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
 }