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
 package com.zipcodewilmington.phonebook;
1
 package com.zipcodewilmington.phonebook;
2
 
2
 
3
+import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
4
+
3
 import java.util.*;
5
 import java.util.*;
4
 
6
 
5
 /**
7
 /**
19
 
21
 
20
 
22
 
21
     public void addEntry(String name, String... number) {
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
     public void additionalPhoneNumberToKey(String name, String number) {
29
     public void additionalPhoneNumberToKey(String name, String number) {
30
+
28
         myTree.get(name).add(number);
31
         myTree.get(name).add(number);
29
     }
32
     }
30
 
33
 
31
 
34
 
32
     public void removeNumberFromName(String name, String number) {
35
     public void removeNumberFromName(String name, String number) {
36
+
33
         myTree.get(name).remove(number);
37
         myTree.get(name).remove(number);
34
     }
38
     }
35
 
39
 
43
         ArrayList<String> matchingNumbers = myTree.get(name);
47
         ArrayList<String> matchingNumbers = myTree.get(name);
44
         String listedNumbers = "";
48
         String listedNumbers = "";
45
         for (String phoneNumbers : matchingNumbers) {
49
         for (String phoneNumbers : matchingNumbers) {
46
-            listedNumbers +=phoneNumbers + "\n";
50
+            listedNumbers +=phoneNumbers + ", ";
47
         }
51
         }
48
        return listedNumbers.trim();
52
        return listedNumbers.trim();
49
 
53
 
62
         return allNames.trim();
66
         return allNames.trim();
63
     }
67
     }
64
 
68
 
69
+
65
     public String listPhoneBook() {
70
     public String listPhoneBook() {
66
 
71
 
67
         Set<String> contacts = myTree.keySet();
72
         Set<String> contacts = myTree.keySet();
68
-        StringBuilder printBook = new StringBuilder();
73
+        String phoneBook = "";
69
 
74
 
70
         for (String name : contacts) {
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
     public String reverseLookup(String number) {
87
     public String reverseLookup(String number) {
104
         PhoneBook phonebookEntry = new PhoneBook();
109
         PhoneBook phonebookEntry = new PhoneBook();
105
 
110
 
106
         phonebookEntry.addEntry("Brian", "3027619121");
111
         phonebookEntry.addEntry("Brian", "3027619121");
107
-        phonebookEntry.addEntry("Dan", "4846394190");
112
+        phonebookEntry.addEntry("Dan", "4846394190", "9897878787");
108
         phonebookEntry.addEntry("Garret", "3027894586");
113
         phonebookEntry.addEntry("Garret", "3027894586");
109
         phonebookEntry.addEntry("Luke", "3147619121");
114
         phonebookEntry.addEntry("Luke", "3147619121");
110
         phonebookEntry.addEntry("Kate", "4899994190");
115
         phonebookEntry.addEntry("Kate", "4899994190");
111
         phonebookEntry.addEntry("Lenore", "3097894586");
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

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
 import org.junit.Test;
5
 import org.junit.Test;
6
 import org.junit.experimental.theories.suppliers.TestedOn;
6
 import org.junit.experimental.theories.suppliers.TestedOn;
7
 
7
 
8
+import java.util.ArrayList;
9
+
8
 
10
 
9
 /**
11
 /**
10
  * Created by leon on 1/23/18.
12
  * Created by leon on 1/23/18.
12
 public class PhoneBookTest {
14
 public class PhoneBookTest {
13
 
15
 
14
 
16
 
17
+
15
     @Test
18
     @Test
16
     public void addTest() {
19
     public void addTest() {
17
         PhoneBook testBook = new PhoneBook();
20
         PhoneBook testBook = new PhoneBook();
18
         testBook.addEntry("Luke", "6109998787");
21
         testBook.addEntry("Luke", "6109998787");
19
         String testNumber = testBook.lookupNumber("Luke");
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
     @Test
37
     @Test
34
     public void removeTest1() {
38
     public void removeTest1() {
35
         PhoneBook testBook = new PhoneBook();
39
         PhoneBook testBook = new PhoneBook();
44
     @Test
48
     @Test
45
     public void stringLookupTest() {
49
     public void stringLookupTest() {
46
         PhoneBook testBook = new PhoneBook();
50
         PhoneBook testBook = new PhoneBook();
47
-        testBook.addEntry("Kate", "4846569090");
51
+        testBook.addEntry("Kate", "4846569090", "9899890099");
48
         String testNumber = testBook.lookupNumber("Kate");
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
         testBook.addEntry("Adam", "4864569090");
61
         testBook.addEntry("Adam", "4864569090");
67
         testBook.addEntry("Zeke", "4787869090");
62
         testBook.addEntry("Zeke", "4787869090");
68
         String actual = testBook.listNames();
63
         String actual = testBook.listNames();
69
-        String expected = "Adam\nKate\nZeke\n";
64
+        String expected = "Adam\nKate\nZeke";
70
         Assert.assertEquals(actual, expected);
65
         Assert.assertEquals(actual, expected);
71
 
66
 
72
 
67
 
76
     public void listPhonebookTest1() {
71
     public void listPhonebookTest1() {
77
         PhoneBook testBook = new PhoneBook();
72
         PhoneBook testBook = new PhoneBook();
78
         testBook.addEntry("Kate", "4846569090");
73
         testBook.addEntry("Kate", "4846569090");
79
-        testBook.addEntry("Adam", "4864569090");
74
+        testBook.addEntry("Adam", "4864569090", "7879891212");
80
         testBook.addEntry("Zeke", "4787869090");
75
         testBook.addEntry("Zeke", "4787869090");
81
         String actual = testBook.listPhoneBook();
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
         Assert.assertEquals(expected, actual);
78
         Assert.assertEquals(expected, actual);
84
 
79
 
85
 
80
 
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
 }