wallet: use self defined type Bitcoin

This commit is contained in:
vinchent 2024-09-11 11:15:24 +02:00
parent 8644bf547b
commit 71bc024fe2
2 changed files with 7 additions and 5 deletions

View File

@ -1,13 +1,15 @@
package wallet
type Bitcoin int
type Wallet struct {
balance int
balance Bitcoin
}
func (w *Wallet) Deposit(units int) {
w.balance += units
func (w *Wallet) Deposit(amount Bitcoin) {
w.balance += amount
}
func (w *Wallet) Balance() int {
func (w *Wallet) Balance() Bitcoin {
return w.balance
}

View File

@ -8,7 +8,7 @@ func TestWallet(t *testing.T) {
wallet.Deposit(10)
got := wallet.Balance()
want := 10
want := Bitcoin(10)
if got != want {
t.Errorf("got %d want %d", got, want)