2016-01-12 14:06:59 +03:00
|
|
|
package match
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-02-02 22:03:37 +03:00
|
|
|
var bench_separators = []rune{'.'}
|
|
|
|
|
2016-01-18 13:07:28 +03:00
|
|
|
const bench_pattern = "abcdefghijklmnopqrstuvwxyz0123456789"
|
|
|
|
|
2016-02-02 22:03:37 +03:00
|
|
|
func TestAppendMerge(t *testing.T) {
|
2016-01-12 14:06:59 +03:00
|
|
|
for id, test := range []struct {
|
2016-02-02 22:03:37 +03:00
|
|
|
segments [2][]int
|
2016-01-12 14:06:59 +03:00
|
|
|
exp []int
|
|
|
|
}{
|
|
|
|
{
|
2016-02-02 22:03:37 +03:00
|
|
|
[2][]int{
|
2016-01-12 14:06:59 +03:00
|
|
|
[]int{0, 6, 7},
|
|
|
|
[]int{0, 1, 3},
|
|
|
|
},
|
2016-02-02 22:03:37 +03:00
|
|
|
[]int{0, 1, 3, 6, 7},
|
2016-01-12 14:06:59 +03:00
|
|
|
},
|
|
|
|
{
|
2016-02-02 22:03:37 +03:00
|
|
|
[2][]int{
|
2016-01-12 14:06:59 +03:00
|
|
|
[]int{0, 1, 3, 6, 7},
|
2016-02-02 22:03:37 +03:00
|
|
|
[]int{0, 1, 10},
|
2016-01-12 14:06:59 +03:00
|
|
|
},
|
2016-02-02 22:03:37 +03:00
|
|
|
[]int{0, 1, 3, 6, 7, 10},
|
2016-01-12 14:06:59 +03:00
|
|
|
},
|
|
|
|
} {
|
2016-02-02 22:03:37 +03:00
|
|
|
act := appendMerge(test.segments[0], test.segments[1])
|
2016-01-12 14:06:59 +03:00
|
|
|
if !reflect.DeepEqual(act, test.exp) {
|
|
|
|
t.Errorf("#%d merge sort segments unexpected:\nact: %v\nexp:%v", id, act, test.exp)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-02 22:03:37 +03:00
|
|
|
|
|
|
|
func BenchmarkAppendMerge(b *testing.B) {
|
|
|
|
s1 := []int{0, 1, 3, 6, 7}
|
|
|
|
s2 := []int{0, 1, 3}
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
appendMerge(s1, s2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkAppendMergeParallel(b *testing.B) {
|
|
|
|
s1 := []int{0, 1, 3, 6, 7}
|
|
|
|
s2 := []int{0, 1, 3}
|
|
|
|
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
for pb.Next() {
|
|
|
|
appendMerge(s1, s2)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkReverse(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
reverseSegments([]int{1, 2, 3, 4})
|
|
|
|
}
|
|
|
|
}
|