Joshua Chung 6 lat temu
rodzic
commit
96caa56517

+ 12
- 0
src/main/java/ArrayListCombiner/ArrayListCombiner.java Wyświetl plik

@@ -1,6 +1,9 @@
1 1
 package ArrayListCombiner;
2 2
 
3
+import Employee.Employee;
4
+
3 5
 import java.util.ArrayList;
6
+import java.util.Collection;
4 7
 
5 8
 /**
6 9
  * Create two generic methods that take two arraylists.  The methods should both append the second ArrayList's items,
@@ -9,4 +12,13 @@ import java.util.ArrayList;
9 12
  * The second method should be called superCombiner and should use ? super E
10 13
  */
11 14
 public class ArrayListCombiner {
15
+
16
+    public static <E> void extendCombiner(ArrayList<E> first, ArrayList<? extends E> second) {
17
+        first.addAll(second);
18
+    }
19
+
20
+    public static <E> void superCombiner(ArrayList<? super E> first, ArrayList<E> second) {
21
+        first.addAll(second);
22
+    }
12 23
 }
24
+

+ 9
- 0
src/main/java/MapFunc/MapFunc.java Wyświetl plik

@@ -9,4 +9,13 @@ import java.util.function.Function;
9 9
  */
10 10
 public class MapFunc {
11 11
 
12
+    @FunctionalInterface
13
+    public interface Function<T, R> {
14
+        
15
+    }
16
+
17
+
18
+    public static <E implements Function<T, R>> void map(ArrayList<E>, Function<T, R>) {
19
+
20
+    }
12 21
 }

+ 4
- 4
src/main/java/Pair/Arrays.java Wyświetl plik

@@ -10,7 +10,7 @@ import java.util.Collections;
10 10
  * A max method that returns the largest item in the arraylist
11 11
  * And a minmax method that returns a pair containing the largest and smallest items from the array list
12 12
  */
13
-public class Arrays {
14
-    public static <___> Pair<E> firstLast(ArrayList<___> a) {
15
-    }
16
-}
13
+//public class Arrays {
14
+//    public static <___> Pair<E> firstLast(ArrayList<___> a) {
15
+//    }
16
+//}

+ 23
- 0
src/main/java/StackArray/GenericStack.java Wyświetl plik

@@ -1,5 +1,8 @@
1 1
 package StackArray;
2 2
 
3
+import StackArrayList.Stack;
4
+
5
+import java.util.ArrayList;
3 6
 import java.util.Arrays;
4 7
 
5 8
 /**
@@ -8,8 +11,28 @@ import java.util.Arrays;
8 11
  * @param <E>
9 12
  */
10 13
 public class GenericStack<E> {
14
+    private ArrayList<E> stack = new ArrayList<>();
11 15
     private E[] elements;
16
+    private int top = 0;
12 17
 
13 18
     public GenericStack() {
19
+        elements = (E[]) new Object[stack.size()];
20
+    }
21
+
22
+    public boolean isEmpty(){
23
+        if(stack.size() > 0) return false;
24
+        return true;
25
+    }
26
+
27
+    public void push (E item) { stack.add(top++, item); }
28
+
29
+    public E pop() throws Exception{
30
+        E e = null;
31
+        if(stack.size() == 0) throw new IndexOutOfBoundsException();
32
+            for(int i = 0; i < stack.size(); i++) {
33
+                e = stack.remove(stack.size() - 1);
34
+            }
35
+            return e;
14 36
     }
15 37
 }
38
+

+ 19
- 0
src/main/java/StackArray/ObjectStack.java Wyświetl plik

@@ -1,5 +1,6 @@
1 1
 package StackArray;
2 2
 
3
+import java.util.ArrayList;
3 4
 import java.util.Arrays;
4 5
 
5 6
 /**
@@ -8,9 +9,27 @@ import java.util.Arrays;
8 9
  * @param <E>
9 10
  */
10 11
 public class ObjectStack<E> {
12
+    private ArrayList<E> stack = new ArrayList<>();
11 13
     private Object[] elements;
14
+    private int top = 0;
12 15
 
13 16
     public ObjectStack() {
17
+        elements = (E[]) new Object[stack.size()];
18
+    }
19
+
20
+    public boolean isEmpty(){
21
+        if(stack.size() > 0) return false;
22
+        return true;
23
+    }
24
+
25
+    public void push (E item) { stack.add(top++, item); }
14 26
 
27
+    public E pop() throws Exception{
28
+        E e = null;
29
+        if(stack.size() == 0) throw new IndexOutOfBoundsException();
30
+        for(int i = 0; i < stack.size(); i++) {
31
+            e = stack.remove(stack.size() - 1);
32
+        }
33
+        return e;
15 34
     }
16 35
 }

