package wallet import "testing" func TestWallet(t *testing.T) { assertBalance := func(t testing.TB, wallet Wallet, want Bitcoin) { t.Helper() got := wallet.Balance() if got != want { t.Errorf("got %q want %q", got, want) } } assertError := func(t testing.TB, err error) { t.Helper() if err == nil { t.Error("wanted an error but didn't get one") } } 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)) }) t.Run("withdraw insufficient funds", func(t *testing.T) { startingBalance := Bitcoin(20) wallet := Wallet{balance: startingBalance} err := wallet.Withdraw(100) assertError(t, err) assertBalance(t, wallet, startingBalance) }) }