Selaa lähdekoodia

Added the fourth microlab.

Zach Marcin 7 vuotta sitten
vanhempi
commit
76b58d7fce

+ 2
- 1
README.md Näytä tiedosto

@@ -12,4 +12,5 @@ Implement Table<K,V> so that it manages an ArrayList of Entry<K,V>.  You must im
12 12
     * `put` which takes a key and value and sets the value in the ArrayList to Entry(key, value);
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
-4.
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.

+ 11
- 0
src/main/java/TableNested/TableNested.java Näytä tiedosto

@@ -0,0 +1,11 @@
1
+package TableNested;
2
+
3
+import java.util.ArrayList;
4
+
5
+/**
6
+ * All you need to do for this microlab is take the Table and Entry from the last one and make Entry a nested class.
7
+ * Think about how nested classes should work with generics.
8
+ */
9
+public class TableNested<K, V> {
10
+
11
+}

+ 50
- 0
src/test/java/TableNested/TableNestedTest.java Näytä tiedosto

@@ -0,0 +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
+//}