|
@@ -1,4 +1,4 @@
|
1
|
|
-
|
|
1
|
+import java.util.TreeMap;
|
2
|
2
|
|
3
|
3
|
import static org.junit.Assert.*;
|
4
|
4
|
import org.junit.After;
|
|
@@ -13,30 +13,98 @@ import org.junit.Test;
|
13
|
13
|
*/
|
14
|
14
|
public class PhoneBookTest
|
15
|
15
|
{
|
16
|
|
- /**
|
17
|
|
- * Default constructor for test class PhoneBookTest
|
18
|
|
- */
|
19
|
|
- public PhoneBookTest()
|
20
|
|
- {
|
|
16
|
+
|
|
17
|
+ PhoneBook phoneBook =new PhoneBook();
|
|
18
|
+ private String name;
|
|
19
|
+ private String number;
|
|
20
|
+ @Test
|
|
21
|
+ public void testAddToPhoneBook1(){
|
|
22
|
+
|
|
23
|
+ phoneBook.addToPhoneBook("Zebra", "111-222-333");;
|
|
24
|
+
|
|
25
|
+ String expectedString = "[Zebra=[111-222-333]]";
|
|
26
|
+ String actualString = phoneBook.displayFromPhoneBook();
|
|
27
|
+
|
|
28
|
+ assertEquals(expectedString, actualString);
|
21
|
29
|
}
|
|
30
|
+
|
|
31
|
+ @Test
|
|
32
|
+ public void testAddToPhoneBookIndividualNumbers(){
|
22
|
33
|
|
23
|
|
- /**
|
24
|
|
- * Sets up the test fixture.
|
25
|
|
- *
|
26
|
|
- * Called before every test case method.
|
27
|
|
- */
|
28
|
|
- @Before
|
29
|
|
- public void setUp()
|
30
|
|
- {
|
|
34
|
+ phoneBook.addToPhoneBookIndividualNumbers("Zebra", "111-222-333");
|
|
35
|
+ phoneBook.addToPhoneBookIndividualNumbers("Zebra", "222-444-4444");
|
|
36
|
+
|
|
37
|
+ String expectedString = "[Zebra=[111-222-333, 222-444-4444]]";
|
|
38
|
+ String actualString = phoneBook.displayFromPhoneBook();
|
|
39
|
+
|
|
40
|
+ assertEquals(expectedString, actualString);
|
|
41
|
+
|
|
42
|
+
|
31
|
43
|
}
|
|
44
|
+
|
|
45
|
+ @Test
|
|
46
|
+ public void testRemoveFromPhoneBook1(){
|
|
47
|
+ PhoneBook phoneBook3 =new PhoneBook();
|
|
48
|
+ phoneBook3.addToPhoneBook("Zebra", "111-222-3333");
|
|
49
|
+ phoneBook3.addToPhoneBook("Dog", "222-444-4444");
|
|
50
|
+ phoneBook3.addToPhoneBook("Cat", "555-666-7777");
|
|
51
|
+ phoneBook3.addToPhoneBook("Alligator", "888-999-1010");
|
|
52
|
+ phoneBook3.addToPhoneBook("Wolf", "111-121-1313");
|
|
53
|
+ phoneBook3.removeFromPhoneBook("Dog");
|
32
|
54
|
|
33
|
|
- /**
|
34
|
|
- * Tears down the test fixture.
|
35
|
|
- *
|
36
|
|
- * Called after every test case method.
|
37
|
|
- */
|
38
|
|
- @After
|
39
|
|
- public void tearDown()
|
40
|
|
- {
|
|
55
|
+ String expectedString = "[Alligator=[888-999-1010], Cat=[555-666-7777], Wolf=[111-121-1313], Zebra=[111-222-3333]]";
|
|
56
|
+
|
|
57
|
+ String actualString = phoneBook3.displayFromPhoneBook();
|
|
58
|
+
|
|
59
|
+ assertEquals(expectedString, actualString);
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ @Test
|
|
65
|
+ public void testRemoveFromPhoneBookIndividualNumbers(){
|
|
66
|
+ phoneBook.addToPhoneBook("Zebra", "111-222-3333");
|
|
67
|
+ phoneBook.addToPhoneBookIndividualNumbers("Zebra", "222-444-4444");
|
|
68
|
+ phoneBook.removeFromPhoneBookIndividualNumbers("Zebra", "111-222-3333");
|
|
69
|
+
|
|
70
|
+ String expectedString = "[Zebra=[222-444-4444]]";
|
|
71
|
+ String actualString = phoneBook.displayFromPhoneBook();
|
|
72
|
+ assertEquals(expectedString, actualString);
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ @Test
|
|
76
|
+ public void testLookupFromPhoneBook(){
|
|
77
|
+ PhoneBook phoneBook4 =new PhoneBook();
|
|
78
|
+ phoneBook4.addToPhoneBook("Zebra", "111-222-3333");
|
|
79
|
+ phoneBook4.addToPhoneBook("Dog", "222-444-4444");
|
|
80
|
+ phoneBook4.addToPhoneBook("Cat", "555-666-7777");
|
|
81
|
+ phoneBook4.addToPhoneBook("Alligator", "888-999-1010");
|
|
82
|
+ phoneBook4.addToPhoneBook("Wolf", "111-121-1313");
|
|
83
|
+
|
|
84
|
+ String expectedString = "[555-666-7777]";
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+ String actualString = phoneBook4.lookupFromPhoneBook("Cat");
|
|
88
|
+
|
|
89
|
+ assertEquals(expectedString, actualString);
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ @Test
|
|
95
|
+ public void testReverseLookup(){
|
|
96
|
+ phoneBook.addToPhoneBook("Zebra", "111-222-3333");
|
|
97
|
+ phoneBook.addToPhoneBook("Dog", "222-444-4444");
|
|
98
|
+ phoneBook.addToPhoneBook("Cat", "555-666-7777");
|
|
99
|
+ phoneBook.addToPhoneBook("Alligator", "888-999-1010");
|
|
100
|
+ phoneBook.addToPhoneBook("Wolf", "111-121-1313");
|
|
101
|
+ String expectedString = "Wolf";
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+ String actualString = phoneBook.reverseLookupFromPhoneBook("111-121-1313");
|
|
105
|
+
|
|
106
|
+ assertEquals(expectedString, actualString);
|
|
107
|
+
|
|
108
|
+
|
41
|
109
|
}
|
42
|
110
|
}
|