diff --git a/shapes/shapes.go b/shapes/shapes.go index 6bc9d9a..0ae1413 100644 --- a/shapes/shapes.go +++ b/shapes/shapes.go @@ -1,10 +1,16 @@ package shapes +import "math" + type Rectangle struct { Width float64 Height float64 } +type Circle struct { + Radius float64 +} + func (r Rectangle) Perimeter() float64 { return 2 * (r.Width + r.Height) } @@ -12,3 +18,7 @@ func (r Rectangle) Perimeter() float64 { func (r Rectangle) Area() float64 { return r.Width * r.Height } + +func (c Circle) Area() float64 { + return c.Radius * c.Radius * math.Pi +} diff --git a/shapes/shapes_test.go b/shapes/shapes_test.go index 0c47a67..7d50ddf 100644 --- a/shapes/shapes_test.go +++ b/shapes/shapes_test.go @@ -23,13 +23,13 @@ func TestArea(t *testing.T) { } }) - // t.Run("circles", func(t *testing.T) { - // circle := Circle{10} - // got := Area(circle) - // exp := 314.1592653589793 - // - // if got != exp { - // t.Errorf("got %.2f expected %.2f", got, 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) + } + }) }