This repository has been archived by the owner on Feb 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
TimeColumn_test.go
executable file
·91 lines (69 loc) · 2.04 KB
/
TimeColumn_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
87
88
89
90
91
package main
import (
"testing"
"math/rand"
"time"
)
var TimeRefSliceLength int = 30
// Compute a time slice with deterministically
// random offsets
func GetTimeRefSlice() []time.Time {
// Deterministic offsets
r := rand.New(rand.NewSource(91235))
// Start of time, convenient
last := time.Unix(0, 0)
result := make([]time.Time, 0)
for i := 0; i < TimeRefSliceLength; i++ {
result = append(result, last)
// Set last to be the previous last plus some number
// of hours that ensure this is strictly ascending
last = last.Add(time.Hour*time.Duration(r.Uint32()>>19) + 1)
}
return result
}
// Sanity test on TimeColumn's After
func TestTimeAfter(t *testing.T) {
ref := GetTimeRefSlice()
col := NewTimeColumn()
col.Push(ref)
// Middle item of slice
middleIndex := TimeRefSliceLength / 2
query := col.After(ref[middleIndex])
computed := query.TruthyIndices()
// We know how long the result should be
if (TimeRefSliceLength-middleIndex)-1 != len(computed) {
t.Fatalf("after has unexpected length %v != %v",
TimeRefSliceLength-middleIndex, len(computed))
}
// Check every item computed is after the middle
for _, refIndex := range computed {
if refIndex < middleIndex {
t.Fatalf("strictly increasing item in subset found as After")
}
}
}
// Sanity test on TimeColumn's ANDAfter
func TestTimeANDAfter(t *testing.T) {
ref := GetTimeRefSlice()
col := NewTimeColumn()
col.Push(ref)
// Middle item of slice
middleIndex := TimeRefSliceLength / 2
// Start from all truthy bools
query := NewBoolColumn()
query.PushTrue(len(ref))
// Filter out bad results
col.ANDAfter(ref[middleIndex], query)
computed := query.TruthyIndices()
// We know how long the result should be
if (TimeRefSliceLength-middleIndex)-1 != len(computed) {
t.Fatalf("after has unexpected length %v != %v",
TimeRefSliceLength-middleIndex, len(computed))
}
// Check every item computed is after the middle
for _, refIndex := range computed {
if refIndex < middleIndex {
t.Fatalf("strictly increasing item in subset found as After")
}
}
}