123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
-
-
- 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, 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(phoneBook);
- }
-
- /**
- * Tears down the test fixture.
- *
- * Called after every test case method.
- */
- @After
- public void tearDown()
- {
-
- }
-
- // add entries
- @Test
- public void testOne() {
- String expected = "Dog 222-444-5555\nZebra 111-222-3333\n";
-
- PhoneBook pb = new PhoneBook(phoneBook);
- pb.add("Zebra", "111-222-3333");
- pb.add("Dog", "222-444-5555");
-
- String actual = pb.display();
-
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void testTwo() {
- String expected = "Dog 222-444-5555\n";
- PhoneBook pb = new PhoneBook(phoneBook);
-
- pb.add("Zebra", "111-222-3333");
- pb.add("Dog", "222-444-5555");
- pb.remove("Zebra");
-
- String actual = pb.display();
-
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void TestThree() {
- String expected = "222-444-5555";
- PhoneBook pb = new PhoneBook(phoneBook);
-
- pb.add("Zebra", "111-222-3333");
- pb.add("Dog", "222-444-5555");
-
- String actual = pb.lookup("Dog");
-
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void TestFour() {
- String expected = "Dog";
- PhoneBook pb = new PhoneBook(phoneBook);
-
- pb.add("Zebra", "111-222-3333");
- pb.add("Dog", "222-444-5555");
-
- String actual = pb.reverseLookup("222-444-5555");
- Assert.assertEquals(expected, actual);
- }
- }
|