-
Notifications
You must be signed in to change notification settings - Fork 0
/
positions_test.go
71 lines (65 loc) · 1.62 KB
/
positions_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package sqroot
import (
"testing"
"github.com/keep94/consume2"
"github.com/stretchr/testify/assert"
)
func TestPositionsBuilder(t *testing.T) {
var pb PositionsBuilder
pb.AddRange(0, 2).Add(4).Add(10).AddRange(-1, 3)
pb.AddRange(15, 17)
pb.AddRange(-3, -1)
pb.AddRange(13, 15)
pb.AddRange(17, 19)
pb.Add(1)
pb.AddRange(20, 25)
pb.AddRange(21, 26)
pb.AddRange(22, 23)
assert.True(t, pb.unsorted)
p := pb.Build()
assert.False(t, pb.unsorted)
assert.Len(t, pb.ranges, 0)
expected := []PositionRange{
{Start: 0, End: 3},
{Start: 4, End: 5},
{Start: 10, End: 11},
{Start: 13, End: 19},
{Start: 20, End: 26},
}
var actual []PositionRange
consume2.FromGenerator(p.Ranges(), consume2.AppendTo(&actual))
assert.Equal(t, expected, actual)
assert.Equal(t, 26, p.End())
}
func TestPositionsBuilderSorted(t *testing.T) {
var pb PositionsBuilder
pb.AddRange(0, 3).AddRange(1, 4).Add(2)
pb.AddRange(4, 6).AddRange(10, 15).AddRange(6, 6).AddRange(7, 5)
pb.AddRange(12, 17)
for i := 100; i < 200; i++ {
pb.Add(i)
}
assert.False(t, pb.unsorted)
assert.Len(t, pb.ranges, 3)
p := pb.Build()
assert.False(t, pb.unsorted)
assert.Len(t, pb.ranges, 0)
expected := []PositionRange{
{Start: 0, End: 6},
{Start: 10, End: 17},
{Start: 100, End: 200},
}
var actual []PositionRange
consume2.FromGenerator(p.Ranges(), consume2.AppendTo(&actual))
assert.Equal(t, expected, actual)
assert.Equal(t, 200, p.End())
}
func TestPositionsBuilderNegative(t *testing.T) {
var pb PositionsBuilder
pb.Add(-1)
assert.Zero(t, pb.Build())
}
func TestPositionsBuilderZero(t *testing.T) {
var pb PositionsBuilder
assert.Zero(t, pb.Build())
}