Saving pointers work

drew/sql-it
Drew Bednar 8 months ago
parent 3686956a02
commit 27d4857f3c

@ -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) {

@ -0,0 +1,4 @@
# Pointers and Errors
https://quii.gitbook.io/learn-go-with-tests/go-fundamentals/pointers-and-errors

@ -0,0 +1,3 @@
module pointers_errors
go 1.21.0

@ -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
}

@ -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)
}
}

@ -4,4 +4,4 @@ You can run individual tests like:
```
go test -run TestArea/Rectangle
```
```
Loading…
Cancel
Save