BankAccount TestDriver
/**
* Test driver for class BankAccount
*
* @author Darren Siegel
* @version 1.0.0
*/
public class TestDriver {
/**
* Main routine that includes the testing code.
*
* @param args String command line arguments
*/
public static void main(String args[]) {
// Test that the constructor initializes the balance to zero.
BankAccount b = new BankAccount();
if (b.balance() != 0) {
System.out.println("Constructor Test Failed");
} else {
System.out.println("Constructor Test Passed");
}
// Test the deposit function.
b.deposit(0);
if (b.balance() != 0) {
System.out.println("Deposit Test 1 Failed");
} else {
System.out.println("Deposit Test 1 Passed");
}
b.deposit(10.25);
if (b.balance() != 10.25) {
System.out.println("Deposit Test 2 Failed");
} else {
System.out.println("Deposit Test 2 Passed");
}
b.deposit(1000000);
if (b.balance() != 1000010.25) {
System.out.println("Deposit Test 3 Failed");
} else {
System.out.println("Deposit Test 3 Passed");
}
// Test the withdraw function.
b.withdraw(0);
if (b.balance() != 1000010.25) {
System.out.println("Withdrawl Test 1 Failed");
} else {
System.out.println("Withdrawl Test 1 Passed");
}
b.withdraw(1000009.25);
if (b.balance() != 1) {
System.out.println("Withdrawl Test 2 Failed");
} else {
System.out.println("Withdrawl Test 2 Passed");
}
b.withdraw(100);
if (b.balance() != -99) {
System.out.println("Withdrawl Test 3 Failed");
} else {
System.out.println("Withdrawl Test 3 Passed");
}
}
}