Browse Source

almost finished

Carolynn Vansant 6 years ago
parent
commit
9d58f8d8cf

+ 15
- 10
src/main/java/com/zipcodewilmington/phonebook/PhoneBook.java View File

@@ -27,18 +27,26 @@ public class PhoneBook {
27 27
         }
28 28
     }
29 29
 
30
-    //add and remove numbers from existing names
31
-    //unfinished, no test cases yet
32
-    public void modifyNumbers(String name, ArrayList<String> number) {
30
+    //add numbers to existing entries
31
+    //no test cases yet
32
+    public void addNumberToEntry(String name, String number) {
33 33
         for (Map.Entry<String, ArrayList<String>> entry : treeMap.entrySet()) {
34
-            ArrayList<String> value = entry.getValue();
35
-            for (String firstNumber : value) {
36
-
34
+            if (name.equals(entry.getKey())) {
35
+                ArrayList<String> value = entry.getValue();
36
+                value.add(number);
37 37
             }
38 38
         }
39
-
40 39
     }
41 40
 
41
+    //remove numbers from existing entries
42
+    //no test cases yet
43
+    public void removeNumberFromEntry(String name, String number) {
44
+        for (Map.Entry<String, ArrayList<String>> entry : treeMap.entrySet()) {
45
+            if (entry.getValue().contains(number)) {
46
+                entry.getValue().remove(number);
47
+            }
48
+        }
49
+    }
42 50
 
43 51
     //remove a name & number entry
44 52
     public void removeEntry(String name) {
@@ -77,7 +85,4 @@ public class PhoneBook {
77 85
         return printOut.toString();
78 86
     }
79 87
 
80
-
81
-
82 88
 }
83
-

+ 24
- 2
src/test/java/com/zipcodewilmington/phonebook/PhoneBookTest.java View File

@@ -29,23 +29,44 @@ public class PhoneBookTest {
29 29
     }
30 30
 
31 31
     @Test
32
-    public void testAdd() {
33
-
32
+    public void testInputEntry() {
34 33
         //Given
35 34
         PhoneBook book = new PhoneBook();
36 35
 
37 36
         ArrayList<String> expectedAddition = new ArrayList<String>();
38 37
         expectedAddition.add("302-555-2222");
39 38
         expectedAddition.add("302-555-3456");
39
+
40 40
         //When
41 41
         book.inputEntry("Bob", expectedAddition);
42 42
         ArrayList<String> actualAddition = new ArrayList<String>(book.lookup("Bob"));
43 43
 
44 44
         //Then
45 45
         Assert.assertEquals(expectedAddition, actualAddition);
46
+    }
47
+
48
+    @Test
49
+    public void addNumberToEntry() {
50
+        //Given
51
+        PhoneBook book = new PhoneBook();
52
+        ArrayList<String> bobNumber = new ArrayList<String>();
53
+        bobNumber.add("302-555-2222");
54
+        book.inputEntry("Bob", bobNumber);
55
+        book.display();
56
+        //Expected
57
+        ArrayList<String> expectedAddition = new ArrayList<String>();
58
+        expectedAddition.add("302-555-2222");
59
+        expectedAddition.add("302-555-1111");
60
+        //When
61
+        book.addNumberToEntry("Bob", "302-555-1111");
62
+        ArrayList<String> actualAddition = book.lookup("Bob");
63
+        //Then
64
+        Assert.assertEquals(expectedAddition, actualAddition);
46 65
 
47 66
     }
48 67
 
68
+    //add test for removeNumberFromEntry
69
+
49 70
     @Test
50 71
     public void testRemoveEntry() {
51 72
 
@@ -129,6 +150,7 @@ public class PhoneBookTest {
129 150
         String expectedName = "Bob";
130 151
         ArrayList<String> bobNumber = new ArrayList<String>();
131 152
         bobNumber.add("302-555-2223");
153
+        bobNumber.add("302-555-5555");
132 154
         book.inputEntry(expectedName, bobNumber);
133 155
 
134 156
         //When;