+ 17
- 2
src/main/java/StackArrayList/Stack.java Wyświetl plik

@@ -7,10 +7,25 @@ import java.util.ArrayList;
7 7
  * If you pop on an empty stack, throw an IndexOutOfBoundsException.
8 8
  */
9 9
 public class Stack<E> {
10
-    private ArrayList elements;
10
+    private ArrayList<E> stack = new ArrayList<E>();
11
+    private int top = 0;
11 12
 
13
+    public Stack(){ }
12 14
 
13
-    public Stack(){
15
+    public boolean isEmpty() {
16
+        if(stack.size() > 0) return false;
17
+        return true; }
14 18
 
19
+    public void push (E item) {
20
+        stack.add(top++, item);
21
+    }
22
+
23
+    public E pop () throws Exception{
24
+        E e = null;
25
+        if(stack.size() == 0) throw new IndexOutOfBoundsException();
26
+            for (int i = 0; i < stack.size(); i++) {
27
+                e = stack.remove(stack.size() - 1);
28
+            }
29
+            return e;
15 30
     }
16 31
 }

+ 2
- 0
src/main/java/Table/Entry.java Wyświetl plik

@@ -17,4 +17,6 @@ public class Entry<K, V> {
17 17
         return value;
18 18
     }
19 19
 
20
+    public void setValue(V value) { this.value = value; }
21
+
20 22
 }

+ 27
- 1
src/main/java/Table/Table.java Wyświetl plik

@@ -1,6 +1,7 @@
1 1
 package Table;
2 2
 
3 3
 import java.util.ArrayList;
4
+import java.util.ConcurrentModificationException;
4 5
 
5 6
 /**
6 7
  * This class needs to manage an ArrayList of Entry objects.  It needs a get method that takes a key and returns
@@ -10,8 +11,33 @@ import java.util.ArrayList;
10 11
  * Void return on `remove`.
11 12
  */
12 13
 public class Table<K, V> {
13
-    private ArrayList entries;
14
+    private ArrayList<Entry> entries;
15
+    private Entry entry;
14 16
 
15 17
     public Table() {
18
+        this.entries = new ArrayList<>();
19
+    }
20
+
21
+    public V get(K k) {
22
+        for(Entry entry : entries)
23
+            if(entry.getKey().equals(k)) {
24
+            return (V)entry.getValue();
25
+            }
26
+            return null;
27
+        }
28
+
29
+    public void put(K k, V v) {
30
+        for(Entry entry : entries) {
31
+            if (entry.getKey().equals(k)) entry.setValue(v);
32
+        }
33
+        entries.add(new Entry(k, v));
34
+    }
35
+
36
+    public void remove(K k) throws Exception{
37
+        try{
38
+        for(int i = 0; i < entries.size(); i++)
39
+            if (entries.get(i).getKey().equals(k)) entries.remove(i);
40
+        }catch (NullPointerException e) {  }
16 41
     }
17 42
 }
43
+

+ 45
- 0
src/main/java/TableNested/TableNested.java Wyświetl plik

@@ -7,5 +7,50 @@ import java.util.ArrayList;
7 7
  * Think about how nested classes should work with generics.
8 8
  */
9 9
 public class TableNested<K, V> {
10
+    private ArrayList<Entry> entries;
11
+    private Entry entry;
12
+
13
+    public TableNested() {
14
+        this.entries = new ArrayList<>();
15
+    }
16
+
17
+    public V get(K k) {
18
+        for(Entry entry : entries)
19
+            if(entry.getKey().equals(k)) {
20
+                return (V)entry.getValue();
21
+            }
22
+        return null;
23
+    }
24
+
25
+    public void put(K k, V v) {
26
+        for(Entry entry : entries) {
27
+            if (entry.getKey().equals(k)) entry.setValue(v);
28
+        }
29
+        entries.add(new Entry(k, v));
30
+    }
31
+
32
+    public void remove(K k) throws Exception{
33
+        try{
34
+            for(int i = 0; i < entries.size(); i++)
35
+                if (entries.get(i).getKey().equals(k)) entries.remove(i);
36
+        }catch (NullPointerException e) {  }
37
+    }
38
+
39
+
40
+    public class Entry<K, V> {
41
+        private K key;
42
+        private V value;
43
+
44
+        public Entry(K key, V value) {
45
+            this.key = key;
46
+            this.value = value;
47
+        }
48
+
49
+        public K getKey() { return key; }
50
+
51
+        public V getValue() { return value; }
52
+
53
+        public void setValue(V value) { this.value = value; }
54
+    }
10 55
 
11 56
 }

