go-by-test/wallet/wallet_test.go

25 lines
515 B
Go

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)
}
}
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))
})
}