diff --git a/wallet/wallet.go b/wallet/wallet.go index f2fb957..fca806e 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -16,6 +16,10 @@ func (w *Wallet) Deposit(amount Bitcoin) { w.balance += amount } +func (w *Wallet) Withdraw(amount Bitcoin) { + w.balance -= amount +} + func (w *Wallet) Balance() Bitcoin { return w.balance } diff --git a/wallet/wallet_test.go b/wallet/wallet_test.go index c575ec9..65e764c 100644 --- a/wallet/wallet_test.go +++ b/wallet/wallet_test.go @@ -3,14 +3,22 @@ package wallet import "testing" func TestWallet(t *testing.T) { - wallet := Wallet{} + assertBalance := func(t testing.TB, wallet Wallet, want Bitcoin) { + t.Helper() - wallet.Deposit(10) - - got := wallet.Balance() - want := Bitcoin(10) - - if got != want { - t.Errorf("got %q want %q", got, want) + got := wallet.Balance() + if got != want { + t.Errorf("got %q want %q", got, want) + } } + t.Run("deposit", func(t *testing.T) { + wallet := Wallet{} + wallet.Deposit(10) + assertBalance(t, wallet, Bitcoin(10)) + }) + t.Run("withdraw", func(t *testing.T) { + wallet := Wallet{balance: Bitcoin(20)} + wallet.Withdraw(10) + assertBalance(t, wallet, Bitcoin(10)) + }) }