-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathkeys_test.go
55 lines (51 loc) · 1.07 KB
/
keys_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
package sortedmap
import (
"testing"
"time"
)
func TestKeys(t *testing.T) {
sm, _, err := newSortedMapFromRandRecords(300)
if err != nil {
t.Fatal(err)
}
i := 0
keys := sm.Keys()
for _, key := range keys {
if key == nil {
t.Fatal("Key's value is nil.")
}
i++
}
if i == 0 {
t.Fatal("The returned slice was empty.")
}
}
func TestBoundedKeys(t *testing.T) {
sm, _, err := newSortedMapFromRandRecords(300)
if err != nil {
t.Fatal(err)
}
i := 0
keys, err := sm.BoundedKeys(time.Time{}, time.Now())
if err != nil {
t.Fatal(err)
}
for _, key := range keys {
if key == nil {
t.Fatal("Key's value is nil.")
}
i++
}
if i == 0 {
t.Fatal("The returned slice was empty.")
}
}
func TestBoundedKeysWithNoBoundsReturned(t *testing.T) {
sm, _, err := newSortedMapFromRandRecords(300)
if err != nil {
t.Fatal(err)
}
if val, err := sm.BoundedKeys(time.Date(5783, 1, 1, 0, 0, 0, 0, time.UTC), time.Now()); err == nil {
t.Fatalf("Values fall between or are equal to the given bounds when it should not have returned bounds: %+v", sm.idx[val[0]])
}
}