32 lines
556 B
Go
32 lines
556 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 {
|
|
shape Shape
|
|
exp float64
|
|
}{
|
|
{Rectangle{30.5, 20.5}, 625.25},
|
|
{Circle{10}, 314.1592653589793},
|
|
{Triangle{12, 6}, 36.0},
|
|
}
|
|
|
|
for _, test := range areaTests {
|
|
got := test.shape.Area()
|
|
if got != test.exp {
|
|
t.Errorf("got %.2f expected %.2f", got, test.exp)
|
|
}
|
|
}
|
|
}
|