1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
-
- import static 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
- {
- PhoneBook phoneBook;
-
- @Before
- public void setUp()
- {
- phoneBook = new PhoneBook();
- }
-
- @Test
- public void addTest(){
- phoneBook.add("Zebra", "111-222-333");
- phoneBook.add("Dog", "222-444-4444");
- int expected = 2;
- int actual = phoneBook.size();
- assertEquals(expected, actual);
- }
-
- @Test
- public void addToMapTest(){
- ArrayList<String> numbers = new ArrayList<>();
- numbers.add("111-222-333");
- numbers.add("222-444-4444");
- phoneBook.add("Zebra", numbers);
- //phoneBook.add("Dog", "222-444-4444");
- int expected = 1;
- int actual = phoneBook.size();
- assertEquals(expected, actual);
- }
-
- @Test
- public void removeTest(){
- ArrayList<String> numbers1 = new ArrayList<>();
- ArrayList<String> numbers2 = new ArrayList<>();
- numbers1.add("111-222-333");
- numbers1.add("222-444-4444");
- numbers2.add("444-222-332");
- numbers2.add("555-444-6666");
- phoneBook.add("Roy", numbers1);
- phoneBook.add("Josh", numbers2);
- int expected = 1;
- phoneBook.remove("Josh");
- int actual = phoneBook.size();
- assertEquals(expected, actual);
- }
-
- @Test
- public void lookUpTest(){
- ArrayList<String> numbers1 = new ArrayList<>();
- ArrayList<String> numbers2 = new ArrayList<>();
- numbers1.add("111-222-333");
- numbers1.add("222-444-4444");
- numbers2.add("444-222-332");
- numbers2.add("555-444-6666");
- phoneBook.add("Roy", numbers1);
- phoneBook.add("Josh", numbers2);
-
- ArrayList<String> expected = numbers1;
- ArrayList<String> actual = phoneBook.lookUp("Roy");
- assertEquals(expected, actual);
- }
- @Test
- public void reverseLookUpTest(){
- ArrayList<String> numbers1 = new ArrayList<>();
- ArrayList<String> numbers2 = new ArrayList<>();
- numbers1.add("111-222-333");
- numbers1.add("222-444-4444");
- numbers2.add("444-222-332");
- numbers2.add("555-444-6666");
- phoneBook.add("Roy", numbers1);
- phoneBook.add("Josh", numbers2);
-
- String expected = "Roy";
- String actual = phoneBook.reverseLookUp(numbers1);
- assertEquals(expected, actual);
- }
- }
|