shapes: add Triangle area test

This commit is contained in:
vinchent 2024-09-11 09:17:21 +02:00
parent 595ed65745
commit 47a831ab33
2 changed files with 17 additions and 5 deletions

View File

@ -1,6 +1,8 @@
package shapes
import "math"
import (
"math"
)
type Shape interface {
Area() float64
@ -11,10 +13,6 @@ type Rectangle struct {
Height float64
}
type Circle struct {
Radius float64
}
func (r Rectangle) Perimeter() float64 {
return 2 * (r.Width + r.Height)
}
@ -23,6 +21,19 @@ func (r Rectangle) Area() float64 {
return r.Width * r.Height
}
type Circle struct {
Radius float64
}
func (c Circle) Area() float64 {
return c.Radius * c.Radius * math.Pi
}
type Triangle struct {
Width float64
Height float64
}
func (t Triangle) Area() float64 {
return t.Width * t.Height * 0.5
}

View File

@ -19,6 +19,7 @@ func TestArea(t *testing.T) {
}{
{Rectangle{30.5, 20.5}, 625.25},
{Circle{10}, 314.1592653589793},
{Triangle{12, 6}, 36.0},
}
for _, test := range areaTests {