-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseq_test.go
85 lines (71 loc) · 1.65 KB
/
seq_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package utp_go
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestContainsStart(t *testing.T) {
prop := func(start, end uint16) bool {
rangeInclusive := newCircularRangeInclusive(start, end)
return rangeInclusive.Contains(start)
}
if !prop(0, 65535) {
t.Error("TestContainsStart failed")
}
}
func TestContainsEnd(t *testing.T) {
prop := func(start, end uint16) bool {
rangeInclusive := newCircularRangeInclusive(start, end)
return rangeInclusive.Contains(end)
}
if !prop(0, 65535) {
t.Error("TestContainsEnd failed")
}
}
func TestIterator(t *testing.T) {
prop := func(start, end uint16) bool {
rangeInclusive := newCircularRangeInclusive(start, end)
var length int
expectedIdx := start
for {
idx, ok := rangeInclusive.Next()
if !ok {
break
}
require.Equal(t, expectedIdx, idx, "Expected %v, got %v", expectedIdx, idx)
expectedIdx += 1
length += 1
}
var expectedLen int
if start <= end {
expectedLen = int(end-start) + 1
} else {
expectedLen = int(65535-start) + int(end) + 2
}
if length != expectedLen {
t.Errorf("Expected length %v, got %v", expectedLen, length)
return false
}
return true
}
if !prop(0, 65535) {
t.Error("TestIterator failed")
}
}
func TestIteratorSingle(t *testing.T) {
prop := func(x uint16) bool {
rangeInclusive := newCircularRangeInclusive(x, x)
val, ok := rangeInclusive.Next()
if !ok || val != x {
t.Errorf("Expected %v, got %v", x, val)
return false
}
if _, ok := rangeInclusive.Next(); ok {
t.Error("Expected no more elements")
return false
}
return true
}
if !prop(0) {
t.Error("TestIteratorSingle failed")
}
}