1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // This file contains tests for some of the internal functions.
14 // Helpers to save typing in the test cases.
18 type SplitTest struct {
28 m_1 = ^uint64(0) // -1 when signed.
29 m_2 = ^uint64(0) - 1 // -2 when signed.
32 var splitTests = []SplitTest{
33 // No need for a test for the empty case; that's picked off before splitIntoRuns.
35 {u{1}, uu{u{1}}, false},
37 {u{3, 2, 1}, uu{u{1, 2, 3}}, true},
39 {u{3, 2, 1}, uu{u{1, 2, 3}}, false},
40 // A gap at the beginning.
41 {u{1, 33, 32, 31}, uu{u{1}, u{31, 32, 33}}, true},
42 // A gap in the middle, in mixed order.
43 {u{33, 7, 32, 31, 9, 8}, uu{u{7, 8, 9}, u{31, 32, 33}}, true},
45 {u{33, 44, 1, 32, 45, 31}, uu{u{1}, u{31, 32, 33}, u{44, 45}}, true},
46 // Unsigned values spanning 0.
47 {u{m1, m0, m_1, m2, m_2}, uu{u{m0, m1, m2}, u{m_2, m_1}}, false},
48 // Signed values spanning 0
49 {u{m1, m0, m_1, m2, m_2}, uu{u{m_2, m_1, m0, m1, m2}}, true},
52 func TestSplitIntoRuns(t *testing.T) {
54 for n, test := range splitTests {
55 values := make([]Value, len(test.input))
56 for i, v := range test.input {
57 values[i] = Value{"", "", v, test.signed, fmt.Sprint(v)}
59 runs := splitIntoRuns(values)
60 if len(runs) != len(test.output) {
61 t.Errorf("#%d: %v: got %d runs; expected %d", n, test.input, len(runs), len(test.output))
64 for i, run := range runs {
65 if len(run) != len(test.output[i]) {
66 t.Errorf("#%d: got %v; expected %v", n, runs, test.output)
69 for j, v := range run {
70 if v.value != test.output[i][j] {
71 t.Errorf("#%d: got %v; expected %v", n, runs, test.output)