-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem061_test.go
More file actions
44 lines (38 loc) · 895 Bytes
/
Copy pathproblem061_test.go
File metadata and controls
44 lines (38 loc) · 895 Bytes
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
package problem061
import (
"testing"
)
type argumentSet struct {
base int
exponent int
result int
}
func assert(t *testing.T, actual int, expected int) bool {
t.Logf("Actual: %d / Expected: %d", actual, expected)
if actual != expected {
return false
}
return true
}
func getBenchmark(pow func(int, int) int, base int, exponent int) func(*testing.B) {
return func(b *testing.B) {
for i := 0; i < b.N; i++ {
pow(base, exponent)
}
}
}
func TestPow(t *testing.T) {
testCases := []argumentSet{
{
base: 8,
exponent: 19,
},
}
for _, testCase := range testCases {
if !assert(t, PowFaster(testCase.base, testCase.exponent), PowSimple(testCase.base, testCase.exponent)) {
t.FailNow()
}
testing.Benchmark(getBenchmark(PowFaster, testCase.base, testCase.exponent))
testing.Benchmark(getBenchmark(PowSimple, testCase.base, testCase.exponent))
}
}