shapes: add rectangle perimeter and area funcs

This commit is contained in:
vinchent 2024-09-11 08:55:19 +02:00
parent 2353543f7d
commit 9381e4c92a
2 changed files with 30 additions and 0 deletions

9
shapes/shapes.go Normal file
View File

@ -0,0 +1,9 @@
package shapes
func Perimeter(width, height float64) float64 {
return 2 * (width + height)
}
func Area(width, height float64) float64 {
return width * height
}

21
shapes/shapes_test.go Normal file
View File

@ -0,0 +1,21 @@
package shapes
import "testing"
func TestPerimeter(t *testing.T) {
got := Perimeter(30.5, 20.5)
exp := 102.0
if got != exp {
t.Errorf("got %.2f expected %.2f", got, exp)
}
}
func TestArea(t *testing.T) {
got := Area(30.5, 20.5)
exp := 625.25
if got != exp {
t.Errorf("got %.2f expected %.2f", got, exp)
}
}