diff --git a/shapes/shapes.go b/shapes/shapes.go index 0ae1413..fded288 100644 --- a/shapes/shapes.go +++ b/shapes/shapes.go @@ -2,6 +2,10 @@ package shapes import "math" +type Shape interface { + Area() float64 +} + type Rectangle struct { Width float64 Height float64 diff --git a/shapes/shapes_test.go b/shapes/shapes_test.go index 7d50ddf..7ca4a32 100644 --- a/shapes/shapes_test.go +++ b/shapes/shapes_test.go @@ -13,23 +13,24 @@ func TestPerimeter(t *testing.T) { } func TestArea(t *testing.T) { - t.Run("rectangles", func(t *testing.T) { - rectangle := Rectangle{30.5, 20.5} - got := rectangle.Area() - exp := 625.25 + 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) } + } + + 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} - got := circle.Area() exp := 314.1592653589793 - - if got != exp { - t.Errorf("got %.2f expected %.2f", got, exp) - } + checkArea(t, circle, exp) }) }