Browse Source

the real final commit

Jared Norris 6 years ago
parent
commit
0dabbce429
2 changed files with 21 additions and 20 deletions
  1. 6
    6
      PhoneBook.java
  2. 15
    14
      PhoneBookTest.java

+ 6
- 6
PhoneBook.java View File

@@ -17,6 +17,7 @@ public class PhoneBook {
17 17
     public void remove (String phoneNumber) {
18 18
         ArrayList<String> edit = new ArrayList<String>();
19 19
         Set<String> keys = phoneBook.keySet();
20
+        
20 21
         for (String key : keys) {
21 22
             if (phoneBook.get(key).contains(phoneNumber)) {
22 23
                 edit = phoneBook.get(key);
@@ -31,12 +32,11 @@ public class PhoneBook {
31 32
     }
32 33
     
33 34
     public String lookup(String name) {
34
-        
35
-        return phoneBook.containsKey(name) ?
36
-               phoneBook.get(name)
37
-                        .toString()
38
-                        .replaceAll("[\\[\\]]", "")
39
-            : "N/A";
35
+        return phoneBook.containsKey(name) ? format(phoneBook.get(name)): "N/A";
36
+    }
37
+    
38
+    public String format(ArrayList<String> numbers) {
39
+        return numbers.toString().replaceAll("[\\[\\]]", "");
40 40
     }
41 41
     
42 42
     public String reverseLookup(String phoneNumber) {

+ 15
- 14
PhoneBookTest.java View File

@@ -1,5 +1,4 @@
1 1
 
2
-
3 2
 import static org.junit.Assert.*;
4 3
 import org.junit.After;
5 4
 import org.junit.Before;
@@ -46,6 +45,19 @@ public class PhoneBookTest
46 45
     }
47 46
     
48 47
     @Test
48
+    public void testReverseLookup()
49
+    {
50
+       PhoneBook test = new PhoneBook();
51
+       String phoneNumber = "(302)-867-5309";
52
+       String expectedName = "Jenny";
53
+       test.add(expectedName, phoneNumber);
54
+       
55
+       String actual = test.reverseLookup(phoneNumber);
56
+       assertEquals(expectedName, actual);
57
+     
58
+    } 
59
+    
60
+    @Test
49 61
     public void testRemoveIndividualNumber() {
50 62
        PhoneBook test = new PhoneBook();
51 63
        String name = "Jenny";
@@ -54,26 +66,15 @@ public class PhoneBookTest
54 66
        test.add(name, number);
55 67
        test.add(name, number2);
56 68
        test.remove(number);
69
+       
57 70
        String actual = test.reverseLookup(number);
58 71
        assertEquals("N/A", actual);
59 72
     }
60 73
     
61 74
     @Test
62
-    public void testReverseLookup()
75
+    public void testDisplay() 
63 76
     {
64 77
        PhoneBook test = new PhoneBook();
65
-       String phoneNumber = "(302)-867-5309";
66
-       String expectedName = "Jenny";
67
-       test.add(expectedName, phoneNumber);
68
-       
69
-       String actual = test.reverseLookup(phoneNumber);
70
-       assertEquals(expectedName, actual);
71
-     
72
-    } 
73
-    
74
-    @Test
75
-    public void testDisplay() {
76
-       PhoneBook test = new PhoneBook();
77 78
        test.add("hey", "302");
78 79
        test.add("yo", "521");
79 80
        test.add("hey", "498");