wallet: add withdraw method
This commit is contained in:
parent
36ef78fb92
commit
8ed0235074
@ -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
|
||||
}
|
||||
|
@ -3,14 +3,22 @@ package wallet
|
||||
import "testing"
|
||||
|
||||
func TestWallet(t *testing.T) {
|
||||
wallet := Wallet{}
|
||||
|
||||
wallet.Deposit(10)
|
||||
assertBalance := func(t testing.TB, wallet Wallet, want Bitcoin) {
|
||||
t.Helper()
|
||||
|
||||
got := wallet.Balance()
|
||||
want := Bitcoin(10)
|
||||
|
||||
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))
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user