7
from chaco.scales.time_scale import tfrac, trange, \
8
TimeScale, CalendarScaleSystem
10
#----------------------------------------------------------------
12
#----------------------------------------------------------------
14
def test_tfrac_days_01():
15
# Not sure this test is useful. --WW
16
t = time.mktime(time.gmtime(0))
17
(base, frac) = tfrac(t, days=1)
21
def test_tfrac_days_02():
22
# Not sure this test is useful. --WW
23
t = time.mktime(time.gmtime(0)) + 3*24.0*3600 + 1000.0
24
(base, frac) = tfrac(t, days=1)
25
assert base == t - 1000.0
28
def test_tfrac_hours_01():
30
(base, frac) = tfrac(t, hours=1)
34
def test_tfrac_hours_02():
36
(base, frac) = tfrac(t, hours=2)
40
def test_tfrac_hours_03():
42
(base, frac) = tfrac(t, hours=2)
43
assert base == 3600 * 4
44
assert frac == 3600 * 1.5
46
def test_tfrac_hours_04():
48
(base, frac) = tfrac(t, hours=3)
49
assert base == 3600 * 3.0
50
assert frac == 3600 * 2.5
52
def test_tfrac_hours_05():
54
(base, frac) = tfrac(t, hours=6)
55
assert base == 3600 * 12.0
56
assert frac == 3600 * 3.5
58
def test_tfrac_minutes_01():
60
(base, frac) = tfrac(t, minutes=1)
64
def test_tfrac_minutes_02():
66
(base, frac) = tfrac(t, minutes=1)
70
def test_tfrac_seconds_01():
72
(base, frac) = tfrac(t, seconds=1)
76
def test_tfrac_seconds_02():
78
(base, frac) = tfrac(t, seconds=1)
82
def test_tfrac_milliseconds_01():
84
(base, frac) = tfrac(t, milliseconds=1)
88
def test_tfrac_milliseconds_02():
90
(base, frac) = tfrac(t, milliseconds=1)
94
def test_tfrac_milliseconds_03():
96
(base, frac) = tfrac(t, milliseconds=10)
100
def test_tfrac_milliseconds_04():
102
# Note that the last digit is lost due to rounding to microsecond scale.
103
(base, frac) = tfrac(t, milliseconds=1)
106
assert frac == 0.000812
108
def test_tfrac_milliseconds_05():
110
# Note that the last digit is lost due to rounding to microsecond scale.
111
(base, frac) = tfrac(t, milliseconds=1)
114
assert frac == 0.000806
117
#----------------------------------------------------------------
119
#----------------------------------------------------------------
121
def test_trange_hours_01():
122
r = trange(0, 1, hours=1)
125
def test_trange_hours_02():
126
r = trange(-1, 1, hours=1)
129
def test_trange_hours_03():
130
r = trange(0, 3600, hours=1)
131
assert r == [0.0, 3600.0]
133
def test_trange_hours_04():
134
r = trange(-3600, 3600, hours=1)
135
assert r == [-3600.0, 0.0, 3600.0]
137
def test_trange_hours_05():
138
r = trange(-10, 3610, hours=1)
139
assert r == [0.0, 3600.0]
141
def test_trange_hours_06():
142
r = trange(-10, 7210, hours=1)
143
assert r == [0.0, 3600.0, 7200.0]
145
def test_trange_hours_07():
146
r = trange(-10, 7210, hours=2)
147
assert r == [0.0, 7200.0]
149
def test_trange_seconds_01():
150
r = trange(0, 1, seconds=1)
151
assert r == [0.0, 1.0]
153
def test_trange_seconds_02():
154
r = trange(0, 10, seconds=1)
155
assert r == range(11)
157
def test_trange_seconds_03():
158
r = trange(0, 1.5, seconds=1)
159
assert r == [0.0, 1.0]
161
def test_trange_milliseconds_01():
162
r = trange(0, 0.1, milliseconds=1)
163
assert np.allclose(np.array(r), np.linspace(0.0, 0.1, 101)).all()
165
def test_trange_milliseconds_02():
166
r = trange(-0.002, 0.001, milliseconds=1)
167
assert np.allclose(np.array(r), np.linspace(-0.002, 0.001, 4))
170
#----------------------------------------------------------------
172
#----------------------------------------------------------------
174
# Could use more tests here... --WW
176
def test_time_scale_seconds_01():
177
ts = TimeScale(seconds=1)
178
ticks = ts.ticks(0, 10)
179
assert (np.array(ticks) == np.linspace(0.0, 10.0, 11)).all()
181
def test_time_scale_seconds_02():
182
ts = TimeScale(seconds=2)
183
ticks = ts.ticks(0, 10)
184
assert (np.array(ticks) == np.linspace(0.0, 10.0, 6)).all()
186
def test_time_scale_milliseconds_01():
187
ts = TimeScale(milliseconds=1)
188
ticks = ts.ticks(0, 0.1)
189
assert len(ticks) == 11
190
assert (np.array(ticks) == np.linspace(0.0, 0.1, 11)).all()
192
#----------------------------------------------------------------
193
# CalendarScaleSystem tests
194
#----------------------------------------------------------------
196
def test_calendar_scale_system_01():
197
css = CalendarScaleSystem()
198
ticks = css.ticks(0,10)
199
assert len(ticks) == 11
200
assert (np.array(ticks) == np.linspace(0,10,11)).all()
203
# TODO: Add more tests of the ticks() and labels() methods of
204
# the CalendarScaleSystem.
206
# Determine why the format switches from '##s' to ':##'
207
# as in the following, and create appropriate tests:
209
# In [145]: css.labels(71010,71021, numlabels=8, char_width=130)
224
# In [146]: css.labels(71010,71022, numlabels=8, char_width=130)