-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_wallet.py
39 lines (31 loc) · 1.03 KB
/
test_wallet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import pytest
from wallet import Wallet, InsufficientAmount
@pytest.fixture
def empty_wallet():
'''Returns a Wallet instance with a zero balance'''
return Wallet()
@pytest.fixture
def wallet():
'''Returns a Wallet instance with a balance of 20'''
return Wallet(20)
def test_default_initial_amount(empty_wallet):
assert empty_wallet.balance == 0
def test_setting_initial_amount(wallet):
assert wallet.balance == 20
def test_wallet_add_cash(wallet):
wallet.add_cash(80)
assert wallet.balance == 100
def test_wallet_spend_cash(wallet):
wallet.spend_cash(10)
assert wallet.balance == 10
def test_wallet_spend_cash_raises_exception_on_insufficient_amount(empty_wallet):
with pytest.raises(InsufficientAmount):
empty_wallet.spend_cash(100)
@pytest.mark.parametrize("earned,spent,expected", [
(30, 10, 20),
(20, 2, 18),
])
def test_transactions(empty_wallet, earned, spent, expected):
empty_wallet.add_cash(earned)
empty_wallet.spend_cash(spent)
assert empty_wallet.balance == expected