Browse Source

One last test to pass and then redoing with person class

Daniel Horowitz 6 years ago
parent
commit
e6148e225e

+ 17
- 12
src/main/java/com/zipcodewilmington/phonebook/PhoneBook.java View File

@@ -1,5 +1,7 @@
1 1
 package com.zipcodewilmington.phonebook;
2 2
 
3
+import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
4
+
3 5
 import java.util.*;
4 6
 
5 7
 /**
@@ -19,17 +21,19 @@ public class PhoneBook {
19 21
 
20 22
 
21 23
     public void addEntry(String name, String... number) {
22
-        ArrayList<String> listOfPhoneNumbers = new ArrayList<String>(Arrays.asList(number));
23
-        myTree.put(name, listOfPhoneNumbers);
24
+        ArrayList<String> allNumbers = new ArrayList<String>(Arrays.asList(number));
25
+        myTree.put(name, allNumbers);
24 26
 
25 27
     }
26 28
 
27 29
     public void additionalPhoneNumberToKey(String name, String number) {
30
+
28 31
         myTree.get(name).add(number);
29 32
     }
30 33
 
31 34
 
32 35
     public void removeNumberFromName(String name, String number) {
36
+
33 37
         myTree.get(name).remove(number);
34 38
     }
35 39
 
@@ -43,7 +47,7 @@ public class PhoneBook {
43 47
         ArrayList<String> matchingNumbers = myTree.get(name);
44 48
         String listedNumbers = "";
45 49
         for (String phoneNumbers : matchingNumbers) {
46
-            listedNumbers +=phoneNumbers + "\n";
50
+            listedNumbers +=phoneNumbers + ", ";
47 51
         }
48 52
        return listedNumbers.trim();
49 53
 
@@ -62,21 +66,22 @@ public class PhoneBook {
62 66
         return allNames.trim();
63 67
     }
64 68
 
69
+
65 70
     public String listPhoneBook() {
66 71
 
67 72
         Set<String> contacts = myTree.keySet();
68
-        StringBuilder printBook = new StringBuilder();
73
+        String phoneBook = "";
69 74
 
70 75
         for (String name : contacts) {
71
-            printBook.append(name).append(": ");
72
-            for (int x = 0; x<myTree.get(name).size(); x++) {
73
-                printBook.append(x).append("  ");
74
-            } printBook.append("\n");
76
+            phoneBook += name + ": ";
77
+          for (int x = 0; x<myTree.get(name).size(); x++) {
78
+                phoneBook += myTree.get(name).get(x) + ", ";
79
+            }
75 80
 
76 81
         }
77
-        String result = printBook.toString();
78 82
 
79
-        return result;
83
+
84
+        return phoneBook.trim();
80 85
     }
81 86
 
82 87
     public String reverseLookup(String number) {
@@ -104,12 +109,12 @@ public class PhoneBook {
104 109
         PhoneBook phonebookEntry = new PhoneBook();
105 110
 
106 111
         phonebookEntry.addEntry("Brian", "3027619121");
107
-        phonebookEntry.addEntry("Dan", "4846394190");
112
+        phonebookEntry.addEntry("Dan", "4846394190", "9897878787");
108 113
         phonebookEntry.addEntry("Garret", "3027894586");
109 114
         phonebookEntry.addEntry("Luke", "3147619121");
110 115
         phonebookEntry.addEntry("Kate", "4899994190");
111 116
         phonebookEntry.addEntry("Lenore", "3097894586");
112
-
117
+        phonebookEntry.removeEntry("Dan");
113 118
 
114 119
 
115 120
 

+ 19
- 0
src/test/java/com/zipcodewilmington/phonebook/PersonTest.java View File

@@ -0,0 +1,19 @@
1
+package com.zipcodewilmington.phonebook;
2
+
3
+//import org.junit.Assert;
4
+//import org.junit.Before;
5
+//import org.junit.Test;
6
+//import org.junit.experimental.theories.suppliers.TestedOn;
7
+//
8
+//public class PersonTest {
9
+//    @Test
10
+//    public void testGetName() {
11
+//
12
+//        Person p = new Person("Kate");
13
+//        String name = p.getName();
14
+//
15
+//        Assert.assertTrue(name == "Kate");
16
+//
17
+//    }
18
+//
19
+//}

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

@@ -5,6 +5,8 @@ import org.junit.Before;
5 5
 import org.junit.Test;
6 6
 import org.junit.experimental.theories.suppliers.TestedOn;
7 7
 
8
+import java.util.ArrayList;
9
+
8 10
 
9 11
 /**
10 12
  * Created by leon on 1/23/18.
@@ -12,24 +14,26 @@ import org.junit.experimental.theories.suppliers.TestedOn;
12 14
 public class PhoneBookTest {
13 15
 
14 16
 
17
+
15 18
     @Test
16 19
     public void addTest() {
17 20
         PhoneBook testBook = new PhoneBook();
18 21
         testBook.addEntry("Luke", "6109998787");
19 22
         String testNumber = testBook.lookupNumber("Luke");
20
-        Assert.assertTrue(testNumber.equals("6109998787"));
21
-
22
-    }
23
-
24
-    @Test
25
-    public void addTest1() {
26
-        PhoneBook testBook = new PhoneBook();
27
-        testBook.addEntry("Kate", "4846569090");
28
-        String testNumber = testBook.lookupNumber("Kate");
29
-        Assert.assertTrue(testNumber.equals("4846569090"));
23
+        Assert.assertTrue(testNumber.equals("6109998787,"));
30 24
 
31 25
     }
32 26
 
27
+//    @Test
28
+//    public void addTest1() {
29
+//        PhoneBook testBook = new PhoneBook();
30
+//        Person expected = new Person("name", "arraylist of phone numbers");
31
+//        testBook.addEntry("Kate", expected);
32
+////        Person actual = testBook.lookupNumber("Kate");
33
+////        Assert.assertTrue(expected.equals(actual));
34
+//
35
+//    }
36
+//
33 37
     @Test
34 38
     public void removeTest1() {
35 39
         PhoneBook testBook = new PhoneBook();
@@ -44,18 +48,9 @@ public class PhoneBookTest {
44 48
     @Test
45 49
     public void stringLookupTest() {
46 50
         PhoneBook testBook = new PhoneBook();
47
-        testBook.addEntry("Kate", "4846569090");
51
+        testBook.addEntry("Kate", "4846569090", "9899890099");
48 52
         String testNumber = testBook.lookupNumber("Kate");
49
-        Assert.assertFalse(testNumber.equals("4846587091"));
50
-
51
-    }
52
-
53
-    @Test
54
-    public void stringLookupTest1() {
55
-        PhoneBook testBook = new PhoneBook();
56
-        testBook.addEntry("Kate", "4846569090");
57
-        String testNumber = testBook.lookupNumber("Kate");
58
-        Assert.assertTrue(testNumber.equals("4846569090"));
53
+        Assert.assertTrue(testNumber.equals("4846569090, 9899890099,"));
59 54
 
60 55
     }
61 56
 
@@ -66,7 +61,7 @@ public class PhoneBookTest {
66 61
         testBook.addEntry("Adam", "4864569090");
67 62
         testBook.addEntry("Zeke", "4787869090");
68 63
         String actual = testBook.listNames();
69
-        String expected = "Adam\nKate\nZeke\n";
64
+        String expected = "Adam\nKate\nZeke";
70 65
         Assert.assertEquals(actual, expected);
71 66
 
72 67
 
@@ -76,10 +71,10 @@ public class PhoneBookTest {
76 71
     public void listPhonebookTest1() {
77 72
         PhoneBook testBook = new PhoneBook();
78 73
         testBook.addEntry("Kate", "4846569090");
79
-        testBook.addEntry("Adam", "4864569090");
74
+        testBook.addEntry("Adam", "4864569090", "7879891212");
80 75
         testBook.addEntry("Zeke", "4787869090");
81 76
         String actual = testBook.listPhoneBook();
82
-        String expected = "Adam: 4864569090\nKate: 4846569090\nZeke: 4787869090\n";
77
+        String expected = "Adam: 4864569090, 7879891212, Kate: 4846569090, Zeke: 4787869090,";
83 78
         Assert.assertEquals(expected, actual);
84 79
 
85 80
 
@@ -93,4 +88,15 @@ public class PhoneBookTest {
93 88
 
94 89
     }
95 90
 
91
+
92
+
93
+    @Test
94
+    public void additionalPhoneNumberToKeyTest() {
95
+        PhoneBook testBook = new PhoneBook();
96
+        testBook.addEntry("Kate", "5659871212");
97
+        testBook.additionalPhoneNumberToKey("Kate", "4999999999");
98
+        String testNumber = testBook.lookupNumber("Kate");
99
+        Assert.assertTrue(testNumber.equals("5659871212, 4999999999,"));
100
+
101
+    }
96 102
 }