-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmathutil_test.go
133 lines (120 loc) · 1.69 KB
/
mathutil_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package main
import "testing"
func testNumberOfDigits(n int, nbOfDigits int) bool {
result := numberOfDigits(n)
return result == nbOfDigits
}
type numberOfDigitsTestSet struct {
number int
nbOfDigits int
}
func TestNumberOfDigits(t *testing.T) {
sets := []numberOfDigitsTestSet{
{
number: 1,
nbOfDigits: 1,
},
{
number: 3,
nbOfDigits: 3,
},
{
number: 10,
nbOfDigits: 11,
},
{
number: 24,
nbOfDigits: 39,
},
{
number: 278,
nbOfDigits: 726,
},
{
number: 300,
nbOfDigits: 792,
},
}
for _, set := range sets {
if !testNumberOfDigits(set.number, set.nbOfDigits) {
t.Log(set.number, "-", set.nbOfDigits)
t.Fail()
}
}
}
func testGcd(a, b, result int) bool {
return gcd(a, b) == result
}
type gcdTestSet struct {
a int
b int
result int
}
func TestGcd(t *testing.T) {
sets := []gcdTestSet{
{
a: 15,
b: 5,
result: 5,
},
{
a: 15,
b: 85,
result: 5,
},
{
a: 153,
b: 54,
result: 9,
},
{
a: 7,
b: 89,
result: 1,
},
}
for _, set := range sets {
if !testGcd(set.a, set.b, set.result) {
t.Log(set.a, set.b, set.result)
t.Fail()
}
}
}
func testLcm(a, b, result int) bool {
return lcm(a, b) == result
}
type lcmTestSet struct {
a int
b int
result int
}
func TestLcm(t *testing.T) {
sets := []lcmTestSet{
{
a: 15,
b: 5,
result: 15,
},
{
a: 21,
b: 14,
result: 42,
},
{
a: 157,
b: 59,
result: 157*59,
},
{
a: 9,
b: 15,
result: 45,
},
}
for _, set := range sets {
if !testLcm(set.a, set.b, set.result) {
t.Log(set.a, set.b, set.result)
t.Fail()
}
}
}