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) {
areaTests := []struct {
shape Shape
exp float64
name string
shape Shape
hasArea float64
}{
{Rectangle{30.5, 20.5}, 625.25},
{Circle{10}, 314.1592653589793},
{Triangle{12, 6}, 36.0},
{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 {
got := test.shape.Area()
if got != test.exp {
t.Errorf("got %.2f expected %.2f", got, test.exp)
}
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)
}
})
}
}