counter: refactor, add assertCounter func
This commit is contained in:
parent
41ae820a21
commit
ea6f225992
@ -2,6 +2,13 @@ package counter
|
|||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
|
func assertCounter(t testing.TB, got Counter, want int) {
|
||||||
|
t.Helper()
|
||||||
|
if got.Value() != want {
|
||||||
|
t.Errorf("got %d, want %d", got.Value(), want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCounter(t *testing.T) {
|
func TestCounter(t *testing.T) {
|
||||||
t.Run("incrementing the counter 3 times leaves it at 3", func(t *testing.T) {
|
t.Run("incrementing the counter 3 times leaves it at 3", func(t *testing.T) {
|
||||||
counter := Counter{}
|
counter := Counter{}
|
||||||
@ -9,12 +16,7 @@ func TestCounter(t *testing.T) {
|
|||||||
counter.Inc()
|
counter.Inc()
|
||||||
counter.Inc()
|
counter.Inc()
|
||||||
counter.Inc()
|
counter.Inc()
|
||||||
|
|
||||||
assertCounter(t, counter, 3)
|
assertCounter(t, counter, 3)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertCounter(t testing.TB, got Counter, want int) {
|
|
||||||
if got.Value() != 3 {
|
|
||||||
t.Errorf("got %d, want %d", got.Value(), want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user