org.jwalk.test
Class Wallet

java.lang.Object
  extended by org.jwalk.test.Wallet

public class Wallet
extends java.lang.Object

Wallet is a simple purse accepting and disbursing money payments. This is a standard test class, provided with the JWalk tool suite. The Wallet stores an integer balance and accepts requests to pay in, or pay out, sums of money. Only positive integer amounts are permitted. The Wallet may reject a request to pay out more than the balance contained.

This test class can be used to demonstrate the ability of an AlgebraWalker to discover the algebraic structure of a Wallet data type, in less than ideal conditions. This is because the transformer payOut() only modifies the object for some invocations (if the amount can actually be paid) and otherwise masquerades as an observer, returning a boolean result. Similarly, the primitive payIn() method masquerades as a transformer, when the resulting balance has been seen before (as a result of a debit in the prefix).

This test class can also be used to demonstrate the ability of a StateSpaceWalker to discover the high-level state space of a Wallet data type, in less than ideal conditions. This is because the state space does not use the full boolean product of predicate outcomes, and the predicates are not mutually independent. Wallet therefore has no Default state, and no state when both predicates are true simultaneously.

Version:
1.0
Author:
Arne-Michael Toersel

Constructor Summary
Wallet()
          Creates a new Wallet with a balance of zero.
 
Method Summary
 boolean inCredit()
          Reports whether this Wallet has some money left.
 boolean isEmpty()
          Reports whether this Wallet has no money left.
 int money()
          Returns the balance of the money in the Wallet.
 void payIn(int amount)
          Pays in an amount of money.
 boolean payOut(int amount)
          Pays out an amount of money, if the Wallet can support this.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Wallet

public Wallet()
Creates a new Wallet with a balance of zero.

Method Detail

payIn

public void payIn(int amount)
Pays in an amount of money. The amount must be positive, otherwise an IllegalArgumentException is raised. The balance is credited with the amount.

Parameters:
amount - the amount to pay in.
Throws:
java.lang.IllegalArgumentException - if the amount is zero or negative.

payOut

public boolean payOut(int amount)
Pays out an amount of money, if the Wallet can support this. The amount must be positive, otherwise an IllegalArgumentException is raised. If the amount is less than, or equal to the balance, the balance is debited by this amount; otherwise the balance is left unchanged.

Parameters:
amount - the amount to pay out.
Returns:
true, if money was paid out, otherwise false.

money

public int money()
Returns the balance of the money in the Wallet.

Returns:
the money in the Wallet.

isEmpty

public boolean isEmpty()
Reports whether this Wallet has no money left.

Returns:
true if this Wallet is empty.

inCredit

public boolean inCredit()
Reports whether this Wallet has some money left.

Returns:
true if this Wallet contains some money.