wallet: add withdraw method
This commit is contained in:
		@ -16,6 +16,10 @@ func (w *Wallet) Deposit(amount Bitcoin) {
 | 
				
			|||||||
	w.balance += amount
 | 
						w.balance += amount
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (w *Wallet) Withdraw(amount Bitcoin) {
 | 
				
			||||||
 | 
						w.balance -= amount
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (w *Wallet) Balance() Bitcoin {
 | 
					func (w *Wallet) Balance() Bitcoin {
 | 
				
			||||||
	return w.balance
 | 
						return w.balance
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -3,14 +3,22 @@ package wallet
 | 
				
			|||||||
import "testing"
 | 
					import "testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestWallet(t *testing.T) {
 | 
					func TestWallet(t *testing.T) {
 | 
				
			||||||
	wallet := Wallet{}
 | 
						assertBalance := func(t testing.TB, wallet Wallet, want Bitcoin) {
 | 
				
			||||||
 | 
							t.Helper()
 | 
				
			||||||
	wallet.Deposit(10)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		got := wallet.Balance()
 | 
							got := wallet.Balance()
 | 
				
			||||||
	want := Bitcoin(10)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if got != want {
 | 
							if got != want {
 | 
				
			||||||
			t.Errorf("got %q want %q", 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))
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user