123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
-
-
- import org.junit.Assert;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
- import java.util.ArrayList;
- /**
- * The test class PhoneBookTest.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class PhoneBookTest
- {
- @Test
- public void addTest() {
- String expected = "(555)-555-5555";
-
- PhoneBook pb = new PhoneBook();
- pb.add("Jane Doe", "(555)-555-5555");
- String actual = pb.lookup("Jane Doe");
-
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void addTest2() {
- String expected = "(555)-555-5555, (444)-444-4444, (333)-333-3333";
-
- PhoneBook pb = new PhoneBook();
- ArrayList<String> phoneNumbers = new ArrayList<String>();
- phoneNumbers.add("(555)-555-5555");
- phoneNumbers.add("(444)-444-4444");
- phoneNumbers.add("(333)-333-3333");
- pb.add("Sloths McSlotherson", phoneNumbers);
- String actual = pb.lookup("Sloths McSlotherson");
-
- Assert.assertEquals(expected, actual);
- }
- public void addTest3() {
- String expected = "(555)-555-5555, (444)-444-4444, (333)-333-3333";
-
- PhoneBook pb = new PhoneBook();
- ArrayList<String> phoneNumbers = new ArrayList<String>();
- phoneNumbers.add("(555)-555-5555");
- phoneNumbers.add("(444)-444-4444");
- pb.add("Turtle Turtleton", phoneNumbers);
- pb.add("Trutle Turtleton", "(333)-333-3333");
- String actual = pb.lookup("Turtle Turtleton");
-
- Assert.assertEquals(expected, actual);
-
- }
- @Test
- public void removeTest() {
- String expected = "Not Found";
-
- PhoneBook pb = new PhoneBook();
- pb.add("Kylo Ren", "(555)-867-5309");
- pb.remove("Kylo Ren");
- String actual = pb.lookup("Kylo Ren");
-
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void removeTestIndividualNumber() {
- String expected = "(555)-867-5309, (789)-789-6789";
-
- PhoneBook pb = new PhoneBook();
- pb.add("Kylo Ren", "(555)-867-5309");
- pb.add("Kylo Ren", "(888)-888-8888");
- pb.add("Kylo Ren", "(789)-789-6789");
- pb.remove("Kylo Ren", 1);
- String actual = pb.lookup("Kylo Ren");
-
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void lookupTest() {
- String expected = "(GIL)-EAD-SUXX";
-
- PhoneBook pb = new PhoneBook();
- pb.add("Kylo Ren", "(555)-867-5309");
- pb.add("June Osborne", "(GIL)-EAD-SUXX");
- pb.add("Serena Joy", "(555)-555-5555");
- String actual = pb.lookup("June Osborne");
-
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void reverseLookupTest() {
- String expected = "Serena Joy";
-
- PhoneBook pb = new PhoneBook();
- pb.add("Kylo Ren", "(555)-867-5309");
- pb.add("June Osborne", "(GIL)-EAD-SUXX");
- pb.add("Serena Joy", "(555)-555-5555");
- String actual = pb.reverseLookup("(555)-555-5555");
-
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void reverseLookupTest2() {
- String expected = "Serena Joy";
-
- PhoneBook pb = new PhoneBook();
- pb.add("Kylo Ren", "(555)-867-5309");
- pb.add("Kylo Ren", "(345)-123-6789");
- pb.add("June Osborne", "(GIL)-EAD-SUXX");
- pb.add("Serena Joy", "(555)-555-5555");
- pb.add("Serena Joy", "(321)-543-8765");
- pb.add("Serena Joy", "(893)-789-0123");
- String actual = pb.reverseLookup("(321)-543-8765");
-
- Assert.assertEquals(expected, actual);
- }
- }
|