Programming Resources
For Fun and Learning
Charles Cusack
Computer Science
Hope College
main

Python
C++

JAVA


PHP
SQL
Assignments

CSCI125Code


TestPhoneBookBetter.java

public class TestPhoneBookBetter
{
   PhoneBookBetter book;
   
    /**
     * Constructor for objects of class TestPhoneBook
     */
    public TestPhoneBookBetter()
    { 
        book = new PhoneBookBetter();
        book.addNumber("Jenny", "Office", "8675309");
        book.addNumber("Joe Smith", "Cell", "123456789");
        book.addNumber("Joe Smith", "Home", "123456781");
        book.addNumber("Jenny", "Home", "(919)-867-5309");
        book.addNumber("Joe Smith", "Office", "616-911-9111");
    } 
    
    public void runTest1() {
        System.out.println("Printing the phonebook:");
        book.printNumbers();
        System.out.println("-------------------------------------");
    }
    
    public void runTest2() { 
        System.out.println("If this is the only thing that prints then the tests all passed.");
        
        if(!book.getNumber("Jenny", "Office").equals("8675309")) {
            System.out.println("Jenny's number was not correctly added");
        }
        
        if(!book.getNumber("Joe Smith", "Cell").equals("123456789")) {
            System.out.println("John Smith's Cell number was not correctly added");
        }
        
        if(!book.getNumber("Joe Smith", "Home").equals("123456781")) {
            System.out.println("John Smith's Home number was not correctly added");
        }
        
        if(!book.getNumber("Joe Smith", "Office").equals("616-911-9111")) {
            System.out.println("John Smith's Office should be unlisted");
        }
        
        if(book.getNumber("Joe Smith", "Club")!=null) {
            System.out.println("John Smith's Club should be unlisted");
        }
        
        if(book.getNumber("Jenny", "Cell")!=null) {
            System.out.println("Jenny's Cell should be unlisted");
        }
        
        if(book.getNumber("Kyle", "Cell")!=null) {
            System.out.println("Kyle is not in the phone book but it appears he might be.");
        }
    }

}