35 lines
785 B
Go
35 lines
785 B
Go
package shapes
|
|
|
|
import "testing"
|
|
|
|
func TestPerimeter(t *testing.T) {
|
|
rectangle := Rectangle{30.5, 20.5}
|
|
got := rectangle.Perimeter()
|
|
exp := 102.0
|
|
|
|
if got != exp {
|
|
t.Errorf("got %.2f expected %.2f", got, exp)
|
|
}
|
|
}
|
|
|
|
func TestArea(t *testing.T) {
|
|
areaTests := []struct {
|
|
name string
|
|
shape Shape
|
|
hasArea float64
|
|
}{
|
|
{name: "Rectangle", shape: Rectangle{Width: 30.5, Height: 20.5}, hasArea: 625.25},
|
|
{name: "Circle", shape: Circle{Radius: 10}, hasArea: 314.1592653589793},
|
|
{name: "Triangle", shape: Triangle{Width: 12, Height: 6}, hasArea: 36.0},
|
|
}
|
|
|
|
for _, test := range areaTests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
got := test.shape.Area()
|
|
if got != test.hasArea {
|
|
t.Errorf("%#v got %g expected %g", test.shape, got, test.hasArea)
|
|
}
|
|
})
|
|
}
|
|
}
|