+ 37
- 36
src/test/java/ArrayListCombiner/ArrayListCombinerTest.java Wyświetl plik

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

+ 36
- 36
src/test/java/MapFunc/MapFuncTest.java Wyświetl plik

@@ -1,36 +1,36 @@
1
-//package MapFunc;
2
-//
3
-//import MapFunc.MapFunc;
4
-//import org.junit.Test;
5
-//
6
-//import java.util.ArrayList;
7
-//import org.junit.Assert;
8
-//
9
-//public class MapFuncTest {
10
-//    @Test
11
-//    public void testSingleTypeMap() throws Exception {
12
-//        // Given an integer array list
13
-//        ArrayList<Integer> intList = new ArrayList<>();
14
-//        intList.add(1);
15
-//        intList.add(2);
16
-//        // When it's mapped with a function to double the value
17
-//        ArrayList<Integer> mappedList = MapFunc.map(intList, num -> num*2);
18
-//        // Then all the values are doubled
19
-//        Assert.assertEquals(new Integer(2), mappedList.get(0));
20
-//        Assert.assertEquals(new Integer(4), mappedList.get(1));
21
-//    }
22
-//
23
-//    @Test
24
-//    public void testMultipleTypeMap() throws Exception {
25
-//        // Given an integer array list
26
-//        ArrayList<Integer> intList = new ArrayList<>();
27
-//        intList.add(1);
28
-//        intList.add(2);
29
-//        // When it's mapped with to string
30
-//        ArrayList<String> mappedList = MapFunc.map(intList, num -> num.toString());
31
-//        // Then all the values are doubled
32
-//        Assert.assertEquals("1", mappedList.get(0));
33
-//        Assert.assertEquals("2", mappedList.get(1));
34
-//    }
35
-//
36
-//}
1
+package MapFunc;
2
+
3
+import MapFunc.MapFunc;
4
+import org.junit.Test;
5
+
6
+import java.util.ArrayList;
7
+import org.junit.Assert;
8
+
9
+public class MapFuncTest {
10
+    @Test
11
+    public void testSingleTypeMap() throws Exception {
12
+        // Given an integer array list
13
+        ArrayList<Integer> intList = new ArrayList<>();
14
+        intList.add(1);
15
+        intList.add(2);
16
+        // When it's mapped with a function to double the value
17
+        ArrayList<Integer> mappedList = MapFunc.map(intList, num -> num*2);
18
+        // Then all the values are doubled
19
+        Assert.assertEquals(new Integer(2), mappedList.get(0));
20
+        Assert.assertEquals(new Integer(4), mappedList.get(1));
21
+    }
22
+
23
+    @Test
24
+    public void testMultipleTypeMap() throws Exception {
25
+        // Given an integer array list
26
+        ArrayList<Integer> intList = new ArrayList<>();
27
+        intList.add(1);
28
+        intList.add(2);
29
+        // When it's mapped with to string
30
+        ArrayList<String> mappedList = MapFunc.map(intList, num -> num.toString());
31
+        // Then all the values are doubled
32
+        Assert.assertEquals("1", mappedList.get(0));
33
+        Assert.assertEquals("2", mappedList.get(1));
34
+    }
35
+
36
+}

+ 41
- 41
src/test/java/StackArray/GenericStackTest.java Wyświetl plik

