Pārlūkot izejas kodu

Added the fifth microlab

Zach Marcin 7 gadus atpakaļ
vecāks
revīzija
9ef642a9a7
3 mainītis faili ar 31 papildinājumiem un 1 dzēšanām
  1. 2
    1
      README.md
  2. 13
    0
      src/main/java/Swap/Swap.java
  3. 16
    0
      src/test/java/Swap/SwapTest.java

+ 2
- 1
README.md Parādīt failu

@@ -13,4 +13,5 @@ Implement Table<K,V> so that it manages an ArrayList of Entry<K,V>.  You must im
13 13
         * Remember, a key point to exactly one value
14 14
     * `remove` which takes a key and removes it from the ArrayList if it's in there.  It's a void method; no return type.
15 15
 4. TableNested -- Take the previous microlab, and make Entry a nested class.  Think about if it'll need to be generic
16
-or not.
16
+or not.
17
+5. Swap -- Get the test to pass.  Look at the specific values being passed in to help you figure it out.

+ 13
- 0
src/main/java/Swap/Swap.java Parādīt failu

@@ -0,0 +1,13 @@
1
+package Swap;
2
+
3
+/**
4
+ * Keep this.  Just make it so the tests pass.
5
+ */
6
+public class Swap {
7
+    public static <T> T[] swap(int i, int j, T... values) {
8
+        T temp = values[i];
9
+        values[i] = values[j];
10
+        values[j] = temp;
11
+        return values;
12
+    }
13
+}

+ 16
- 0
src/test/java/Swap/SwapTest.java Parādīt failu

@@ -0,0 +1,16 @@
1
+package Swap;
2
+//
3
+//import org.junit.Assert;
4
+//import org.junit.Test;
5
+//
6
+///**
7
+// * Get the tests passing.
8
+// */
9
+//public class SwapTest {
10
+//    @Test
11
+//    public void testSwap() throws Exception {
12
+//        Double[] result = Swap.swap(0,1, 1.5, 2,3);
13
+//        Double[] expected = {2.0, 1.5, 3.0};
14
+//        Assert.assertArrayEquals(expected, result);
15
+//    }
16
+//}