-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdivide_test.go
45 lines (41 loc) · 958 Bytes
/
divide_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
package dividetwointegers
import (
"math"
"testing"
"github.com/WindomZ/testify/assert"
)
func Test_divide(t *testing.T) {
assert.Equal(t, math.MaxInt32, divide(0, 0))
assert.Equal(t, math.MaxInt32, divide(-math.MaxInt32, -1))
assert.Equal(t, 0, divide(0, 1))
assert.Equal(t, 4, divide(12, 3))
assert.Equal(t, 5, divide(15, 3))
assert.Equal(t, 5, divide(16, 3))
assert.Equal(t, 6, divide(18, 3))
assert.Equal(t, 6, divide(19, 3))
assert.Equal(t, 5, divide(20, 4))
assert.Equal(t, 5, divide(23, 4))
assert.Equal(t, 6, divide(24, 4))
assert.Equal(t, -6, divide(27, -4))
}
func Benchmark_divide(b *testing.B) {
b.StopTimer()
b.ReportAllocs()
b.StartTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
divide(0, 0)
divide(-math.MaxInt32, -1)
divide(0, 1)
divide(12, 3)
divide(15, 3)
divide(16, 3)
divide(18, 3)
divide(19, 3)
divide(20, 4)
divide(23, 4)
divide(24, 4)
divide(27, -4)
}
})
}