-
-
Notifications
You must be signed in to change notification settings - Fork 95
/
range_test.go
86 lines (73 loc) · 1.14 KB
/
range_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
86
// Copyright 2018-20 PJ Engineering and Business Solutions Pty. Ltd. All rights reserved.
package dataframe
import (
"testing"
)
type tcase struct {
Start *int
End *int
ExpN int
ExpS int
ExpE int
}
func TestRange(t *testing.T) {
vals := []int{0, 1, 2, 3}
N := len(vals)
i := func(i int) *int {
return &i
}
tests := []tcase{
{
Start: nil,
End: nil,
ExpN: 4,
ExpS: 0,
ExpE: 3,
},
{
Start: i(1),
End: i(3),
ExpN: 3,
ExpS: 1,
ExpE: 3,
},
{
Start: nil,
End: i(-1),
ExpN: 4,
ExpS: 0,
ExpE: 3,
},
{
Start: nil,
End: i(-2),
ExpN: 3,
ExpS: 0,
ExpE: 2,
},
{
Start: i(-3),
End: i(-2),
ExpN: 2,
ExpS: 1,
ExpE: 2,
},
}
for i, tc := range tests {
rng := &Range{Start: tc.Start, End: tc.End}
nrows, err := rng.NRows(N)
if err != nil {
panic(err)
}
if nrows != tc.ExpN {
t.Errorf("%d: |got: %v |expected: %v", i, nrows, tc.ExpN)
}
s, e, err := rng.Limits(N)
if err != nil {
panic(err)
}
if s != tc.ExpS || e != tc.ExpE {
t.Errorf("%d: |got: %v,%v |expected: %v,%v", i, s, e, tc.ExpS, tc.ExpE)
}
}
}