quii / learn-go-with-tests

Learn Go with test-driven development
MIT License
22.21k stars 2.81k forks source link

Pointers & errors 100% test coverage #797

Open SoroushBeigi opened 3 months ago

SoroushBeigi commented 3 months ago

Pointers & errors chapter tests do not cover the whole codebase, because this function is not tested:

func (b Bitcoin) String() string {
    return fmt.Sprintf("%d BTC", b)
}

which can be covered with the test below:

t.Run("Bitcoin String", func(t *testing.T) {
        btc := Bitcoin(10)
        got := btc.String()
        want := "10 BTC"

        if got != want {
            t.Errorf("got %s want %s", got, want)
        }
    })

I strongly believe that we should encourage learners to find why the test coverage is not 100% and fix it as an assignment first.

SoroushBeigi commented 3 months ago

@quii should I go for it?

quii commented 3 months ago

Sure, but do a quick draft first so I can help you

SoroushBeigi commented 3 months ago

@quii I created this PR with basic practice exercise added. feel free to tell me any possible improvements