Bladeren bron

part 6 done, making progress

ahsonali 6 jaren geleden
bovenliggende
commit
d5fe550ec5

+ 17
- 1
src/main/java/ArrayListCombiner/ArrayListCombiner.java Bestand weergeven

@@ -1,5 +1,7 @@
1 1
 package ArrayListCombiner;
2 2
 
3
+import Employee.Employee;
4
+
3 5
 import java.util.ArrayList;
4 6
 
5 7
 /**
@@ -8,5 +10,19 @@ import java.util.ArrayList;
8 10
  * The first method should be called extendCombiner and should use ? extends E
9 11
  * The second method should be called superCombiner and should use ? super E
10 12
  */
11
-public class ArrayListCombiner {
13
+public class ArrayListCombiner
14
+{
15
+
16
+
17
+    public static<E> void extendCombiner(ArrayList<E> first, ArrayList<? extends E> second)
18
+    {
19
+        first.addAll(second);
20
+    }
21
+
22
+    public static<E> void superCombiner(ArrayList<? super E> first, ArrayList<E> second)
23
+    {
24
+        first.addAll(second);
25
+    }
26
+    //superCombiner and extendCombiner
27
+
12 28
 }

+ 35
- 35
src/test/java/ArrayListCombiner/ArrayListCombinerTest.java Bestand weergeven

@@ -9,40 +9,40 @@ import org.junit.Assert;
9 9
 import java.util.ArrayList;
10 10
 
11 11
 public class ArrayListCombinerTest {
12
-//    Employee foo = new Employee("FOO", 100);
13
-//    Manager bar = new Manager("BAR", 100);
14
-//    @Test
15
-//    public void testExtendCombiner() throws Exception {
16
-//        // Given an array list with employees
17
-//        ArrayList<Employee> first = new ArrayList<>();
18
-//        first.add(foo);
19
-//        // An an array list with managers
20
-//        ArrayList<Manager> second = new ArrayList<>();
21
-//        second.add(bar);
22
-//        // When  I combine them
23
-//        ArrayListCombiner.extendCombiner(first, second);
24
-//        // Then I should get an arrayList with both
25
-//        ArrayList<Employee> expected = new ArrayList<>();
26
-//        expected.add(foo);
27
-//        expected.add(bar);
28
-//        Assert.assertEquals(expected, first);
29
-//    }
30
-//
31
-//    @Test
32
-//    public void testSuperCombiner() throws Exception {
33
-//        // Given an array list with employees
34
-//        ArrayList<Employee> first = new ArrayList<>();
35
-//        first.add(foo);
36
-//        // An an array list with managers
37
-//        ArrayList<Manager> second = new ArrayList<>();
38
-//        second.add(bar);
39
-//        // When  I combine them
40
-//        ArrayListCombiner.superCombiner(first, second);
41
-//        // Then I should get an arrayList with both
42
-//        ArrayList<Employee> expected = new ArrayList<>();
43
-//        expected.add(foo);
44
-//        expected.add(bar);
45
-//        Assert.assertEquals(expected, first);
46
-//    }
12
+  Employee foo = new Employee("FOO", 100);
13
+    Manager bar = new Manager("BAR", 100);
14
+    @Test
15
+    public void testExtendCombiner() throws Exception {
16
+        // Given an array list with employees
17
+        ArrayList<Employee> first = new ArrayList<>();
18
+        first.add(foo);
19
+        // An an array list with managers
20
+        ArrayList<Manager> second = new ArrayList<>();
21
+        second.add(bar);
22
+        // When  I combine them
23
+        ArrayListCombiner.extendCombiner(first, second);
24
+        // Then I should get an arrayList with both
25
+        ArrayList<Employee> expected = new ArrayList<>();
26
+        expected.add(foo);
27
+        expected.add(bar);
28
+        Assert.assertEquals(expected, first);
29
+    }
30
+
31
+    @Test
32
+    public void testSuperCombiner() throws Exception {
33
+        // Given an array list with employees
34
+        ArrayList<Employee> first = new ArrayList<>();
35
+        first.add(foo);
36
+        // An an array list with managers
37
+        ArrayList<Manager> second = new ArrayList<>();
38
+        second.add(bar);
39
+        // When  I combine them
40
+        ArrayListCombiner.superCombiner(first, second);
41
+        // Then I should get an arrayList with both
42
+        ArrayList<Employee> expected = new ArrayList<>();
43
+        expected.add(foo);
44
+        expected.add(bar);
45
+        Assert.assertEquals(expected, first);
46
+    }
47 47
 
48 48
 }

+ 15
- 15
src/test/java/Swap/SwapTest.java Bestand weergeven

@@ -1,16 +1,16 @@
1 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
-//}
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.0,3.0);
13
+        Double[] expected = {2.0, 1.5, 3.0};
14
+        Assert.assertArrayEquals(expected, result);
15
+    }
16
+}