This repository was archived by the owner on Jan 30, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathiterator_test.go
More file actions
145 lines (110 loc) · 3.3 KB
/
Copy pathiterator_test.go
File metadata and controls
145 lines (110 loc) · 3.3 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package skiptake
import "testing"
func Test_SkipTake_Seek(t *testing.T) {
subject := []uint64{10, 11, 12, 13, 14, 20, 21, 22, 30, 40, 41, 42, 43, 44, 50}
list := Create(subject...)
t.Logf("%v -> %v", subject, list)
iter := list.Iterate()
skip, take := iter.NextSkipTake()
expectUint64(t, skip, 10)
expectUint64(t, take, 5)
n := iter.Next()
expectUint64(t, n, 10)
skip, take = iter.Seek(5)
expectUint64(t, skip, 20)
expectUint64(t, take, 3)
// Check that next works after a seek
n = iter.Next()
expectUint64(t, n, 20)
// Seek for the current position
_, _ = iter.Seek(6)
n = iter.Next()
expectUint64(t, n, 21)
// Seek again
skip, take = iter.Seek(10)
expectUint64(t, skip, 41)
expectUint64(t, take, 4)
// Check NextSkipTake works after a seek
skip, take = iter.NextSkipTake()
expectUint64(t, skip, 5)
expectUint64(t, take, 1)
//Seek backwards
skip, take = iter.Seek(1)
expectUint64(t, skip, 11)
expectUint64(t, take, 4)
// Seek beyond the end
skip, take = iter.Seek(16)
expectUint64(t, take, 0)
}
func Test_SkipTake_IterNextSkipTake(t *testing.T) {
list := FromRaw(1, 10, 2, 20, 3, 30, 4, 40)
iter := list.Iterate()
skip, take := iter.NextSkipTake()
expectUint64(t, skip, 1)
expectUint64(t, take, 10)
skip, take = iter.NextSkipTake()
expectUint64(t, skip, 2)
expectUint64(t, take, 20)
skip, take = iter.NextSkipTake()
expectUint64(t, skip, 3)
expectUint64(t, take, 30)
skip, take = iter.NextSkipTake()
expectUint64(t, skip, 4)
expectUint64(t, take, 40)
skip, take = iter.NextSkipTake()
expectUint64(t, skip, 0)
expectUint64(t, take, 0)
}
func Test_SkipTake_IterNextSkipTakeSeek(t *testing.T) {
list := FromRaw(1, 10, 2, 20, 3, 30, 4, 40)
iter := list.Iterate()
t.Logf("%v", list)
skip, take := iter.NextSkipTake()
expectUint64(t, skip, 1)
expectUint64(t, take, 10)
skip, take = iter.Seek(12)
expectUint64(t, skip, 15)
expectUint64(t, take, 18)
expectUint64(t, iter.Next(), 15)
skip, take = iter.NextSkipTake()
expectUint64(t, skip, 3)
expectUint64(t, take, 30)
skip, take = iter.Seek(0)
expectUint64(t, skip, 1)
expectUint64(t, take, 10)
}
func Test_SkipTake_IterMixNext(t *testing.T) {
list := makeRange(
intrv{0, 4}, intrv{10, 14}, intrv{20, 24}, intrv{30, 34}, intrv{40, 44})
iter := list.Iterate()
t.Logf("%v", list)
// Get skip-take pair. In the interval of [0, 4]
skip, take := iter.NextSkipTake()
expectUint64(t, skip, 0)
expectUint64(t, take, 5)
// Get individual values. In the interval of [0, 4]
expectUint64(t, iter.Next(), 0)
expectUint64(t, iter.Next(), 1)
// Current interval is now [2, 4]
// Get next skip-take pair. In the interval of [10, 14]
skip, take = iter.NextSkipTake()
expectUint64(t, skip, 5)
expectUint64(t, take, 5)
// Get next skip-take pair. In the interval of [20, 24]
skip, take = iter.NextSkipTake()
expectUint64(t, skip, 5)
expectUint64(t, take, 5)
// Get individual values until we leave the interval
expectUint64(t, iter.Next(), 20)
expectUint64(t, iter.Next(), 21)
expectUint64(t, iter.Next(), 22)
expectUint64(t, iter.Next(), 23)
expectUint64(t, iter.Next(), 24)
expectUint64(t, iter.Next(), 30)
expectUint64(t, iter.Next(), 31)
// Get next skip-take pair. In the interval of [40, 44]
skip, take = iter.NextSkipTake()
expectUint64(t, skip, 5)
expectUint64(t, take, 5)
expectUint64(t, iter.Next(), 40)
}