-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtrap_test.go
32 lines (28 loc) · 842 Bytes
/
trap_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
package trappingrainwater
import (
"testing"
"github.com/WindomZ/testify/assert"
)
func Test_trap(t *testing.T) {
assert.Equal(t, 0, trap([]int{}))
assert.Equal(t, 3, trap([]int{4, 1, 0, 2, 1, 0}))
assert.Equal(t, 8, trap([]int{4, 4, 2, 2, 1, 3, 5}))
assert.Equal(t, 8, trap([]int{4, 4, 2, 2, 1, 3, 5, 5, 5}))
assert.Equal(t, 6, trap([]int{0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1}))
assert.Equal(t, 16, trap([]int{2, 1, 6, 6, 1, 1, 1, 3, 5, 1, 2, 1}))
}
func Benchmark_trap(b *testing.B) {
b.StopTimer()
b.ReportAllocs()
b.StartTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
trap([]int{})
trap([]int{4, 1, 0, 2, 1, 0})
trap([]int{4, 4, 2, 2, 1, 3, 5})
trap([]int{4, 4, 2, 2, 1, 3, 5, 5, 5})
trap([]int{0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1})
trap([]int{2, 1, 6, 6, 1, 1, 1, 3, 5, 1, 2, 1})
}
})
}