@@ -1,41 +1,41 @@
1
-//package StackArray;
2
-//
3
-//import org.junit.Assert;
4
-//import org.junit.Test;
5
-//
6
-//public class GenericStackTest {
7
-//    @Test
8
-//    public void testPushingGrowsTheStack() throws Exception {
9
-//        // Given an empty stack
10
-//        GenericStack<String> stack = new GenericStack<>();
11
-//
12
-//        // Assert that it is empty.
13
-//        Assert.assertEquals(true, stack.isEmpty());
14
-//        // When we push something onto the stack
15
-//        stack.push("foobar");
16
-//        // Then it shouldn't be empty
17
-//        Assert.assertEquals(false, stack.isEmpty());
18
-//    }
19
-//
20
-//    @Test
21
-//    public void testPushingAndPoppingOrder() throws Exception {
22
-//        // Given an empty stack
23
-//        GenericStack<String> stack = new GenericStack<>();
24
-//        // When we push two elements on it
25
-//        stack.push("foo");
26
-//        stack.push("bar");
27
-//        // Then we should see them returned in the correct order
28
-//        Assert.assertEquals("bar", stack.pop());
29
-//        Assert.assertEquals("foo", stack.pop());
30
-//    }
31
-//
32
-//    @Test(expected = IndexOutOfBoundsException.class)
33
-//    public void testPopFirst() throws Exception {
34
-//        // Given an empty stack
35
-//        GenericStack<String> stack = new GenericStack<>();
36
-//        // When it's popped
37
-//        stack.pop();
38
-//        // Then we should get an exception
39
-//    }
40
-//
41
-//}
1
+package StackArray;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class GenericStackTest {
7
+    @Test
8
+    public void testPushingGrowsTheStack() throws Exception {
9
+        // Given an empty stack
10
+        GenericStack<String> stack = new GenericStack<>();
11
+
12
+        // Assert that it is empty.
13
+        Assert.assertEquals(true, stack.isEmpty());
14
+        // When we push something onto the stack
15
+        stack.push("foobar");
16
+        // Then it shouldn't be empty
17
+        Assert.assertEquals(false, stack.isEmpty());
18
+    }
19
+
20
+    @Test
21
+    public void testPushingAndPoppingOrder() throws Exception {
22
+        // Given an empty stack
23
+        GenericStack<String> stack = new GenericStack<>();
24
+        // When we push two elements on it
25
+        stack.push("foo");
26
+        stack.push("bar");
27
+        // Then we should see them returned in the correct order
28
+        Assert.assertEquals("bar", stack.pop());
29
+        Assert.assertEquals("foo", stack.pop());
30
+    }
31
+
32
+    @Test(expected = IndexOutOfBoundsException.class)
33
+    public void testPopFirst() throws Exception {
34
+        // Given an empty stack
35
+        GenericStack<String> stack = new GenericStack<>();
36
+        // When it's popped
37
+        stack.pop();
38
+        // Then we should get an exception
39
+    }
40
+
41
+}

+ 39
- 39
src/test/java/StackArray/ObjectStackTest.java Wyświetl plik

@@ -1,39 +1,39 @@
1
-//package StackArray;
2
-//
3
-//import org.junit.Assert;
4
-//import org.junit.Test;
5
-//
6
-//public class ObjectStackTest {
7
-//    @Test
8
-//    public void testPushingGrowsTheStack() throws Exception {
9
-//        // Given an empty stack
10
-//        ObjectStack<String> stack = new ObjectStack<>();
11
-//        // Assert that it is empty.
12
-//        Assert.assertEquals(true, stack.isEmpty());
13
-//        // When we push something onto the stack
14
-//        stack.push("foobar");
15
-//        // Then it shouldn't be empty
16
-//        Assert.assertEquals(false, stack.isEmpty());
17
-//    }
18
-//
19
-//    @Test
20
-//    public void testPushingAndPoppingOrder() throws Exception {
21
-//        // Given an empty stack
22
-//        ObjectStack<String> stack = new ObjectStack<>();
23
-//        // When we push two elements on it
24
-//        stack.push("foo");
25
-//        stack.push("bar");
26
-//        // Then we should see them returned in the correct order
27
-//        Assert.assertEquals("bar", stack.pop());
28
-//        Assert.assertEquals("foo", stack.pop());
29
-//    }
30
-//
31
-//    @Test(expected = IndexOutOfBoundsException.class)
32
-//    public void testPopFirst() throws Exception {
33
-//        // Given an empty stack
34
-//        ObjectStack<String> stack = new ObjectStack<>();
35
-//        // When it's popped
36
-//        stack.pop();
37
-//        // Then we should get an exception
38
-//    }
39
-//}
1
+package StackArray;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class ObjectStackTest {
7
+    @Test
8
+    public void testPushingGrowsTheStack() throws Exception {
9
+        // Given an empty stack
10
+        ObjectStack<String> stack = new ObjectStack<>();
11
+        // Assert that it is empty.
12
+        Assert.assertEquals(true, stack.isEmpty());
13
+        // When we push something onto the stack
14
+        stack.push("foobar");
15
+        // Then it shouldn't be empty
16
+        Assert.assertEquals(false, stack.isEmpty());
17
+    }
18
+
19
+    @Test
20
+    public void testPushingAndPoppingOrder() throws Exception {
21
+        // Given an empty stack
22
+        ObjectStack<String> stack = new ObjectStack<>();
23
+        // When we push two elements on it
24
+        stack.push("foo");
25
+        stack.push("bar");
26
+        // Then we should see them returned in the correct order
27
+        Assert.assertEquals("bar", stack.pop());
28
+        Assert.assertEquals("foo", stack.pop());
29
+    }
30
+
31
+    @Test(expected = IndexOutOfBoundsException.class)
32
+    public void testPopFirst() throws Exception {
33
+        // Given an empty stack
34
+        ObjectStack<String> stack = new ObjectStack<>();
35
+        // When it's popped
36
+        stack.pop();
37
+        // Then we should get an exception
38
+    }
39
+}

