shapes: transform to a table test
This commit is contained in:
		@ -13,24 +13,18 @@ func TestPerimeter(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestArea(t *testing.T) {
 | 
					func TestArea(t *testing.T) {
 | 
				
			||||||
	checkArea := func(t testing.TB, shape Shape, exp float64) {
 | 
						areaTests := []struct {
 | 
				
			||||||
		t.Helper()
 | 
							shape Shape
 | 
				
			||||||
		got := shape.Area()
 | 
							exp   float64
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
		if got != exp {
 | 
							{Rectangle{30.5, 20.5}, 625.25},
 | 
				
			||||||
			t.Errorf("got %.2f expected %.2f", got, exp)
 | 
							{Circle{10}, 314.1592653589793},
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	t.Run("rectangles", func(t *testing.T) {
 | 
						for _, test := range areaTests {
 | 
				
			||||||
		rectangle := Rectangle{30.5, 20.5}
 | 
							got := test.shape.Area()
 | 
				
			||||||
		exp := 625.25
 | 
							if got != test.exp {
 | 
				
			||||||
		checkArea(t, rectangle, exp)
 | 
								t.Errorf("got %.2f expected %.2f", got, test.exp)
 | 
				
			||||||
	})
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	t.Run("circles", func(t *testing.T) {
 | 
					 | 
				
			||||||
		circle := Circle{10}
 | 
					 | 
				
			||||||
		exp := 314.1592653589793
 | 
					 | 
				
			||||||
		checkArea(t, circle, exp)
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user