|
@@ -1,7 +1,144 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
|
2
|
+import org.junit.Assert;
|
|
3
|
+import org.junit.Test;
|
|
4
|
+import java.util.*;
|
2
|
5
|
|
3
|
6
|
/**
|
4
|
|
- * Created by leon on 1/23/18.
|
|
7
|
+ * Created by Kay.
|
5
|
8
|
*/
|
6
|
9
|
public class PhoneBookTest {
|
7
|
|
-}
|
|
10
|
+//instantiating new object for each test so that they are not reliant on each other. unique...
|
|
11
|
+ @Test
|
|
12
|
+ public void addTest() {
|
|
13
|
+ PhoneBook phTest = new PhoneBook();
|
|
14
|
+ String name = "Kay";
|
|
15
|
+ String number = "1234567890";
|
|
16
|
+ phTest.add(name, number);
|
|
17
|
+ Assert.assertTrue(phTest.lookup(name).contains(number));
|
|
18
|
+ }
|
|
19
|
+
|
|
20
|
+ @Test
|
|
21
|
+ public void addFailTest() {
|
|
22
|
+ PhoneBook phTest = new PhoneBook();
|
|
23
|
+ String name = "Kay";
|
|
24
|
+ String number = "1234567890";
|
|
25
|
+ phTest.add(name, number);
|
|
26
|
+ Assert.assertTrue(phTest.lookup("Pony") == null);
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+ @Test
|
|
30
|
+ public void removeTest() {
|
|
31
|
+ PhoneBook phTest = new PhoneBook();
|
|
32
|
+ String name = "Bob";
|
|
33
|
+ String number = "3456784523";
|
|
34
|
+ //adding a test value key pair to test for removal
|
|
35
|
+ phTest.add(name, number);
|
|
36
|
+ Assert.assertTrue(phTest.lookup(name).contains(number));
|
|
37
|
+ //after confirmation that it has been added, it needs to be removed
|
|
38
|
+ phTest.remove(name);
|
|
39
|
+ Assert.assertTrue(phTest.lookup(name) == null);
|
|
40
|
+
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ @Test
|
|
44
|
+ public void lookupTest() {
|
|
45
|
+ PhoneBook phTest = new PhoneBook();
|
|
46
|
+ String name = "John";
|
|
47
|
+ String number = "8765930";
|
|
48
|
+ phTest.add(name, number);
|
|
49
|
+ Assert.assertTrue(phTest.lookup(name).contains(number));
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+ @Test
|
|
54
|
+ public void listNameTest() {
|
|
55
|
+ PhoneBook phTest = new PhoneBook();
|
|
56
|
+ phTest.add("Joe", "12334");
|
|
57
|
+ phTest.add("Kay", "45873423");
|
|
58
|
+ phTest.add("Elisha", "234234");
|
|
59
|
+ phTest.add("Nico", "24234");
|
|
60
|
+
|
|
61
|
+ //Set is used because it is a method of tree map HAD TO IMPORT
|
|
62
|
+ Set<String> names = phTest.listNames();
|
|
63
|
+ Assert.assertTrue(names.size() == 4);
|
|
64
|
+ Assert.assertTrue(names.contains("Joe"));
|
|
65
|
+ Assert.assertTrue(names.contains("Kay"));
|
|
66
|
+ Assert.assertTrue(names.contains("Elisha"));
|
|
67
|
+ Assert.assertTrue(names.contains("Nico"));
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ @Test
|
|
71
|
+ public void listNamesFailTest() {
|
|
72
|
+ PhoneBook phTest = new PhoneBook();
|
|
73
|
+ phTest.add("Cat", "12334");
|
|
74
|
+ phTest.add("Dog", "45873423");
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+ //Set is used because it is a method of tree map HAD TO IMPORT
|
|
78
|
+ Set<String> names = phTest.listNames();
|
|
79
|
+ Assert.assertTrue(names.size() == 2);
|
|
80
|
+ Assert.assertFalse(names.contains("Joe"));
|
|
81
|
+ Assert.assertFalse(names.contains("Kay"));
|
|
82
|
+ }
|
|
83
|
+
|
|
84
|
+ @Test
|
|
85
|
+ public void listRecordsTest() {
|
|
86
|
+ PhoneBook phTest = new PhoneBook();
|
|
87
|
+ //added two new entries to test
|
|
88
|
+ phTest.add("Dumbo", "487542");
|
|
89
|
+ phTest.add("Blumbo", "1800234583");
|
|
90
|
+
|
|
91
|
+ //turned into an array to iterate through.
|
|
92
|
+ Object[] array = phTest.listRecords().toArray();
|
|
93
|
+ //to.Array returns Object[] array
|
|
94
|
+ for (int i = 0; i < array.length; i++) {
|
|
95
|
+ //Object that was in array was Map.Entry: a record on map (key value pair)
|
|
96
|
+ Map.Entry<String, List<String>> record = (Map.Entry) array[i];
|
|
97
|
+ //0 index = Laura because treemap is sorted alphabetically
|
|
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
|
+ }
|
|
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));
|
|
138
|
+ }
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+ }
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+ }
|