From 8644bf547b386fbd3b107707f671b91697dec620 Mon Sep 17 00:00:00 2001 From: vinchent Date: Wed, 11 Sep 2024 11:08:53 +0200 Subject: [PATCH] wallet: add wallet struct and balance funcs --- wallet/wallet.go | 13 +++++++++++++ wallet/wallet_test.go | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 wallet/wallet.go create mode 100644 wallet/wallet_test.go diff --git a/wallet/wallet.go b/wallet/wallet.go new file mode 100644 index 0000000..440ff47 --- /dev/null +++ b/wallet/wallet.go @@ -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 +} diff --git a/wallet/wallet_test.go b/wallet/wallet_test.go new file mode 100644 index 0000000..e17a7a9 --- /dev/null +++ b/wallet/wallet_test.go @@ -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) + } +}