shapes: use Rectangle as receiver
This commit is contained in:
parent
5de98f3ac8
commit
d5d910db5a
@ -5,10 +5,10 @@ type Rectangle struct {
|
|||||||
Height float64
|
Height float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func Perimeter(r Rectangle) float64 {
|
func (r Rectangle) Perimeter() float64 {
|
||||||
return 2 * (r.Width + r.Height)
|
return 2 * (r.Width + r.Height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Area(r Rectangle) float64 {
|
func (r Rectangle) Area() float64 {
|
||||||
return r.Width * r.Height
|
return r.Width * r.Height
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import "testing"
|
|||||||
|
|
||||||
func TestPerimeter(t *testing.T) {
|
func TestPerimeter(t *testing.T) {
|
||||||
rectangle := Rectangle{30.5, 20.5}
|
rectangle := Rectangle{30.5, 20.5}
|
||||||
got := Perimeter(rectangle)
|
got := rectangle.Perimeter()
|
||||||
exp := 102.0
|
exp := 102.0
|
||||||
|
|
||||||
if got != exp {
|
if got != exp {
|
||||||
@ -13,11 +13,23 @@ func TestPerimeter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestArea(t *testing.T) {
|
func TestArea(t *testing.T) {
|
||||||
rectangle := Rectangle{30.5, 20.5}
|
t.Run("rectangles", func(t *testing.T) {
|
||||||
got := Area(rectangle)
|
rectangle := Rectangle{30.5, 20.5}
|
||||||
exp := 625.25
|
got := rectangle.Area()
|
||||||
|
exp := 625.25
|
||||||
|
|
||||||
if got != exp {
|
if got != exp {
|
||||||
t.Errorf("got %.2f expected %.2f", got, exp)
|
t.Errorf("got %.2f expected %.2f", got, exp)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
// }
|
||||||
|
// })
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user