wallet: add wallet struct and balance funcs

This commit is contained in:
vinchent 2024-09-11 11:08:53 +02:00
parent f5ecd40f01
commit 8644bf547b
2 changed files with 29 additions and 0 deletions

13
wallet/wallet.go Normal file
View File

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

16
wallet/wallet_test.go Normal file
View File

@ -0,0 +1,16 @@
package wallet
import "testing"
func TestWallet(t *testing.T) {
wallet := Wallet{}
wallet.Deposit(10)
got := wallet.Balance()
want := 10
if got != want {
t.Errorf("got %d want %d", got, want)
}
}