+ 45
- 45
src/test/java/StackArrayList/StackTest.java Wyświetl plik

@@ -1,45 +1,45 @@
1
-//package StackArrayList;
2
-//
3
-//import org.junit.Test;
4
-//
5
-//import org.junit.Assert;
6
-//
7
-//public class StackTest {
8
-//    @Test
9
-//    public void testEmptyStackStopsBeingEmptyWhenAnItemIsAdded() throws Exception {
10
-//        // Given an empty stack
11
-//        Stack<String> stack = new Stack<>();
12
-//        // Assert that it starts empty
13
-//        Assert.assertEquals(true, stack.isEmpty());
14
-//        // When an element gets pushed
15
-//        stack.push("foobar");
16
-//        // Then the stack should not be empty.
17
-//        Assert.assertEquals(false, stack.isEmpty());
18
-//    }
19
-//
20
-//    @Test
21
-//    public void testTwoItemsPushedComeOutInCorrectOrder() throws Exception {
22
-//        // Given an empty stack
23
-//        Stack<String> stack = new Stack<>();
24
-//
25
-//        //When two items are pushed
26
-//        stack.push("foo");
27
-//        stack.push("bar");
28
-//
29
-//        // Then they should come off in reverse order.
30
-//        Assert.assertEquals("bar", stack.pop());
31
-//        Assert.assertEquals("foo", stack.pop());
32
-//
33
-//        // And then the stack should be empty
34
-//        Assert.assertEquals(true, stack.isEmpty());
35
-//    }
36
-//
37
-//    @Test(expected = IndexOutOfBoundsException.class)
38
-//    public void testPopFirst() throws Exception {
39
-//        // Given an empty stack
40
-//        Stack<String> stack = new Stack<>();
41
-//        // Then it is popped
42
-//        stack.pop();
43
-//        // We should get an exception
44
-//    }
45
-//}
1
+package StackArrayList;
2
+
3
+import org.junit.Test;
4
+
5
+import org.junit.Assert;
6
+
7
+public class StackTest {
8
+    @Test
9
+    public void testEmptyStackStopsBeingEmptyWhenAnItemIsAdded() throws Exception {
10
+        // Given an empty stack
11
+        Stack<String> stack = new Stack<>();
12
+        // Assert that it starts empty
13
+        Assert.assertEquals(true, stack.isEmpty());
14
+        // When an element gets pushed
15
+        stack.push("foobar");
16
+        // Then the stack should not be empty.
17
+        Assert.assertEquals(false, stack.isEmpty());
18
+    }
19
+
20
+    @Test
21
+    public void testTwoItemsPushedComeOutInCorrectOrder() throws Exception {
22
+        // Given an empty stack
23
+        Stack<String> stack = new Stack<>();
24
+
25
+        //When two items are pushed
26
+        stack.push("foo");
27
+        stack.push("bar");
28
+
29
+        // Then they should come off in reverse order.
30
+        Assert.assertEquals("bar", stack.pop());
31
+        Assert.assertEquals("foo", stack.pop());
32
+
33
+        // And then the stack should be empty
34
+        Assert.assertEquals(true, stack.isEmpty());
35
+    }
36
+
37
+    @Test(expected = IndexOutOfBoundsException.class)
38
+    public void testPopFirst() throws Exception {
39
+        // Given an empty stack
40
+        Stack<String> stack = new Stack<>();
41
+        // Then it is popped
42
+        stack.pop();
43
+        // We should get an exception
44
+    }
45
+}

