|
@@ -1,42 +1,55 @@
|
1
|
|
-
|
2
|
|
-
|
|
1
|
+import java.util.*;
|
3
|
2
|
import static org.junit.Assert.*;
|
4
|
|
-import org.junit.After;
|
5
|
|
-import org.junit.Before;
|
6
|
3
|
import org.junit.Test;
|
7
|
4
|
|
8
|
|
-/**
|
9
|
|
- * The test class PhoneBookTest.
|
10
|
|
- *
|
11
|
|
- * @author (your name)
|
12
|
|
- * @version (a version number or a date)
|
13
|
|
- */
|
14
|
|
-public class PhoneBookTest
|
|
5
|
+
|
|
6
|
+public class PhoneBookTest
|
15
|
7
|
{
|
16
|
|
- /**
|
17
|
|
- * Default constructor for test class PhoneBookTest
|
18
|
|
- */
|
19
|
|
- public PhoneBookTest()
|
20
|
|
- {
|
|
8
|
+ @Test
|
|
9
|
+ public void addTest(){
|
|
10
|
+ PhoneBook phoneBook = new PhoneBook();
|
|
11
|
+ phoneBook.add("vince","333-333-3333");
|
|
12
|
+ int actual = phoneBook.size();
|
|
13
|
+ int expected = 1;
|
|
14
|
+ assertEquals(actual,expected);
|
21
|
15
|
}
|
22
|
16
|
|
23
|
|
- /**
|
24
|
|
- * Sets up the test fixture.
|
25
|
|
- *
|
26
|
|
- * Called before every test case method.
|
27
|
|
- */
|
28
|
|
- @Before
|
29
|
|
- public void setUp()
|
30
|
|
- {
|
|
17
|
+ @Test
|
|
18
|
+ public void removeTest(){
|
|
19
|
+ PhoneBook phoneBook = new PhoneBook();
|
|
20
|
+ phoneBook.add("vince","333-333-3333");
|
|
21
|
+ phoneBook.remove("vince");
|
|
22
|
+ int actual = phoneBook.size();
|
|
23
|
+ int expected = 0;
|
|
24
|
+ assertEquals(actual,expected);
|
31
|
25
|
}
|
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
|
+
|
|
27
|
+ @Test
|
|
28
|
+ public void lookupTest(){
|
|
29
|
+ PhoneBook phoneBook = new PhoneBook();
|
|
30
|
+ phoneBook.add("vince","333-333-3333");
|
|
31
|
+ String actual = phoneBook.lookup("vince");
|
|
32
|
+ String expected = "333-333-3333";
|
|
33
|
+ assertEquals(actual,expected);
|
|
34
|
+ }
|
|
35
|
+ @Test
|
|
36
|
+ public void lookupReverseTest(){
|
|
37
|
+ PhoneBook phoneBook = new PhoneBook();
|
|
38
|
+ phoneBook.add("vince","333-333-3333");
|
|
39
|
+ String actual = phoneBook.reverseLookup("333-333-3333");
|
|
40
|
+ String expected = "vince";
|
|
41
|
+ assertEquals(actual,expected);
|
|
42
|
+ }
|
|
43
|
+
|
|
44
|
+ @Test
|
|
45
|
+ public void displayTest(){
|
|
46
|
+ PhoneBook phoneBook = new PhoneBook();
|
|
47
|
+ phoneBook.add("vince","333-333-3333");
|
|
48
|
+ phoneBook.add("bill","444-444-4444");
|
|
49
|
+ phoneBook.add("john","555-555-5555");
|
|
50
|
+ String actual = phoneBook.display();
|
|
51
|
+ String expected = "bill : 444-444-4444\njohn : 555-555-5555\nvince : 333-333-3333\n";
|
|
52
|
+ assertEquals(actual,expected);
|
41
|
53
|
}
|
|
54
|
+
|
42
|
55
|
}
|