diff --git a/shapes/shapes_test.go b/shapes/shapes_test.go index 7ca4a32..52ba94c 100644 --- a/shapes/shapes_test.go +++ b/shapes/shapes_test.go @@ -13,24 +13,18 @@ func TestPerimeter(t *testing.T) { } func TestArea(t *testing.T) { - checkArea := func(t testing.TB, shape Shape, exp float64) { - t.Helper() - got := shape.Area() - - if got != exp { - t.Errorf("got %.2f expected %.2f", got, exp) - } + areaTests := []struct { + shape Shape + exp float64 + }{ + {Rectangle{30.5, 20.5}, 625.25}, + {Circle{10}, 314.1592653589793}, } - t.Run("rectangles", func(t *testing.T) { - rectangle := Rectangle{30.5, 20.5} - exp := 625.25 - checkArea(t, rectangle, exp) - }) - - t.Run("circles", func(t *testing.T) { - circle := Circle{10} - exp := 314.1592653589793 - checkArea(t, circle, exp) - }) + for _, test := range areaTests { + got := test.shape.Area() + if got != test.exp { + t.Errorf("got %.2f expected %.2f", got, test.exp) + } + } }