go-by-test/wallet/wallet_test.go

25 lines
515 B
Go
Raw Normal View History

package wallet
import "testing"
func TestWallet(t *testing.T) {
2024-09-11 09:22:04 +00:00
assertBalance := func(t testing.TB, wallet Wallet, want Bitcoin) {
t.Helper()
2024-09-11 09:22:04 +00:00
got := wallet.Balance()
if got != want {
t.Errorf("got %q want %q", got, want)
}
}
2024-09-11 09:22:04 +00:00
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))
})
}