/**
* Very simple test of BetterPhoneBook.
* Definitely not complete
*/
public class TestBetterPhoneBook
{
public static void runTest() {
BetterPhoneBook book = new BetterPhoneBook();
book.addNumber("Phil", "Cell", "123-45-6789");
book.addNumber("Phil", "Home", "987-65-4321");
book.addNumber("Jenny", "Home", "867-5309");
book.addNumber("John", "Office", "67");
book.addNumber("Phil", "Office", "616-123-1234");
System.out.println("Running tests");
// Test add
if(book.phonebookSize()!=3) {
System.out.println("There should be 3 numbers listed in the phone book, but there are "
+ book.phonebookSize());
}
System.out.println("------------------");
// Test print number of numbers
System.out.println("It should like 3 for Phil, and 1 for each of Jenny and John, "
+"in some unspecified order.");
book.printNumberOfNumbers();
System.out.println("------------------");
// Test print number of numbers V2
System.out.println("It should like 3 for Phil, and 1 for each of Jenny and John, "
+"in some unspecified order.");
book.printNumberOfNumbersV2();
System.out.println("------------------");
// Test case: Typical (name is in map, and type is in their map)
String number = book.getNumber("Phil", "Home");
if(number==null) {
System.out.println("Phil's Home phone should be 987-65-4321, but null was returned");
} else if(!number.equals("987-65-4321")) {
System.out.println("Phil's Home phone should be 987-65-4321, but is listed as "
+number);
}
// Test case: Name exists in map, type does not.
number = book.getNumber("Phil","Disco");
if(number!=null) {
System.out.println("Phil's should not have a Disco number, but it is listed as "
+number);
}
// Test Case: Name does not exist in map
number = book.getNumber("Angela", "Any");
if(number!=null) {
System.out.println("Angela should not have any numbers, but her Any is listed as "
+number);
}
// Test printing. Should print 3 number for phil and one for Jenny
System.out.println("Should print 3 number for phil and one for Jenny:");
book.printNumbers("Phil");
book.printNumbers("Jenny");
}
}