+ 15
- 15
src/test/java/Swap/SwapTest.java Wyświetl plik

@@ -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
+        Number[] result = Swap.swap(0,1, 1.5, 2,3);
13
+        Number[] expected = {2, 1.5, 3};
14
+        Assert.assertArrayEquals(expected, result);
15
+    }
16
+}

+ 50
- 50
src/test/java/Table/TableTest.java Wyświetl plik

@@ -1,50 +1,50 @@
1
-//package Table;
2
-//
3
-//import org.junit.Assert;
4
-//import org.junit.Test;
5
-//
6
-//public class TableTest {
7
-//    @Test
8
-//    public void testGetWithoutAnItemReturnsNull() throws Exception {
9
-//        // Given an empty table
10
-//        Table<String, Integer> table = new Table<String, Integer>();
11
-//        // When we try and get an item then it returns null
12
-//        Assert.assertEquals(table.get("foo"), null);
13
-//    }
14
-//
15
-//    @Test
16
-//    public void testPutAnItemReturnsAndDoesNotDelete() throws Exception {
17
-//        //Given an empty table
18
-//        Table<String, Integer> table = new Table<String, Integer>();
19
-//        // When we put an item in it
20
-//        table.put("foo", 1);
21
-//        // Then we should be able to get it's value
22
-//        Assert.assertEquals(table.get("foo"), new Integer(1));
23
-//        // And then we should be able to get it again as it wasn't removed
24
-//        Assert.assertEquals(table.get("foo"), new Integer(1));
25
-//    }
26
-//
27
-//    @Test
28
-//    public void testOverwritingAnItem() throws Exception {
29
-//        //Given an empty table
30
-//        Table<String, Integer> table = new Table<String, Integer>();
31
-//        // When we put an item in it
32
-//        table.put("foo", 1);
33
-//        // And we put a new value with the same key
34
-//        table.put("foo", 2);
35
-//        // Then we should get back the new value
36
-//        Assert.assertEquals(table.get("foo"), new Integer(2));
37
-//    }
38
-//
39
-//    @Test
40
-//    public void testRemoveAnItem() throws Exception {
41
-//        //Given an empty table
42
-//        Table<String, Integer> table = new Table<String, Integer>();
43
-//        // When we put an item in it
44
-//        table.put("foo", 1);
45
-//        // And we remove that item
46
-//        table.remove("foo");
47
-//        // Then we should get back null for that balue
48
-//        Assert.assertEquals(table.get("foo"), null);
49
-//    }
50
-//}
1
+package Table;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class TableTest {
7
+    @Test
8
+    public void testGetWithoutAnItemReturnsNull() throws Exception {
9
+        // Given an empty table
10
+        Table<String, Integer> table = new Table<String, Integer>();
11
+        // When we try and get an item then it returns null
12
+        Assert.assertEquals(table.get("foo"), null);
13
+    }
14
+
15
+    @Test
16
+    public void testPutAnItemReturnsAndDoesNotDelete() throws Exception {
17
+        //Given an empty table
18
+        Table<String, Integer> table = new Table<String, Integer>();
19
+        // When we put an item in it
20
+        table.put("foo", 1);
21
+        // Then we should be able to get it's value
22
+        Assert.assertEquals(table.get("foo"), new Integer(1));
23
+        // And then we should be able to get it again as it wasn't removed
24
+        Assert.assertEquals(table.get("foo"), new Integer(1));
25
+    }
26
+
27
+    @Test
28
+    public void testOverwritingAnItem() throws Exception {
29
+        //Given an empty table
30
+        Table<String, Integer> table = new Table<String, Integer>();
31
+        // When we put an item in it
32
+        table.put("foo", 1);
33
+        // And we put a new value with the same key
34
+        table.put("foo", 2);
35
+        // Then we should get back the new value
36
+        Assert.assertEquals(table.get("foo"), new Integer(2));
37
+    }
38
+
39
+    @Test
40
+    public void testRemoveAnItem() throws Exception {
41
+        //Given an empty table
42
+        Table<String, Integer> table = new Table<String, Integer>();
43
+        // When we put an item in it
44
+        table.put("foo", 1);
45
+        // And we remove that item
46
+        table.remove("foo");
47
+        // Then we should get back null for that value
48
+        Assert.assertEquals(table.get("foo"), null);
49
+    }
50
+}

