RAHUL goswami

RAHUL goswami

  • NA
  • 10
  • 8.5k

domain matrix for testing

Oct 10 2013 11:27 AM
How we can design the domain matrix for testing the withdraw method using the domain testing technique. please help if anyone know!

here is the example:

public class BankAccount{

   private double balance;
   private boolean closed;

   public BankAccount(){
      balance = 0;
      closed = false;
   }

   public double getBalance(){
       return balance;
   }

   // deposit requires the following condition
   // amount>=0 && !isClosed()
   public void deposit(double amount) {
 if (closed) {
System.out.println("Cannot deposit because the account is closed!");
  return;  // throwing an exception would be better
   }
      if (amount>=0) {
         balance = balance + amount;
   }
   }

   // withdraw requires the following condition
   // getBalance()>0 && amount>0 && getBalance() - amount>=0 && !isClosed()
   public void withdraw(double amount) {
// error!
//   if (closed) {
// System.out.println("Cannot withdraw because the account is closed!");
//   return;  // throwing an exception would be better
//   }
       if (balance>0 && amount>0 && balance-amount>=0) {
           balance = balance - amount;
      }
   }

   public void close() {
  if (balance>=0) {
           withdraw (balance);
      closed = true;
       }
   }

   public boolean isClosed() {
  return closed;
   }
}