gotdd/shapes_test.go

34 lines
657 B
Go
Raw Permalink Normal View History

2022-01-20 04:20:12 +00:00
package main
import "testing"
func TestPerimeter(t *testing.T) {
rectangle := Rectangle{10.0, 10.0}
got := Perimeter(rectangle)
want := 40.0
if got != want {
t.Errorf("got %.2f want %.2f", got, want)
}
}
func TestArea(t *testing.T) {
areaTests := []struct {
name string
shape Shape
hasArea float64
}{
{name: "Rectangle", shape: Rectangle{12, 6}, hasArea: 72.0},
{name: "Circle", shape: Circle{10}, hasArea: 314.1592653589793},
{name: "Triangle", shape: Triangle{12, 6}, hasArea: 36},
}
for _, tt := range areaTests {
got := tt.shape.Area()
if got != tt.hasArea {
t.Errorf("got %g want %g", got, tt.hasArea)
}
}
}