From 595ed65745d93d020fd0657d2cbe23bdba9e952d Mon Sep 17 00:00:00 2001 From: vinchent Date: Wed, 11 Sep 2024 09:14:28 +0200 Subject: [PATCH] shapes: transform to a table test --- shapes/shapes_test.go | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) 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) + } + } }