Project 14 of 20, for Caitlin
Testing the Bank
Tests for Caitlin's festival fund accounts that pass on the real thing and fail on broken copies, then two new features written tests first.
Sign up free to open itLog in
Act 2 needs a free account, so your work is saved as you go. Act 1 is open to everyone.
The brief
- CaitlinThe festival fund has real money in it now, but Aaesha won't pay in until it's been tested.
- AaeshaMy requirements are, one, the accounts are right, and two, they stay right.
- AaeshaAnd three, if someone breaks them we find out by lunchtime, instead of the week of the festival.
- PaulThat's three requirements, and one of them is tests.
- AaeshaActually, all three are tests.
The festival fund's Account is in bank.py, the class you wrote for Caitlin. Write tests for it in test_bank.py: plain functions whose names start with test_, each checking one thing with assert. Your tests must pass on the real bank.py and fail on broken ones.
Then Aaesha's two new requirements, tests first:
transfer(other, pence)moves money from one account into another and returnsTrue. If there isn't enough, nothing moves and it returnsFalse. An amount that isn't more than 0 raises aValueError.add_interest(percent)pays in that much interest on the balance, rounded to the nearest penny, and returns it. Interest that rounds to nothing isn't paid in at all.
passed test_deposit passed test_withdraw passed test_withdraw_everything passed test_too_much passed test_str passed test_deposit_nothing passed test_transfer passed test_transfer_too_much passed test_transfer_everything passed test_transfer_nothing passed test_interest passed test_interest_rounds_to_the_penny passed test_no_interest_on_nothing
What you learn
What's in it
- Checking what you believe
- Checking what you believe
- Where the bugs live
- Exactly everything
- A test is a function
- Tests that can't fail
- How pytest does it
- Tests before code
- How Paul would do it
- Fix Caitlin's version
- Tests first
- Make the bank pass
- Ship it