Mexi 6 years ago
parent
commit
b60ce15e18
2 changed files with 47 additions and 31 deletions
  1. 17
    2
      PhoneBook.java
  2. 30
    29
      PhoneBookTest.java

+ 17
- 2
PhoneBook.java View File

1
- 
1
+import java.util.TreeMap; 
2
+import java.util.Map;
2
 
3
 
3
 /**
4
 /**
4
- * Created by leon on 1/23/18.
5
+ * Created by Mexi Liang on 06/11/18.
5
  */
6
  */
6
 public class PhoneBook {
7
 public class PhoneBook {
8
+    String name = "";
9
+    String phoneNumber= "";
10
+    Map<String,String> phoneBook = new TreeMap<>();    
11
+    public void addEntry(String name,String phoneNumber){
12
+        phoneBook.put(name, phoneNumber);
13
+    }    
14
+    
15
+    public void removeEntry(String name){
16
+        phoneBook.remove(name);
17
+    }
18
+    
19
+    public int size(){
20
+    return phoneBook.size(); //return size of the phonebook
21
+    }
7
 }
22
 }

+ 30
- 29
PhoneBookTest.java View File

1
-
2
-
3
-import static org.junit.Assert.*;
4
-import org.junit.After;
5
-import org.junit.Before;
1
+import org.junit.Assert;
6
 import org.junit.Test;
2
 import org.junit.Test;
7
 
3
 
8
 /**
4
 /**
13
  */
9
  */
14
 public class PhoneBookTest
10
 public class PhoneBookTest
15
 {
11
 {
16
-    /**
17
-     * Default constructor for test class PhoneBookTest
18
-     */
19
-    public PhoneBookTest()
20
-    {
12
+    @Test
13
+    public void addEntryTest(){
14
+    //Given
15
+    PhoneBook phoneBook = new PhoneBook();
16
+    String name = "Zebra";
17
+    String phoneNumber = "111-222-333";
18
+    String expected = "Zebra , 111-222-333";
19
+    //When
20
+    phoneBook.addEntry(name,phoneNumber);
21
+    
22
+    //Then
23
+    Assert.assertEquals(1,phoneBook.size());
24
+    
21
     }
25
     }
22
-
23
-    /**
24
-     * Sets up the test fixture.
25
-     *
26
-     * Called before every test case method.
27
-     */
28
-    @Before
29
-    public void setUp()
30
-    {
31
-    }
32
-
33
-    /**
34
-     * Tears down the test fixture.
35
-     *
36
-     * Called after every test case method.
37
-     */
38
-    @After
39
-    public void tearDown()
40
-    {
26
+    @Test
27
+    public void removeEntry(){
28
+    //Given
29
+    PhoneBook phoneBook = new PhoneBook();
30
+    String name = "Zebra";
31
+    String expected = "";
32
+    //when
33
+    phoneBook.removeEntry(name);
34
+    //Then
35
+    Assert.assertEquals(0, phoneBook.size());
41
     }
36
     }
37
+    
38
+    public String lookUp(){
39
+    return null;
40
+    } 
41
+    
42
+    
42
 }
43
 }