shapes: make table test more readable

This commit is contained in:
vinchent 2024-09-11 09:19:05 +02:00
parent 47a831ab33
commit f5ecd40f01

View File

@ -14,18 +14,21 @@ func TestPerimeter(t *testing.T) {
func TestArea(t *testing.T) { func TestArea(t *testing.T) {
areaTests := []struct { areaTests := []struct {
shape Shape name string
exp float64 shape Shape
hasArea float64
}{ }{
{Rectangle{30.5, 20.5}, 625.25}, {name: "Rectangle", shape: Rectangle{Width: 30.5, Height: 20.5}, hasArea: 625.25},
{Circle{10}, 314.1592653589793}, {name: "Circle", shape: Circle{Radius: 10}, hasArea: 314.1592653589793},
{Triangle{12, 6}, 36.0}, {name: "Triangle", shape: Triangle{Width: 12, Height: 6}, hasArea: 36.0},
} }
for _, test := range areaTests { for _, test := range areaTests {
got := test.shape.Area() t.Run(test.name, func(t *testing.T) {
if got != test.exp { got := test.shape.Area()
t.Errorf("got %.2f expected %.2f", got, test.exp) if got != test.hasArea {
} t.Errorf("%#v got %g expected %g", test.shape, got, test.hasArea)
}
})
} }
} }