forked from GolangUnited/golang-united-school-homework-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.go
41 lines (31 loc) · 859 Bytes
/
solution.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package square
import (
"math"
)
// Define custom int type to hold sides number and update CalcSquare signature by replacing #yourTypeNameHere#
// Define constants to represent 0, 3 and 4 sides. Test uses mnemos: SidesTriangle(==3), SidesSquare(==4), SidesCircle(==0)
// it's like:
// CalcSquare(10.0, SidesTriangle)
// CalcSquare(10.0, SidesSquare)
// CalcSquare(10.0, SidesCircle)
type sideQuantity int
const (
SidesTriangle sideQuantity = 3
SidesSquare sideQuantity = 4
SidesCircle sideQuantity = 0
)
func CalcSquare(sideLen float64, sidesNum sideQuantity) float64 {
switch sidesNum {
case SidesTriangle:
square := math.Sqrt(3)/4*math.Pow(sideLen, 2)
return square
case SidesSquare:
square := math.Pow(sideLen,2)
return square
case SidesCircle:
square := math.Pi * math.Pow(sideLen,2)
return square
default:
return 0
}
}