|
@@ -14,7 +14,7 @@ public class PhoneBookTest {
|
14
|
14
|
String name = "Kay";
|
15
|
15
|
String number = "1234567890";
|
16
|
16
|
phTest.add(name, number);
|
17
|
|
- Assert.assertTrue(phTest.lookup(name).equals(number));
|
|
17
|
+ Assert.assertTrue(phTest.lookup(name).contains(number));
|
18
|
18
|
}
|
19
|
19
|
|
20
|
20
|
@Test
|
|
@@ -33,19 +33,20 @@ public class PhoneBookTest {
|
33
|
33
|
String number = "3456784523";
|
34
|
34
|
//adding a test value key pair to test for removal
|
35
|
35
|
phTest.add(name, number);
|
36
|
|
- Assert.assertTrue(phTest.lookup(name).equals(number));
|
|
36
|
+ Assert.assertTrue(phTest.lookup(name).contains(number));
|
37
|
37
|
//after confirmation that it has been added, it needs to be removed
|
38
|
38
|
phTest.remove(name);
|
39
|
39
|
Assert.assertTrue(phTest.lookup(name) == null);
|
40
|
40
|
|
41
|
41
|
}
|
|
42
|
+
|
42
|
43
|
@Test
|
43
|
44
|
public void lookupTest() {
|
44
|
45
|
PhoneBook phTest = new PhoneBook();
|
45
|
46
|
String name = "John";
|
46
|
47
|
String number = "8765930";
|
47
|
48
|
phTest.add(name, number);
|
48
|
|
- Assert.assertTrue(phTest.lookup(name).equals(number));
|
|
49
|
+ Assert.assertTrue(phTest.lookup(name).contains(number));
|
49
|
50
|
}
|
50
|
51
|
|
51
|
52
|
|
|
@@ -81,37 +82,63 @@ public class PhoneBookTest {
|
81
|
82
|
}
|
82
|
83
|
|
83
|
84
|
@Test
|
84
|
|
- public void listRecordsTest(){
|
|
85
|
+ public void listRecordsTest() {
|
85
|
86
|
PhoneBook phTest = new PhoneBook();
|
86
|
87
|
//added two new entries to test
|
87
|
|
- phTest.add("Nico","487542");
|
88
|
|
- phTest.add("Laura","1-800-no-sugar");
|
|
88
|
+ phTest.add("Dumbo", "487542");
|
|
89
|
+ phTest.add("Blumbo", "1800234583");
|
89
|
90
|
|
90
|
91
|
//turned into an array to iterate through.
|
91
|
92
|
Object[] array = phTest.listRecords().toArray();
|
92
|
93
|
//to.Array returns Object[] array
|
93
|
94
|
for (int i = 0; i < array.length; i++) {
|
94
|
95
|
//Object that was in array was Map.Entry: a record on map (key value pair)
|
95
|
|
- Map.Entry record = (Map.Entry) array[i];
|
|
96
|
+ Map.Entry<String, List<String>> record = (Map.Entry) array[i];
|
96
|
97
|
//0 index = Laura because treemap is sorted alphabetically
|
97
|
|
- if (i == 0 ){
|
98
|
|
- Assert.assertTrue(record.getKey().equals("Laura"));
|
99
|
|
- Assert.assertTrue(record.getValue().equals("1-800-no-sugar"));
|
100
|
|
- }else{
|
101
|
|
- Assert.assertTrue(record.getKey().equals("Nico"));
|
102
|
|
- Assert.assertTrue(record.getValue().equals("487542"));
|
103
|
|
- }
|
|
98
|
+ if (i == 0) {
|
|
99
|
+ Assert.assertTrue(record.getKey().equals("Blumbo"));
|
|
100
|
+ Assert.assertTrue(record.getValue().contains("1800234583"));
|
|
101
|
+ } else {
|
|
102
|
+ Assert.assertTrue(record.getKey().equals("Dumbo"));
|
|
103
|
+ Assert.assertTrue(record.getValue().contains("487542"));
|
|
104
|
+ }
|
|
105
|
+ }
|
|
106
|
+ }
|
|
107
|
+
|
|
108
|
+ @Test
|
|
109
|
+ public void reverselookupTest() {
|
|
110
|
+ PhoneBook phTest = new PhoneBook();
|
|
111
|
+ String expectedName = "Blumbo";
|
|
112
|
+ String expectedNumber = "1234567";
|
|
113
|
+ phTest.add(expectedName, expectedNumber);
|
|
114
|
+ //adding entry to test return
|
|
115
|
+ String actual = phTest.reverseLookup(expectedNumber);
|
|
116
|
+ Assert.assertEquals(expectedName, actual);
|
|
117
|
+
|
|
118
|
+ }
|
104
|
119
|
|
|
120
|
+ @Test
|
|
121
|
+ public void addTwoNumbersTest() {
|
|
122
|
+ ArrayList<String> phoneNumbers = new ArrayList<String>();
|
|
123
|
+ phoneNumbers.add("1111");
|
|
124
|
+ phoneNumbers.add("2222");
|
|
125
|
+
|
|
126
|
+ PhoneBook phTest = new PhoneBook();
|
|
127
|
+ String expectedName = "Blumbo";
|
|
128
|
+ phTest.add(expectedName, phoneNumbers.get(0));
|
|
129
|
+ phTest.add(expectedName, phoneNumbers.get(1));
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+ //adding entry to test return
|
|
134
|
+ List<String> actual = phTest.lookup(expectedName);
|
|
135
|
+
|
|
136
|
+ for(String phoneNumber : phoneNumbers) {
|
|
137
|
+ Assert.assertTrue(actual.contains(phoneNumber));
|
105
|
138
|
}
|
106
|
139
|
|
|
140
|
+
|
107
|
141
|
}
|
108
|
142
|
|
109
|
|
- // @Test
|
110
|
|
-// public void reverselookupTest() {
|
111
|
|
-// String name = "Bob";
|
112
|
|
-// String number = "8765930";
|
113
|
|
-// phTest.add(name, number);
|
114
|
|
-// Assert.assertTrue(phTest.lookup(number).equals(name));
|
115
|
|
-// }
|
116
|
143
|
|
117
|
144
|
}
|