123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
-
- import org.junit.Assert;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
-
- import java.util.*;
-
- /**
- * The test class PhoneBookTest.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class PhoneBookTest
- {
-
- TreeMap<String, ArrayList<String>> phoneBook = new TreeMap<>();
- /**
- * Default constructor for test class PhoneBookTest
- */
- public PhoneBookTest()
- {
- }
-
- /**
- * Sets up the test fixture.
- *
- * Called before every test case method.
- */
- @Before
- public void setUp()
- {
- PhoneBook pb = new PhoneBook();
- }
-
- /**
- * Tears down the test fixture.
- *
- * Called after every test case method.
- */
- @After
- public void tearDown()
- {
-
- }
-
- // add entries
- @Test
- public void testAdd() {
- String expected = "Zebra 111-222-3333 222-444-5555\n";
-
- PhoneBook pb = new PhoneBook();
- pb.add("Zebra", "111-222-3333");
- pb.add("Zebra", "222-444-5555");
-
- String actual = pb.display();
-
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testRemove() {
- String expected = "Zebra 222-444-5555\n";
- PhoneBook pb = new PhoneBook(phoneBook);
-
- pb.add("Zebra", "111-222-3333");
- pb.add("Zebra", "222-444-5555");
- pb.remove("Zebra", "111-222-3333");
-
- String actual = pb.display();
-
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testRemoveRecord() {
- String expected = "Zebra 222-444-5555\n";
- PhoneBook pb = new PhoneBook(phoneBook);
-
- pb.add("Dog", "111-222-3333");
- pb.add("Dog", "333-444-5555");
- pb.add("Zebra", "222-444-5555");
- pb.removeRecord("Dog");
-
- String actual = pb.display();
-
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testLookup() {
-
- ArrayList<String> expected = new ArrayList<>();
- expected.add("111-222-3333");
- expected.add("222-444-5555");
- PhoneBook pb = new PhoneBook(phoneBook);
-
- pb.add("Zebra", "111-222-3333");
- pb.add("Zebra", "222-444-5555");
-
- ArrayList<String> actual = pb.lookup("Zebra");
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testReverseLookup() {
-
- String expected = "Zebra";
- PhoneBook pb = new PhoneBook(phoneBook);
-
- pb.add("Zebra", "111-222-3333");
- pb.add("Zebra", "222-444-5555");
-
- String actual = pb.reverseLookup("222-444-5555");
- Assert.assertEquals(expected, actual);
- }
- }
|