shapes: add rectangle perimeter and area funcs
This commit is contained in:
parent
2353543f7d
commit
9381e4c92a
9
shapes/shapes.go
Normal file
9
shapes/shapes.go
Normal 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
21
shapes/shapes_test.go
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user