-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmaxSubArray_test.go
32 lines (28 loc) · 1 KB
/
maxSubArray_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 maximumsubarray
import (
"testing"
"github.com/WindomZ/testify/assert"
)
func Test_maxSubArray(t *testing.T) {
assert.Equal(t, 0, maxSubArray([]int{}))
assert.Equal(t, 7, maxSubArray([]int{1, 2, 3, -4, 5}))
assert.Equal(t, 6, maxSubArray([]int{-2, 1, -3, 4, -1, 2, 1, -5, 4}))
assert.Equal(t, 14, maxSubArray([]int{-2, 1, -3, 4, -1, 2, 1, -5, 4, 9, -6}))
assert.Equal(t, 18, maxSubArray([]int{-2, 1, -3, 4, -1, 2, 1, -5, 4, 9, -6, 10, -12}))
assert.Equal(t, 10, maxSubArray([]int{-2, 1, -3, 4, -1, 2, 1, -5, 4, -9, -6, 10, -12}))
}
func Benchmark_maxSubArray(b *testing.B) {
b.StopTimer()
b.ReportAllocs()
b.StartTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
maxSubArray([]int{})
maxSubArray([]int{1, 2, 3, -4, 5})
maxSubArray([]int{-2, 1, -3, 4, -1, 2, 1, -5, 4})
maxSubArray([]int{-2, 1, -3, 4, -1, 2, 1, -5, 4, 9, -6})
maxSubArray([]int{-2, 1, -3, 4, -1, 2, 1, -5, 4, 9, -6, 10, -12})
maxSubArray([]int{-2, 1, -3, 4, -1, 2, 1, -5, 4, -9, -6, 10, -12})
}
})
}