wallet: add wallet struct and balance funcs
This commit is contained in:
parent
f5ecd40f01
commit
8644bf547b
13
wallet/wallet.go
Normal file
13
wallet/wallet.go
Normal 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
16
wallet/wallet_test.go
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user