Browse Source

work in progress

Mexi 6 years ago
parent
commit
775be79ec7
2 changed files with 34 additions and 5 deletions
  1. 6
    2
      PhoneBook.java
  2. 28
    3
      PhoneBookTest.java

+ 6
- 2
PhoneBook.java View File

@@ -9,14 +9,18 @@ public class PhoneBook {
9 9
     String phoneNumber= "";
10 10
     Map<String,String> phoneBook = new TreeMap<>();    
11 11
     public void addEntry(String name,String phoneNumber){
12
-        phoneBook.put(name, phoneNumber);
12
+        phoneBook.put(name, phoneNumber); //add a new number
13 13
     }    
14 14
     
15 15
     public void removeEntry(String name){
16
-        phoneBook.remove(name);
16
+        phoneBook.remove(name);//delete a number
17 17
     }
18 18
     
19 19
     public int size(){
20 20
     return phoneBook.size(); //return size of the phonebook
21 21
     }
22
+    
23
+    public String lookUp(String name){
24
+    return phoneBook.get(name);
25
+    } 
22 26
 }

+ 28
- 3
PhoneBookTest.java View File

@@ -1,5 +1,7 @@
1 1
 import org.junit.Assert;
2 2
 import org.junit.Test;
3
+import java.util.Map;
4
+import java.util.TreeMap;
3 5
 
4 6
 /**
5 7
  * The test class PhoneBookTest.
@@ -35,9 +37,32 @@ public class PhoneBookTest
35 37
     Assert.assertEquals(0, phoneBook.size());
36 38
     }
37 39
     
38
-    public String lookUp(){
39
-    return null;
40
-    } 
40
+  
41 41
     
42
+    @Test
43
+    public void lookUp(){
44
+    PhoneBook phoneBook = new PhoneBook();
45
+    String name = "Zebra";
46
+    String expected = "111-222-333";
47
+    phoneBook.addEntry(name,expected);
48
+    //when
49
+    String actual = phoneBook.lookUp(name);
50
+    //then
51
+    Assert.assertEquals(expected,actual);
52
+    }
42 53
     
54
+    @Test
55
+    public void reverseLoopUp(){
56
+    PhoneBook phoneBook = new PhoneBook();
57
+    String phoneNumber = "111-222-333";
58
+    String expected = "Zebra";
59
+    //when
60
+    // String actual = phoneBook.reverseLookUp(phoneNumber);
61
+    //then
62
+    // Assert.assertEquals(expected,actual);
63
+    }
64
+    
65
+    @Test
66
+    public void display(){
67
+    }
43 68
 }