Skip to content

Test-Driving The Wallet Class

Depends on Wallet/WalletTest

This lab requires the Wallet and WalletTest classes that we worked on, so you can pull the latest code from the repository and start from there, or you can copy the Wallet.java and WalletTest.java files from the source code repository and add them to your project.

Goal

Add a bet method to the Wallet class using test-driven development.

TDD Steps

Follow the Predictive TDD steps as described in this presentation, starting at slide #8.

Behavior

Add a method bet that takes an int as the bet amount, e.g., the method should look like:

public void bet(int amount)

Test-drive these behaviors

  1. Ensure that betting an amount reduces the balance correctly by validating against balance()

  2. Ensure that placing multiple bets reduces the balance correctly

  3. Ensure that betting the full balance of the wallet causes isEmpty() to continue to work correctly

  4. What should happen if you bet too much money (more than the balance)? Implement this if you have time.