+ 50
- 50
src/test/java/TableNested/TableNestedTest.java Wyświetl plik

@@ -1,50 +1,50 @@
1
-//package TableNested;
2
-//
3
-//import org.junit.Assert;
4
-//import org.junit.Test;
5
-//
6
-//public class TableNestedTest {
7
-//    @Test
8
-//    public void testGetWithoutAnItemReturnsNull() throws Exception {
9
-//        // Given an empty table
10
-//        TableNested<String, Integer> table = new TableNested<String, Integer>();
11
-//        // When we try and get an item then it returns null
12
-//        Assert.assertEquals(table.get("foo"), null);
13
-//    }
14
-//
15
-//    @Test
16
-//    public void testPutAnItemReturnsAndDoesNotDelete() throws Exception {
17
-//        //Given an empty table
18
-//        TableNested<String, Integer> table = new TableNested<String, Integer>();
19
-//        // When we put an item in it
20
-//        table.put("foo", 1);
21
-//        // Then we should be able to get it's value
22
-//        Assert.assertEquals(table.get("foo"), new Integer(1));
23
-//        // And then we should be able to get it again as it wasn't removed
24
-//        Assert.assertEquals(table.get("foo"), new Integer(1));
25
-//    }
26
-//
27
-//    @Test
28
-//    public void testOverwritingAnItem() throws Exception {
29
-//        //Given an empty table
30
-//        TableNested<String, Integer> table = new TableNested<String, Integer>();
31
-//        // When we put an item in it
32
-//        table.put("foo", 1);
33
-//        // And we put a new value with the same key
34
-//        table.put("foo", 2);
35
-//        // Then we should get back the new value
36
-//        Assert.assertEquals(table.get("foo"), new Integer(2));
37
-//    }
38
-//
39
-//    @Test
40
-//    public void testRemoveAnItem() throws Exception {
41
-//        //Given an empty table
42
-//        TableNested<String, Integer> table = new TableNested<String, Integer>();
43
-//        // When we put an item in it
44
-//        table.put("foo", 1);
45
-//        // And we remove that item
46
-//        table.remove("foo");
47
-//        // Then we should get back null for that balue
48
-//        Assert.assertEquals(table.get("foo"), null);
49
-//    }
50
-//}
1
+package TableNested;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class TableNestedTest {
7
+    @Test
8
+    public void testGetWithoutAnItemReturnsNull() throws Exception {
9
+        // Given an empty table
10
+        TableNested<String, Integer> table = new TableNested<String, Integer>();
11
+        // When we try and get an item then it returns null
12
+        Assert.assertEquals(table.get("foo"), null);
13
+    }
14
+
15
+    @Test
16
+    public void testPutAnItemReturnsAndDoesNotDelete() throws Exception {
17
+        //Given an empty table
18
+        TableNested<String, Integer> table = new TableNested<String, Integer>();
19
+        // When we put an item in it
20
+        table.put("foo", 1);
21
+        // Then we should be able to get it's value
22
+        Assert.assertEquals(table.get("foo"), new Integer(1));
23
+        // And then we should be able to get it again as it wasn't removed
24
+        Assert.assertEquals(table.get("foo"), new Integer(1));
25
+    }
26
+
27
+    @Test
28
+    public void testOverwritingAnItem() throws Exception {
29
+        //Given an empty table
30
+        TableNested<String, Integer> table = new TableNested<String, Integer>();
31
+        // When we put an item in it
32
+        table.put("foo", 1);
33
+        // And we put a new value with the same key
34
+        table.put("foo", 2);
35
+        // Then we should get back the new value
36
+        Assert.assertEquals(table.get("foo"), new Integer(2));
37
+    }
38
+
39
+    @Test
40
+    public void testRemoveAnItem() throws Exception {
41
+        //Given an empty table
42
+        TableNested<String, Integer> table = new TableNested<String, Integer>();
43
+        // When we put an item in it
44
+        table.put("foo", 1);
45
+        // And we remove that item
46
+        table.remove("foo");
47
+        // Then we should get back null for that balue
48
+        Assert.assertEquals(table.get("foo"), null);
49
+    }
50
+}