-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrains_test.go
52 lines (46 loc) · 1.11 KB
/
grains_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
package grains
import (
"testing"
)
func TestSquare(t *testing.T) {
for _, tc := range squareTests {
t.Run(tc.description, func(t *testing.T) {
actualVal, actualErr := Square(tc.input)
if tc.expectError {
if actualErr == nil {
t.Errorf("Square(%d) expected an error, got: %d", tc.input, actualVal)
}
} else {
if actualErr != nil {
t.Errorf("Square(%d) expected %d, but got error: %v", tc.input, actualVal, actualErr)
} else if actualVal != tc.expectedVal {
t.Errorf("Square(%d) = %d, want %d", tc.input, actualVal, tc.expectedVal)
}
}
})
}
}
func TestTotal(t *testing.T) {
var expected uint64 = 18446744073709551615
if actual := Total(); actual != expected {
t.Errorf("Total() = %d, want:%d", actual, expected)
}
}
func BenchmarkSquare(b *testing.B) {
if testing.Short() {
b.Skip("skipping benchmark in short mode.")
}
for i := 0; i < b.N; i++ {
for _, test := range squareTests {
Square(test.input)
}
}
}
func BenchmarkTotal(b *testing.B) {
if testing.Short() {
b.Skip("skipping benchmark in short mode.")
}
for i := 0; i < b.N; i++ {
Total()
}
}