|
@@ -1,7 +1,79 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
2
|
2
|
|
|
3
|
+import org.junit.Assert;
|
|
4
|
+import org.junit.Before;
|
|
5
|
+import org.junit.Test;
|
|
6
|
+
|
3
|
7
|
/**
|
4
|
8
|
* Created by leon on 1/23/18.
|
|
9
|
+ * https://git.zipcode.rocks/Cohort4.2/CR-MicroLabs-Composition-PhoneBook
|
5
|
10
|
*/
|
6
|
11
|
public class PhoneBookTest {
|
|
12
|
+ String testName;
|
|
13
|
+ String testNumber;
|
|
14
|
+
|
|
15
|
+ @Before
|
|
16
|
+ public void setup() {
|
|
17
|
+ testName = "Test Testmond";
|
|
18
|
+ testNumber = "302-299-6553";
|
|
19
|
+ }
|
|
20
|
+
|
|
21
|
+ @Test
|
|
22
|
+ public void addTest() {
|
|
23
|
+// adds an entry to the composite associate data type
|
|
24
|
+ PhoneBook app = new PhoneBook();
|
|
25
|
+
|
|
26
|
+ double before = app.getEntryCount();
|
|
27
|
+
|
|
28
|
+ app.add(testName, testNumber);
|
|
29
|
+
|
|
30
|
+ double after = app.getEntryCount();
|
|
31
|
+
|
|
32
|
+ Assert.assertTrue((before + 1) == after);
|
|
33
|
+ }
|
|
34
|
+
|
|
35
|
+ @Test
|
|
36
|
+ public void hasEntryTest() {
|
|
37
|
+ PhoneBook app = new PhoneBook();
|
|
38
|
+
|
|
39
|
+ app.add(testName, testNumber);
|
|
40
|
+ Assert.assertTrue(app.hasEntry(testName));
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ @Test
|
|
44
|
+ public void lookupTest() {
|
|
45
|
+ PhoneBook app = new PhoneBook();
|
|
46
|
+
|
|
47
|
+ app.add(testName, testNumber);
|
|
48
|
+ Assert.assertTrue(app.lookup(testName).equals(testNumber));
|
|
49
|
+ }
|
|
50
|
+
|
|
51
|
+ @Test
|
|
52
|
+ public void removeTest() {
|
|
53
|
+ PhoneBook app = new PhoneBook();
|
|
54
|
+// removes an entry to the composite associate data type
|
|
55
|
+ app.add(testName, testNumber);
|
|
56
|
+ app.remove(testName);
|
|
57
|
+ Assert.assertFalse(app.hasEntry(testName));
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ @Test
|
|
61
|
+ public void reverseLookupTest() {
|
|
62
|
+ PhoneBook app = new PhoneBook();
|
|
63
|
+// returns a name for the respective input phoneNumber
|
|
64
|
+ app.add(testName, testNumber);
|
|
65
|
+ String entry = app.reverseLookup(testNumber);
|
|
66
|
+ Assert.assertTrue(entry.equals((testName)));
|
|
67
|
+ }
|
|
68
|
+
|
|
69
|
+ @Test
|
|
70
|
+ public void listNamesAndNumbersTest() {
|
|
71
|
+ PhoneBook app = new PhoneBook();
|
|
72
|
+
|
|
73
|
+// return a human-readable list of all entries (names and phone numbers) in alphabetical order.
|
|
74
|
+// Format should be [name] [phone number]
|
|
75
|
+
|
|
76
|
+// System.out.println()
|
|
77
|
+ }
|
|
78
|
+
|
7
|
79
|
}
|