This repository has been archived by the owner on Nov 20, 2023. It is now read-only.
forked from GolangUnited/golang-united-school-homework-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution_test.go
69 lines (63 loc) · 1.42 KB
/
solution_test.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package square
import (
"math"
"testing"
)
const deltaTesting = 0.001
func equalDeltaFloat64(a, b, delta float64) bool {
return math.Abs(b-a) < delta
}
func Test_solutionSquare(t *testing.T) {
data := []struct {
In float64
Expected float64
}{
{In: 0, Expected: 0},
{In: 1, Expected: 1},
{In: 4.4, Expected: 19.36},
{In: 15.67, Expected: 245.5489},
}
for _, q := range data {
got := CalcSquare(q.In, SidesSquare)
if !equalDeltaFloat64(got, q.Expected, deltaTesting) {
t.Logf("Square4 expected: %f, got: %f", q.Expected, got)
t.Fail()
}
}
}
func Test_solutionTriangle(t *testing.T) {
data := []struct {
In float64
Expected float64
}{
{In: 0, Expected: 0},
{In: 1, Expected: 0.433013},
{In: 4.4, Expected: 8.383126},
{In: 15.67, Expected: 106.325793},
}
for _, q := range data {
got := CalcSquare(q.In, SidesTriangle)
if !equalDeltaFloat64(got, q.Expected, deltaTesting) {
t.Logf("Square4 expected: %f, got: %f", q.Expected, got)
t.Fail()
}
}
}
func Test_solutionCircle(t *testing.T) {
data := []struct {
In float64
Expected float64
}{
{In: 0, Expected: 0},
{In: 1, Expected: 3.141593},
{In: 4.4, Expected: 60.821234},
{In: 15.67, Expected: 771.414620},
}
for _, q := range data {
got := CalcSquare(q.In, SidesCircle)
if !equalDeltaFloat64(got, q.Expected, deltaTesting) {
t.Logf("Square0 expected: %f, got: %f", q.Expected, got)
t.Fail()
}
}
}