shapes: add Circle struct and Area func
This commit is contained in:
parent
d5d910db5a
commit
ff89c50710
@ -1,10 +1,16 @@
|
|||||||
package shapes
|
package shapes
|
||||||
|
|
||||||
|
import "math"
|
||||||
|
|
||||||
type Rectangle struct {
|
type Rectangle struct {
|
||||||
Width float64
|
Width float64
|
||||||
Height float64
|
Height float64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Circle struct {
|
||||||
|
Radius float64
|
||||||
|
}
|
||||||
|
|
||||||
func (r Rectangle) Perimeter() float64 {
|
func (r Rectangle) Perimeter() float64 {
|
||||||
return 2 * (r.Width + r.Height)
|
return 2 * (r.Width + r.Height)
|
||||||
}
|
}
|
||||||
@ -12,3 +18,7 @@ func (r Rectangle) Perimeter() float64 {
|
|||||||
func (r Rectangle) Area() float64 {
|
func (r Rectangle) Area() float64 {
|
||||||
return r.Width * r.Height
|
return r.Width * r.Height
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c Circle) Area() float64 {
|
||||||
|
return c.Radius * c.Radius * math.Pi
|
||||||
|
}
|
||||||
|
@ -23,13 +23,13 @@ func TestArea(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// t.Run("circles", func(t *testing.T) {
|
t.Run("circles", func(t *testing.T) {
|
||||||
// circle := Circle{10}
|
circle := Circle{10}
|
||||||
// got := Area(circle)
|
got := circle.Area()
|
||||||
// exp := 314.1592653589793
|
exp := 314.1592653589793
|
||||||
//
|
|
||||||
// if got != exp {
|
if got != exp {
|
||||||
// t.Errorf("got %.2f expected %.2f", got, exp)
|
t.Errorf("got %.2f expected %.2f", got, exp)
|
||||||
// }
|
}
|
||||||
// })
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user