wallet: use self defined type Bitcoin
This commit is contained in:
parent
8644bf547b
commit
71bc024fe2
@ -1,13 +1,15 @@
|
|||||||
package wallet
|
package wallet
|
||||||
|
|
||||||
|
type Bitcoin int
|
||||||
|
|
||||||
type Wallet struct {
|
type Wallet struct {
|
||||||
balance int
|
balance Bitcoin
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Wallet) Deposit(units int) {
|
func (w *Wallet) Deposit(amount Bitcoin) {
|
||||||
w.balance += units
|
w.balance += amount
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Wallet) Balance() int {
|
func (w *Wallet) Balance() Bitcoin {
|
||||||
return w.balance
|
return w.balance
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ func TestWallet(t *testing.T) {
|
|||||||
wallet.Deposit(10)
|
wallet.Deposit(10)
|
||||||
|
|
||||||
got := wallet.Balance()
|
got := wallet.Balance()
|
||||||
want := 10
|
want := Bitcoin(10)
|
||||||
|
|
||||||
if got != want {
|
if got != want {
|
||||||
t.Errorf("got %d want %d", got, want)
|
t.Errorf("got %d want %d", got, want)
|
||||||
|
Loading…
Reference in New Issue
Block a user