-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtickers_test.go
More file actions
182 lines (140 loc) · 3.4 KB
/
Copy pathtickers_test.go
File metadata and controls
182 lines (140 loc) · 3.4 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package margaid
import (
"testing"
"time"
"github.com/erkkah/margaid/xt"
)
func TestTimeTickerStart(t *testing.T) {
x := xt.X(t)
min := SecondsFromTime(time.Date(2020, time.September, 4, 9, 10, 0, 0, time.Local))
max := SecondsFromTime(time.Date(2020, time.September, 4, 9, 11, 0, 0, time.Local))
m := New(100, 100, WithRange(
XAxis,
min,
max,
))
ticker := m.TimeTicker(time.Kitchen)
s := NewSeries()
timestamp := time.Date(2020, time.September, 4, 9, 10, 30, 0, time.Local)
s.Add(MakeValue(SecondsFromTime(timestamp), 123))
start := ticker.start(XAxis, s, 10)
// 60 secs in 10 steps leads to 6s step size
x.Equal(start, min)
}
func TestTimeTickerStep(t *testing.T) {
x := xt.X(t)
min := SecondsFromTime(time.Date(2020, time.September, 4, 9, 10, 0, 0, time.Local))
max := SecondsFromTime(time.Date(2020, time.September, 4, 9, 11, 0, 0, time.Local))
m := New(100, 100, WithRange(
XAxis,
min,
max,
))
ticker := m.TimeTicker(time.Kitchen)
s := NewSeries()
timestamp := time.Date(2020, time.September, 4, 9, 10, 30, 0, time.Local)
s.Add(MakeValue(SecondsFromTime(timestamp), 123))
step := ticker.start(XAxis, s, 10)
more := true
count := 0
for ; step <= max && more; step, more = ticker.next(step) {
count++
}
x.Equal(count, 11)
x.Assert(more)
}
func TestValueTickerStart_Lin(t *testing.T) {
x := xt.X(t)
min := 12.34
max := 56.78
m := New(100, 100, WithRange(
XAxis,
min,
max,
))
ticker := m.ValueTicker('f', 0, 10)
s := NewSeries()
s.Add(MakeValue(30, 123))
start := ticker.start(XAxis, s, 10)
x.Assert(start > min, "start > min")
x.Assert(start < max, "start < max")
}
func TestValueTickerStep_Lin(t *testing.T) {
x := xt.X(t)
min := 12.34
max := 56.78
m := New(100, 100, WithRange(
XAxis,
min,
max,
))
ticker := m.ValueTicker('f', 0, 10)
s := NewSeries()
s.Add(MakeValue(30, 123))
step := ticker.start(XAxis, s, 10)
more := true
count := 0
for ; step <= max && more; step, more = ticker.next(step) {
count++
}
// There are four marks in the range [10.0, 50.0]
x.Equal(count, 4)
x.Assert(more)
}
func TestValueTickerStart_Log(t *testing.T) {
x := xt.X(t)
min := 12.34
max := 56.78
m := New(100, 100, WithRange(
XAxis,
min,
max,
), WithProjection(XAxis, Log))
ticker := m.ValueTicker('f', 0, 10)
s := NewSeries()
s.Add(MakeValue(30, 123))
start := ticker.start(XAxis, s, 10)
x.Assert(start > min, "start > min")
x.Assert(start < max, "start < max")
}
func TestValueTickerStep_Log(t *testing.T) {
x := xt.X(t)
min := 12.34
max := 56.78
m := New(100, 100, WithRange(
XAxis,
min,
max,
), WithProjection(XAxis, Log))
ticker := m.ValueTicker('f', 0, 10)
s := NewSeries()
s.Add(MakeValue(30, 123))
step := ticker.start(XAxis, s, 10)
more := true
count := 0
for ; step <= max && more; step, more = ticker.next(step) {
count++
}
// There are 4 base 10 marks in the range [20.0, 50.0]
x.Equal(count, 4)
x.Assert(more)
}
func TestValueTickerSimpleRange(t *testing.T) {
x := xt.X(t)
s := NewSeries()
s.Add(MakeValue(1, 0))
s.Add(MakeValue(2, 0))
s.Add(MakeValue(3, 0))
max := 1.0
m := New(100, 100, WithAutorange(XAxis, s), WithAutorange(YAxis, s))
ticker := m.ValueTicker('f', 0, 10)
step := ticker.start(YAxis, s, 10)
more := true
count := 0
for ; step <= max && more; step, more = ticker.next(step) {
count++
}
// There are 5+1+5 base 10 marks in the range [-1.0, 1.0]
x.Equal(count, 11)
x.Assert(more)
}