From 27d4857f3c57887dcab60c5affd9f117117b764a Mon Sep 17 00:00:00 2001 From: Drew Bednar Date: Mon, 17 Jun 2024 17:03:39 -0400 Subject: [PATCH] Saving pointers work --- learn_go_with_tests/arrays/sum_test.go | 1 + learn_go_with_tests/pointers_errors/README.md | 4 ++++ learn_go_with_tests/pointers_errors/go.mod | 3 +++ learn_go_with_tests/pointers_errors/wallet.go | 12 ++++++++++++ .../pointers_errors/wallet_test.go | 17 +++++++++++++++++ learn_go_with_tests/structs/README.md | 2 +- 6 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 learn_go_with_tests/pointers_errors/README.md create mode 100644 learn_go_with_tests/pointers_errors/go.mod create mode 100644 learn_go_with_tests/pointers_errors/wallet.go create mode 100644 learn_go_with_tests/pointers_errors/wallet_test.go diff --git a/learn_go_with_tests/arrays/sum_test.go b/learn_go_with_tests/arrays/sum_test.go index 1c275e0..99de6f7 100644 --- a/learn_go_with_tests/arrays/sum_test.go +++ b/learn_go_with_tests/arrays/sum_test.go @@ -86,6 +86,7 @@ func TestSumAll(t *testing.T) { func TestSumAllTails(t *testing.T) { // Another example of helper function + // By defining this function inside the test, it cannot be used by other functions in this package. checkSums := func(t testing.TB, got, want []int) { t.Helper() if !reflect.DeepEqual(got, want) { diff --git a/learn_go_with_tests/pointers_errors/README.md b/learn_go_with_tests/pointers_errors/README.md new file mode 100644 index 0000000..4496445 --- /dev/null +++ b/learn_go_with_tests/pointers_errors/README.md @@ -0,0 +1,4 @@ +# Pointers and Errors + +https://quii.gitbook.io/learn-go-with-tests/go-fundamentals/pointers-and-errors + diff --git a/learn_go_with_tests/pointers_errors/go.mod b/learn_go_with_tests/pointers_errors/go.mod new file mode 100644 index 0000000..29c1b86 --- /dev/null +++ b/learn_go_with_tests/pointers_errors/go.mod @@ -0,0 +1,3 @@ +module pointers_errors + +go 1.21.0 diff --git a/learn_go_with_tests/pointers_errors/wallet.go b/learn_go_with_tests/pointers_errors/wallet.go new file mode 100644 index 0000000..cde9e66 --- /dev/null +++ b/learn_go_with_tests/pointers_errors/wallet.go @@ -0,0 +1,12 @@ +package pointers_errors + +type Wallet struct { + balance int +} + +func (w Wallet) Deposit(amount int) { +} + +func (w Wallet) Balance() int { + return 0 +} diff --git a/learn_go_with_tests/pointers_errors/wallet_test.go b/learn_go_with_tests/pointers_errors/wallet_test.go new file mode 100644 index 0000000..32de526 --- /dev/null +++ b/learn_go_with_tests/pointers_errors/wallet_test.go @@ -0,0 +1,17 @@ +package pointers_errors + +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) + } +} diff --git a/learn_go_with_tests/structs/README.md b/learn_go_with_tests/structs/README.md index b695dce..f8d5f5f 100644 --- a/learn_go_with_tests/structs/README.md +++ b/learn_go_with_tests/structs/README.md @@ -4,4 +4,4 @@ You can run individual tests like: ``` go test -run TestArea/Rectangle -``` +``` \ No newline at end of file