when_exe 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -23
- data/lib/when_exe/ephemeris/moon.rb +333 -333
- data/lib/when_exe/linkeddata.rb +0 -1
- data/lib/when_exe/locales/encoding_conversion.rb +134 -134
- data/lib/when_exe/locales/iast.rb +90 -90
- data/lib/when_exe/locales/transliteration_table.rb +62 -62
- data/lib/when_exe/parts/method_cash.rb +224 -224
- data/lib/when_exe/region/chinese/calendars.rb +1016 -1016
- data/lib/when_exe/region/geologicalage.rb +1 -1
- data/lib/when_exe/region/japanese/calendars.rb +397 -397
- data/lib/when_exe/region/japanese/eclipses.rb +1194 -1194
- data/lib/when_exe/region/japanese/nihon_shoki.rb +70 -70
- data/lib/when_exe/region/korean.rb +384 -384
- data/lib/when_exe/region/ryukyu.rb +101 -101
- data/lib/when_exe/tmposition.rb +2 -2
- data/lib/when_exe/tmreference.rb +3 -3
- data/lib/when_exe/version.rb +1 -1
- data/test/scripts/geometric_complex.rb +41 -41
- data/test/scripts/korea.rb +59 -59
- data/test/scripts/thai.rb +36 -36
- data/test/test/basictypes.rb +431 -431
- data/test/test/calendarnote.rb +86 -86
- data/test/test/calendartypes.rb +97 -97
- data/test/test/coordinates.rb +397 -397
- data/test/test/ephemeris.rb +115 -115
- data/test/test/ephemeris/moon.rb +14 -14
- data/test/test/ephemeris/planets.rb +14 -14
- data/test/test/ephemeris/sun.rb +14 -14
- data/test/test/inspect.rb +153 -153
- data/test/test/parts.rb +488 -488
- data/test/test/region/armenian.rb +20 -20
- data/test/test/region/bahai.rb +58 -58
- data/test/test/region/balinese.rb +34 -34
- data/test/test/region/chinese.rb +229 -229
- data/test/test/region/christian.rb +226 -226
- data/test/test/region/coptic.rb +27 -27
- data/test/test/region/discordian.rb +20 -20
- data/test/test/region/french.rb +33 -33
- data/test/test/region/geologicalage.rb +17 -17
- data/test/test/region/iran.rb +54 -54
- data/test/test/region/islamic.rb +54 -54
- data/test/test/region/japanese.rb +261 -261
- data/test/test/region/jewish.rb +63 -63
- data/test/test/region/shire.rb +58 -58
- data/test/test/region/swedish.rb +45 -45
- data/test/test/region/thai.rb +116 -116
- data/test/test/region/tibetan.rb +30 -30
- data/test/test/region/vietnamese.rb +102 -102
- data/test/test/region/zoroastrian.rb +58 -58
- data/test/test/timestandard.rb +81 -81
- data/test/test/tmobjects.rb +402 -402
- data/test/test/tmreference.rb +157 -157
- metadata +4 -88
data/test/test/tmobjects.rb
CHANGED
@@ -1,402 +1,402 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
=begin
|
3
|
-
Copyright (C) 2011-2013 Takashi SUGA
|
4
|
-
|
5
|
-
You may use and/or modify this file according to the license
|
6
|
-
described in the LICENSE.txt file included in this archive.
|
7
|
-
=end
|
8
|
-
|
9
|
-
module MiniTest::TM
|
10
|
-
|
11
|
-
#
|
12
|
-
# (5.2) Temporal Objects Package
|
13
|
-
#
|
14
|
-
#
|
15
|
-
|
16
|
-
class Separation < MiniTest::TestCase
|
17
|
-
def test_nothing
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class Order < MiniTest::TestCase
|
22
|
-
def test_nothing
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class RelativePosition < MiniTest::TestCase
|
27
|
-
def test_nothing
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class Object < MiniTest::TestCase
|
32
|
-
def test_nothing
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
class Complex < MiniTest::TestCase
|
37
|
-
def test_nothing
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
class TopologicalComplex < MiniTest::TestCase
|
42
|
-
def test_nothing
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
class Primitive < MiniTest::TestCase
|
47
|
-
def test_nothing
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class GeometricPrimitive < MiniTest::TestCase
|
52
|
-
def test_nothing
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
class Instant < MiniTest::TestCase
|
57
|
-
|
58
|
-
include When::TM::RelativePosition
|
59
|
-
|
60
|
-
def test__distance
|
61
|
-
position = []
|
62
|
-
instant = []
|
63
|
-
When.when?('20110201/06').each do |sample|
|
64
|
-
position << When.when?(sample)
|
65
|
-
instant << When::TM::Instant.new(position[-1])
|
66
|
-
end
|
67
|
-
period_0202_0204 = When::TM::Period.new(instant[1], instant[3])
|
68
|
-
|
69
|
-
sample = ['P2D', 'P1D', 'P0D', 'P1D', 'P2D', 'P3D']
|
70
|
-
instant.each do |i|
|
71
|
-
assert_equal(sample.shift, i.distance(instant[2]).to_s)
|
72
|
-
end
|
73
|
-
|
74
|
-
sample = ['P1D', 'P0D', 'P0D', 'P0D', 'P1D', 'P2D']
|
75
|
-
instant.each do |i|
|
76
|
-
assert_equal(sample.shift, i.distance(period_0202_0204).to_s)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def test__relative_position
|
81
|
-
position = []
|
82
|
-
instant = []
|
83
|
-
When.when?('20110201/06').each do |sample|
|
84
|
-
position << When.when?(sample)
|
85
|
-
instant << When::TM::Instant.new(position[-1])
|
86
|
-
end
|
87
|
-
period_0202_0204 = When::TM::Period.new(instant[1], instant[3])
|
88
|
-
|
89
|
-
sample = [Before, Before, Equals, After, After, After]
|
90
|
-
instant.each do |i|
|
91
|
-
assert_equal(sample.shift, i.relative_position(instant[2]))
|
92
|
-
end
|
93
|
-
|
94
|
-
sample = [Before, Begins, During, Ends, After, After]
|
95
|
-
instant.each do |i|
|
96
|
-
assert_equal(sample.shift, i.relative_position(period_0202_0204))
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
class Period < MiniTest::TestCase
|
102
|
-
|
103
|
-
include When::TM::RelativePosition
|
104
|
-
|
105
|
-
def test__distance
|
106
|
-
position = []
|
107
|
-
instant = []
|
108
|
-
When.when?('20110201/06').each do |sample|
|
109
|
-
position << When.when?(sample)
|
110
|
-
instant << When::TM::Instant.new(position[-1])
|
111
|
-
end
|
112
|
-
assert_equal(["2011-02-01", "2011-02-02", "2011-02-03",
|
113
|
-
"2011-02-04", "2011-02-05", "2011-02-06"],
|
114
|
-
position.map {|v| v.to_s})
|
115
|
-
|
116
|
-
period_0201_0202 = When::TM::Period.new(instant[0], instant[1])
|
117
|
-
period_0202_0203 = When::TM::Period.new(instant[1], instant[2])
|
118
|
-
period_0203_0204 = When::TM::Period.new(instant[2], instant[3])
|
119
|
-
period_0204_0205 = When::TM::Period.new(instant[3], instant[4])
|
120
|
-
period_0205_0206 = When::TM::Period.new(instant[4], instant[5])
|
121
|
-
|
122
|
-
period_0202_0204 = When::TM::Period.new(instant[1], instant[3])
|
123
|
-
period_0204_0206 = When::TM::Period.new(instant[3], instant[5])
|
124
|
-
period_0203_0206 = When::TM::Period.new(instant[2], instant[5])
|
125
|
-
period_0201_0206 = When::TM::Period.new(instant[0], instant[5])
|
126
|
-
|
127
|
-
extent_0201_0202 = When::EX::Extent.new(period_0201_0202)
|
128
|
-
extent_0202_0203 = When::EX::Extent.new(period_0202_0203)
|
129
|
-
extent_0203_0204 = When::EX::Extent.new(period_0203_0204)
|
130
|
-
extent_0204_0205 = When::EX::Extent.new(period_0204_0205)
|
131
|
-
extent_0205_0206 = When::EX::Extent.new(period_0205_0206)
|
132
|
-
|
133
|
-
extent_0202_0204 = When::EX::Extent.new(period_0202_0204)
|
134
|
-
extent_0204_0206 = When::EX::Extent.new(period_0204_0206)
|
135
|
-
extent_0203_0206 = When::EX::Extent.new(period_0203_0206)
|
136
|
-
extent_0201_0206 = When::EX::Extent.new(period_0201_0206)
|
137
|
-
|
138
|
-
sample = ['P1D', 'P0D', 'P0D', 'P0D', 'P1D', 'P2D']
|
139
|
-
instant.each do |i|
|
140
|
-
assert_equal(sample.shift, period_0202_0204.distance(i).to_s)
|
141
|
-
end
|
142
|
-
|
143
|
-
[['P2D', period_0201_0202, period_0204_0206],
|
144
|
-
['P0D', period_0201_0202, period_0202_0204],
|
145
|
-
['P0D', period_0202_0203, period_0202_0204],
|
146
|
-
['P0D', period_0203_0204, period_0202_0204],
|
147
|
-
['P0D', period_0204_0205, period_0202_0204],
|
148
|
-
['P0D', period_0203_0206, period_0202_0204],
|
149
|
-
['P1D', period_0205_0206, period_0202_0204]].each do |sample|
|
150
|
-
assert_equal(sample[0], sample[1].distance(sample[2]).to_s)
|
151
|
-
assert_equal(sample[0], sample[2].distance(sample[1]).to_s)
|
152
|
-
end
|
153
|
-
|
154
|
-
sample = ['P1D', 'P0D', 'P0D', 'P0D', 'P1D', 'P2D']
|
155
|
-
instant.each do |i|
|
156
|
-
assert_equal(sample.shift, extent_0202_0204.distance(i).to_s)
|
157
|
-
end
|
158
|
-
|
159
|
-
[['P2D', extent_0201_0202, extent_0204_0206],
|
160
|
-
['P0D', extent_0201_0202, extent_0202_0204],
|
161
|
-
['P0D', extent_0202_0203, extent_0202_0204],
|
162
|
-
['P0D', extent_0203_0204, extent_0202_0204],
|
163
|
-
['P0D', extent_0204_0205, extent_0202_0204],
|
164
|
-
['P0D', extent_0203_0206, extent_0202_0204],
|
165
|
-
['P1D', extent_0205_0206, extent_0202_0204]].each do |sample|
|
166
|
-
assert_equal(sample[0], sample[1].distance(sample[2]).to_s)
|
167
|
-
assert_equal(sample[0], sample[2].distance(sample[1]).to_s)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
def test__relative_position
|
172
|
-
position = []
|
173
|
-
instant = []
|
174
|
-
When.when?('20110201/06').each do |sample|
|
175
|
-
position << When.when?(sample)
|
176
|
-
instant << When::TM::Instant.new(position[-1])
|
177
|
-
end
|
178
|
-
period_0201_0202 = When::TM::Period.new(instant[0], instant[1])
|
179
|
-
period_0202_0203 = When::TM::Period.new(instant[1], instant[2])
|
180
|
-
period_0203_0204 = When::TM::Period.new(instant[2], instant[3])
|
181
|
-
period_0204_0205 = When::TM::Period.new(instant[3], instant[4])
|
182
|
-
period_0205_0206 = When::TM::Period.new(instant[4], instant[5])
|
183
|
-
|
184
|
-
period_0202_0204 = When::TM::Period.new(instant[1], instant[3])
|
185
|
-
period_0203_0206 = When::TM::Period.new(instant[2], instant[5])
|
186
|
-
period_0204_0206 = When::TM::Period.new(instant[3], instant[5])
|
187
|
-
period_0201_0206 = When::TM::Period.new(instant[0], instant[5])
|
188
|
-
|
189
|
-
sample = [After, BegunBy, Contains, EndedBy, Before, Before]
|
190
|
-
instant.each do |i|
|
191
|
-
assert_equal(sample.shift, period_0202_0204.relative_position(i))
|
192
|
-
end
|
193
|
-
|
194
|
-
[[Before, period_0201_0202, period_0204_0206],
|
195
|
-
[Meets, period_0201_0202, period_0202_0204],
|
196
|
-
[Overlaps, period_0202_0204, period_0203_0206],
|
197
|
-
[Begins, period_0202_0203, period_0202_0204],
|
198
|
-
[BegunBy, period_0202_0204, period_0202_0203],
|
199
|
-
|
200
|
-
[During, period_0202_0204, period_0201_0206],
|
201
|
-
[Contains, period_0201_0206, period_0202_0204],
|
202
|
-
[Equals, period_0202_0204, period_0202_0204],
|
203
|
-
|
204
|
-
[OverlappedBy, period_0203_0206, period_0202_0204],
|
205
|
-
[Ends, period_0203_0204, period_0202_0204],
|
206
|
-
[EndedBy, period_0202_0204, period_0203_0204],
|
207
|
-
[MetBy, period_0204_0205, period_0202_0204],
|
208
|
-
[After, period_0205_0206, period_0202_0204]].each do |sample|
|
209
|
-
assert_equal(sample[0], sample[1].relative_position(sample[2]))
|
210
|
-
end
|
211
|
-
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
class TopologicalPrimitive < MiniTest::TestCase
|
216
|
-
def test_nothing
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
class Node < MiniTest::TestCase
|
221
|
-
def test_nothing
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
class Edge < MiniTest::TestCase
|
226
|
-
def test_nothing
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
class Duration < MiniTest::TestCase
|
231
|
-
def test__duration_constructors
|
232
|
-
assert_equal( 1, When::TM::Duration.new(1).duration)
|
233
|
-
assert_equal( 1.0/128, When::TM::Duration.second(1).duration)
|
234
|
-
assert_equal( 60.0/128, When::TM::Duration.minute(1).duration)
|
235
|
-
assert_equal( 3600.0/128, When::TM::Duration.hour(1).duration)
|
236
|
-
assert_equal(86400.0/128, When::TM::Duration.day(1).duration)
|
237
|
-
assert_equal(93784.0/128, When::TM::Duration.dhms(1,2,3,4).duration)
|
238
|
-
end
|
239
|
-
|
240
|
-
def test__duration_values
|
241
|
-
assert_equal(1, When::TM::Duration.new(1).system)
|
242
|
-
assert_equal(2, When::TM::Duration.second(2).second)
|
243
|
-
assert_equal(3, When::TM::Duration.minute(3).minute)
|
244
|
-
assert_equal(4, When::TM::Duration.hour(4).hour)
|
245
|
-
assert_equal(5, When::TM::Duration.day(5).day)
|
246
|
-
assert_equal([1,2,3,4], When::TM::Duration.dhms(1,2,3,4).to_dhms)
|
247
|
-
assert_equal([-2,21,56,56], (-When::TM::Duration.dhms(1,2,3,4)).to_dhms)
|
248
|
-
end
|
249
|
-
|
250
|
-
def test__duration_elements
|
251
|
-
duration = When::TM::Duration.dhms(1,2,3,4.5)
|
252
|
-
assert_equal(1, duration[0])
|
253
|
-
assert_equal(2, duration[1])
|
254
|
-
assert_equal(3, duration[2])
|
255
|
-
assert_equal(4.5, duration[3])
|
256
|
-
end
|
257
|
-
|
258
|
-
def test__duration_arithmetics
|
259
|
-
assert_equal(When::TM::Duration.dhms(-2,21,56,56), -When::TM::Duration.dhms(1,2,3,4))
|
260
|
-
assert_equal(When::TM::Duration.dhms(2,3,4,5), When::TM::Duration.dhms(1,2,3,4) + When::TM::Duration.dhms(1,1,1,1))
|
261
|
-
assert_equal(When::TM::Duration.dhms(0,1,2,3), When::TM::Duration.dhms(1,2,3,4) - When::TM::Duration.dhms(1,1,1,1))
|
262
|
-
assert_equal(When::TM::Duration.dhms(2,4,6,8), When::TM::Duration.dhms(1,2,3,4) * 2)
|
263
|
-
assert_equal(When::TM::Duration.dhms(1,2,3,4), When::TM::Duration.dhms(2,4,6,8) / 2)
|
264
|
-
assert_equal(2, When::TM::Duration.dhms(2,4,6,8) / When::TM::Duration.dhms(1,2,3,4))
|
265
|
-
end
|
266
|
-
|
267
|
-
def test__duration_and_time
|
268
|
-
start = Time.now
|
269
|
-
duration = When::TM::Duration.dhms(1,2,3,4.25)
|
270
|
-
stop = start + duration
|
271
|
-
assert_equal((RUBY_VERSION.to_f<1.9 ? 93784.25 : 93784), stop-start)
|
272
|
-
assert_raises(TypeError) {
|
273
|
-
::Date.today + duration
|
274
|
-
}
|
275
|
-
require 'when_exe/core/duration'
|
276
|
-
stop = start + duration
|
277
|
-
assert_equal(93784.25, stop-start)
|
278
|
-
|
279
|
-
now_date = DateTime.now
|
280
|
-
duration = When::TM::Duration.hour(8)
|
281
|
-
assert_equal(Rational(1,128), (now_date + duration * 3 / 128 ) - now_date)
|
282
|
-
assert_equal(Rational(1,3), (now_date + duration ) - now_date)
|
283
|
-
assert_equal(Rational(1,1), (now_date + duration * 3) - now_date)
|
284
|
-
|
285
|
-
stop = start + When.Duration('P1DT2H3M4S')
|
286
|
-
assert_equal(93784, stop-start)
|
287
|
-
|
288
|
-
assert_raises(TypeError) {
|
289
|
-
stop = start + When.Duration('P2M1DT2H3M4S')
|
290
|
-
}
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
class PeriodDuration < MiniTest::TestCase
|
295
|
-
def test__period_duration
|
296
|
-
period = When.Duration('P2Y3M4D')
|
297
|
-
[[-2, 2], [-1, 3], [0, 4]].each do |sample|
|
298
|
-
assert_equal(sample[1], period[sample[0]])
|
299
|
-
end
|
300
|
-
period = When.Duration('PT5H6M7S')
|
301
|
-
[[1, 5], [2, 6], [3, 7]].each do |sample|
|
302
|
-
assert_equal(sample[1], period[sample[0]])
|
303
|
-
end
|
304
|
-
period = When.Duration('P2Y3M4DT5H6M7S')
|
305
|
-
[[-2, 2], [-1, 3], [0, 4], [1, 5], [2, 6], [3, 7]].each do |sample|
|
306
|
-
assert_equal(sample[1], period[sample[0]])
|
307
|
-
end
|
308
|
-
period = When.Duration('P8W9D')
|
309
|
-
[[-0.5, 8], [0, 8*7+9]].each do |sample|
|
310
|
-
assert_equal(sample[1], period[sample[0]])
|
311
|
-
end
|
312
|
-
end
|
313
|
-
|
314
|
-
def test__period_duration_diff
|
315
|
-
date1 = When.when?('2012-07-01')
|
316
|
-
date2 = When.when?('2012-07-02')
|
317
|
-
duration = date2 - date1
|
318
|
-
assert_equal('P1D', duration.to_s)
|
319
|
-
assert_equal(When::TM::PeriodDuration, duration.class)
|
320
|
-
|
321
|
-
if Object.const_defined?(:TZInfo)
|
322
|
-
time = When.when?('2013-03-10T01:00:00', :tz=>'America/New_York')
|
323
|
-
assert_equal('2013-03-10T02:30:00-04:00', (time + When.Duration('PT1.5H')).to_s) # ��ʂ�1.5����
|
324
|
-
else
|
325
|
-
puts
|
326
|
-
puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
|
327
|
-
end
|
328
|
-
|
329
|
-
vcal = When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
|
330
|
-
time = When.when?('2013-03-10T01:00:00', :clock=>vcal['America/New_York'])
|
331
|
-
assert_equal('2013-03-10T02:30:00-04:00', (time + When.Duration('PT1.5H')).to_s) # ��ʂ�1.5����
|
332
|
-
end
|
333
|
-
|
334
|
-
Sample10 = %w(2013-01-31 2013-02-28 2013-03-31 2013-04-30 2013-05-31
|
335
|
-
2013-06-30 2013-07-31 2013-08-31 2013-09-30 2013-10-31)
|
336
|
-
|
337
|
-
Sample12 = %w(2013-01-31 2013-02-28 2013-03-31 2013-04-30 2013-05-31 2013-06-30
|
338
|
-
2013-07-31 2013-08-31 2013-09-30 2013-10-31 2013-11-30 2013-12-31)
|
339
|
-
|
340
|
-
def test__duration_each
|
341
|
-
sample = Sample10.dup
|
342
|
-
When::P1M.enum_for(When.when?('2013-01-31'), :forward, 10).each do |date|
|
343
|
-
assert_equal(sample.shift, date.to_s)
|
344
|
-
end
|
345
|
-
|
346
|
-
count = 0
|
347
|
-
(When.when?('2013-01-31') ^ When::P1M).each({:count_limit=>0}) do |date|
|
348
|
-
count += 1
|
349
|
-
end
|
350
|
-
assert_equal(0, count)
|
351
|
-
|
352
|
-
sample = Sample10.dup
|
353
|
-
(When.when?('2013-01-31') ^ When::P1M).each({:count_limit=>10}) do |date|
|
354
|
-
assert_equal(sample.shift, date.to_s)
|
355
|
-
end
|
356
|
-
|
357
|
-
sample = Sample12.dup
|
358
|
-
(When.when?('2013-01-31') ^ When::P1M).each({:until=>When.when?('2013-12-31')}) do |date|
|
359
|
-
assert_equal(sample.shift, date.to_s)
|
360
|
-
end
|
361
|
-
|
362
|
-
sample = Sample12.reverse
|
363
|
-
(When.when?('2013-12-31') ^ -When::P1M).each({:until=>When.when?('2013-01-31')}) do |date|
|
364
|
-
assert_equal(sample.shift, date.to_s)
|
365
|
-
end
|
366
|
-
end
|
367
|
-
end
|
368
|
-
|
369
|
-
class IntervalLength < MiniTest::TestCase
|
370
|
-
def test__interval_length
|
371
|
-
[
|
372
|
-
['7E-3s', 7, 3, 10, 'second', '7E-3s' ],
|
373
|
-
['8X-2m', 8, 2, 60, 'minute', '8X-2m' ],
|
374
|
-
['6(12)7D', 6, -7, 12, 'day', '6(12)+7D' ],
|
375
|
-
['1(16)4*10S', 1, -4, 16, '10', '1(16)+4*10S']
|
376
|
-
].each do |sample|
|
377
|
-
interval = When.Duration(sample[0])
|
378
|
-
assert_equal(sample[1..5], [interval.value, interval.factor, interval.radix, interval.unit, interval.to_s])
|
379
|
-
end
|
380
|
-
end
|
381
|
-
|
382
|
-
def test__interval_length_diff
|
383
|
-
time1 = When.when?('2012-07-01T01:23:45+09:00')
|
384
|
-
time2 = When.when?('2012-07-02T01:23:45+09:00')
|
385
|
-
duration = time2 - time1
|
386
|
-
assert_equal('86401.0s', duration.to_s)
|
387
|
-
assert_equal(When::TM::IntervalLength, duration.class)
|
388
|
-
|
389
|
-
if Object.const_defined?(:TZInfo)
|
390
|
-
time = When.when?('2013-03-10T01:00:00', :tz=>'America/New_York')
|
391
|
-
assert_equal('2013-03-10T03:30:00-04:00', (time + When.Duration('1.5h')).to_s) # �����I��1.5����
|
392
|
-
else
|
393
|
-
puts
|
394
|
-
puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
|
395
|
-
end
|
396
|
-
|
397
|
-
vcal = When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
|
398
|
-
time = When.when?('2013-03-10T01:00:00', :clock=>vcal['America/New_York'])
|
399
|
-
assert_equal('2013-03-10T03:30:00-04:00', (time + When.Duration('1.5h')).to_s) # �����I��1.5����
|
400
|
-
end
|
401
|
-
end
|
402
|
-
end
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
=begin
|
3
|
+
Copyright (C) 2011-2013 Takashi SUGA
|
4
|
+
|
5
|
+
You may use and/or modify this file according to the license
|
6
|
+
described in the LICENSE.txt file included in this archive.
|
7
|
+
=end
|
8
|
+
|
9
|
+
module MiniTest::TM
|
10
|
+
|
11
|
+
#
|
12
|
+
# (5.2) Temporal Objects Package
|
13
|
+
#
|
14
|
+
#
|
15
|
+
|
16
|
+
class Separation < MiniTest::TestCase
|
17
|
+
def test_nothing
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Order < MiniTest::TestCase
|
22
|
+
def test_nothing
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class RelativePosition < MiniTest::TestCase
|
27
|
+
def test_nothing
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Object < MiniTest::TestCase
|
32
|
+
def test_nothing
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Complex < MiniTest::TestCase
|
37
|
+
def test_nothing
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class TopologicalComplex < MiniTest::TestCase
|
42
|
+
def test_nothing
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class Primitive < MiniTest::TestCase
|
47
|
+
def test_nothing
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class GeometricPrimitive < MiniTest::TestCase
|
52
|
+
def test_nothing
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class Instant < MiniTest::TestCase
|
57
|
+
|
58
|
+
include When::TM::RelativePosition
|
59
|
+
|
60
|
+
def test__distance
|
61
|
+
position = []
|
62
|
+
instant = []
|
63
|
+
When.when?('20110201/06').each do |sample|
|
64
|
+
position << When.when?(sample)
|
65
|
+
instant << When::TM::Instant.new(position[-1])
|
66
|
+
end
|
67
|
+
period_0202_0204 = When::TM::Period.new(instant[1], instant[3])
|
68
|
+
|
69
|
+
sample = ['P2D', 'P1D', 'P0D', 'P1D', 'P2D', 'P3D']
|
70
|
+
instant.each do |i|
|
71
|
+
assert_equal(sample.shift, i.distance(instant[2]).to_s)
|
72
|
+
end
|
73
|
+
|
74
|
+
sample = ['P1D', 'P0D', 'P0D', 'P0D', 'P1D', 'P2D']
|
75
|
+
instant.each do |i|
|
76
|
+
assert_equal(sample.shift, i.distance(period_0202_0204).to_s)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def test__relative_position
|
81
|
+
position = []
|
82
|
+
instant = []
|
83
|
+
When.when?('20110201/06').each do |sample|
|
84
|
+
position << When.when?(sample)
|
85
|
+
instant << When::TM::Instant.new(position[-1])
|
86
|
+
end
|
87
|
+
period_0202_0204 = When::TM::Period.new(instant[1], instant[3])
|
88
|
+
|
89
|
+
sample = [Before, Before, Equals, After, After, After]
|
90
|
+
instant.each do |i|
|
91
|
+
assert_equal(sample.shift, i.relative_position(instant[2]))
|
92
|
+
end
|
93
|
+
|
94
|
+
sample = [Before, Begins, During, Ends, After, After]
|
95
|
+
instant.each do |i|
|
96
|
+
assert_equal(sample.shift, i.relative_position(period_0202_0204))
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class Period < MiniTest::TestCase
|
102
|
+
|
103
|
+
include When::TM::RelativePosition
|
104
|
+
|
105
|
+
def test__distance
|
106
|
+
position = []
|
107
|
+
instant = []
|
108
|
+
When.when?('20110201/06').each do |sample|
|
109
|
+
position << When.when?(sample)
|
110
|
+
instant << When::TM::Instant.new(position[-1])
|
111
|
+
end
|
112
|
+
assert_equal(["2011-02-01", "2011-02-02", "2011-02-03",
|
113
|
+
"2011-02-04", "2011-02-05", "2011-02-06"],
|
114
|
+
position.map {|v| v.to_s})
|
115
|
+
|
116
|
+
period_0201_0202 = When::TM::Period.new(instant[0], instant[1])
|
117
|
+
period_0202_0203 = When::TM::Period.new(instant[1], instant[2])
|
118
|
+
period_0203_0204 = When::TM::Period.new(instant[2], instant[3])
|
119
|
+
period_0204_0205 = When::TM::Period.new(instant[3], instant[4])
|
120
|
+
period_0205_0206 = When::TM::Period.new(instant[4], instant[5])
|
121
|
+
|
122
|
+
period_0202_0204 = When::TM::Period.new(instant[1], instant[3])
|
123
|
+
period_0204_0206 = When::TM::Period.new(instant[3], instant[5])
|
124
|
+
period_0203_0206 = When::TM::Period.new(instant[2], instant[5])
|
125
|
+
period_0201_0206 = When::TM::Period.new(instant[0], instant[5])
|
126
|
+
|
127
|
+
extent_0201_0202 = When::EX::Extent.new(period_0201_0202)
|
128
|
+
extent_0202_0203 = When::EX::Extent.new(period_0202_0203)
|
129
|
+
extent_0203_0204 = When::EX::Extent.new(period_0203_0204)
|
130
|
+
extent_0204_0205 = When::EX::Extent.new(period_0204_0205)
|
131
|
+
extent_0205_0206 = When::EX::Extent.new(period_0205_0206)
|
132
|
+
|
133
|
+
extent_0202_0204 = When::EX::Extent.new(period_0202_0204)
|
134
|
+
extent_0204_0206 = When::EX::Extent.new(period_0204_0206)
|
135
|
+
extent_0203_0206 = When::EX::Extent.new(period_0203_0206)
|
136
|
+
extent_0201_0206 = When::EX::Extent.new(period_0201_0206)
|
137
|
+
|
138
|
+
sample = ['P1D', 'P0D', 'P0D', 'P0D', 'P1D', 'P2D']
|
139
|
+
instant.each do |i|
|
140
|
+
assert_equal(sample.shift, period_0202_0204.distance(i).to_s)
|
141
|
+
end
|
142
|
+
|
143
|
+
[['P2D', period_0201_0202, period_0204_0206],
|
144
|
+
['P0D', period_0201_0202, period_0202_0204],
|
145
|
+
['P0D', period_0202_0203, period_0202_0204],
|
146
|
+
['P0D', period_0203_0204, period_0202_0204],
|
147
|
+
['P0D', period_0204_0205, period_0202_0204],
|
148
|
+
['P0D', period_0203_0206, period_0202_0204],
|
149
|
+
['P1D', period_0205_0206, period_0202_0204]].each do |sample|
|
150
|
+
assert_equal(sample[0], sample[1].distance(sample[2]).to_s)
|
151
|
+
assert_equal(sample[0], sample[2].distance(sample[1]).to_s)
|
152
|
+
end
|
153
|
+
|
154
|
+
sample = ['P1D', 'P0D', 'P0D', 'P0D', 'P1D', 'P2D']
|
155
|
+
instant.each do |i|
|
156
|
+
assert_equal(sample.shift, extent_0202_0204.distance(i).to_s)
|
157
|
+
end
|
158
|
+
|
159
|
+
[['P2D', extent_0201_0202, extent_0204_0206],
|
160
|
+
['P0D', extent_0201_0202, extent_0202_0204],
|
161
|
+
['P0D', extent_0202_0203, extent_0202_0204],
|
162
|
+
['P0D', extent_0203_0204, extent_0202_0204],
|
163
|
+
['P0D', extent_0204_0205, extent_0202_0204],
|
164
|
+
['P0D', extent_0203_0206, extent_0202_0204],
|
165
|
+
['P1D', extent_0205_0206, extent_0202_0204]].each do |sample|
|
166
|
+
assert_equal(sample[0], sample[1].distance(sample[2]).to_s)
|
167
|
+
assert_equal(sample[0], sample[2].distance(sample[1]).to_s)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def test__relative_position
|
172
|
+
position = []
|
173
|
+
instant = []
|
174
|
+
When.when?('20110201/06').each do |sample|
|
175
|
+
position << When.when?(sample)
|
176
|
+
instant << When::TM::Instant.new(position[-1])
|
177
|
+
end
|
178
|
+
period_0201_0202 = When::TM::Period.new(instant[0], instant[1])
|
179
|
+
period_0202_0203 = When::TM::Period.new(instant[1], instant[2])
|
180
|
+
period_0203_0204 = When::TM::Period.new(instant[2], instant[3])
|
181
|
+
period_0204_0205 = When::TM::Period.new(instant[3], instant[4])
|
182
|
+
period_0205_0206 = When::TM::Period.new(instant[4], instant[5])
|
183
|
+
|
184
|
+
period_0202_0204 = When::TM::Period.new(instant[1], instant[3])
|
185
|
+
period_0203_0206 = When::TM::Period.new(instant[2], instant[5])
|
186
|
+
period_0204_0206 = When::TM::Period.new(instant[3], instant[5])
|
187
|
+
period_0201_0206 = When::TM::Period.new(instant[0], instant[5])
|
188
|
+
|
189
|
+
sample = [After, BegunBy, Contains, EndedBy, Before, Before]
|
190
|
+
instant.each do |i|
|
191
|
+
assert_equal(sample.shift, period_0202_0204.relative_position(i))
|
192
|
+
end
|
193
|
+
|
194
|
+
[[Before, period_0201_0202, period_0204_0206],
|
195
|
+
[Meets, period_0201_0202, period_0202_0204],
|
196
|
+
[Overlaps, period_0202_0204, period_0203_0206],
|
197
|
+
[Begins, period_0202_0203, period_0202_0204],
|
198
|
+
[BegunBy, period_0202_0204, period_0202_0203],
|
199
|
+
|
200
|
+
[During, period_0202_0204, period_0201_0206],
|
201
|
+
[Contains, period_0201_0206, period_0202_0204],
|
202
|
+
[Equals, period_0202_0204, period_0202_0204],
|
203
|
+
|
204
|
+
[OverlappedBy, period_0203_0206, period_0202_0204],
|
205
|
+
[Ends, period_0203_0204, period_0202_0204],
|
206
|
+
[EndedBy, period_0202_0204, period_0203_0204],
|
207
|
+
[MetBy, period_0204_0205, period_0202_0204],
|
208
|
+
[After, period_0205_0206, period_0202_0204]].each do |sample|
|
209
|
+
assert_equal(sample[0], sample[1].relative_position(sample[2]))
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
class TopologicalPrimitive < MiniTest::TestCase
|
216
|
+
def test_nothing
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
class Node < MiniTest::TestCase
|
221
|
+
def test_nothing
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
class Edge < MiniTest::TestCase
|
226
|
+
def test_nothing
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
class Duration < MiniTest::TestCase
|
231
|
+
def test__duration_constructors
|
232
|
+
assert_equal( 1, When::TM::Duration.new(1).duration)
|
233
|
+
assert_equal( 1.0/128, When::TM::Duration.second(1).duration)
|
234
|
+
assert_equal( 60.0/128, When::TM::Duration.minute(1).duration)
|
235
|
+
assert_equal( 3600.0/128, When::TM::Duration.hour(1).duration)
|
236
|
+
assert_equal(86400.0/128, When::TM::Duration.day(1).duration)
|
237
|
+
assert_equal(93784.0/128, When::TM::Duration.dhms(1,2,3,4).duration)
|
238
|
+
end
|
239
|
+
|
240
|
+
def test__duration_values
|
241
|
+
assert_equal(1, When::TM::Duration.new(1).system)
|
242
|
+
assert_equal(2, When::TM::Duration.second(2).second)
|
243
|
+
assert_equal(3, When::TM::Duration.minute(3).minute)
|
244
|
+
assert_equal(4, When::TM::Duration.hour(4).hour)
|
245
|
+
assert_equal(5, When::TM::Duration.day(5).day)
|
246
|
+
assert_equal([1,2,3,4], When::TM::Duration.dhms(1,2,3,4).to_dhms)
|
247
|
+
assert_equal([-2,21,56,56], (-When::TM::Duration.dhms(1,2,3,4)).to_dhms)
|
248
|
+
end
|
249
|
+
|
250
|
+
def test__duration_elements
|
251
|
+
duration = When::TM::Duration.dhms(1,2,3,4.5)
|
252
|
+
assert_equal(1, duration[0])
|
253
|
+
assert_equal(2, duration[1])
|
254
|
+
assert_equal(3, duration[2])
|
255
|
+
assert_equal(4.5, duration[3])
|
256
|
+
end
|
257
|
+
|
258
|
+
def test__duration_arithmetics
|
259
|
+
assert_equal(When::TM::Duration.dhms(-2,21,56,56), -When::TM::Duration.dhms(1,2,3,4))
|
260
|
+
assert_equal(When::TM::Duration.dhms(2,3,4,5), When::TM::Duration.dhms(1,2,3,4) + When::TM::Duration.dhms(1,1,1,1))
|
261
|
+
assert_equal(When::TM::Duration.dhms(0,1,2,3), When::TM::Duration.dhms(1,2,3,4) - When::TM::Duration.dhms(1,1,1,1))
|
262
|
+
assert_equal(When::TM::Duration.dhms(2,4,6,8), When::TM::Duration.dhms(1,2,3,4) * 2)
|
263
|
+
assert_equal(When::TM::Duration.dhms(1,2,3,4), When::TM::Duration.dhms(2,4,6,8) / 2)
|
264
|
+
assert_equal(2, When::TM::Duration.dhms(2,4,6,8) / When::TM::Duration.dhms(1,2,3,4))
|
265
|
+
end
|
266
|
+
|
267
|
+
def test__duration_and_time
|
268
|
+
start = Time.now
|
269
|
+
duration = When::TM::Duration.dhms(1,2,3,4.25)
|
270
|
+
stop = start + duration
|
271
|
+
assert_equal((RUBY_VERSION.to_f<1.9 ? 93784.25 : 93784), stop-start)
|
272
|
+
assert_raises(TypeError) {
|
273
|
+
::Date.today + duration
|
274
|
+
}
|
275
|
+
require 'when_exe/core/duration'
|
276
|
+
stop = start + duration
|
277
|
+
assert_equal(93784.25, stop-start)
|
278
|
+
|
279
|
+
now_date = DateTime.now
|
280
|
+
duration = When::TM::Duration.hour(8)
|
281
|
+
assert_equal(Rational(1,128), (now_date + duration * 3 / 128 ) - now_date)
|
282
|
+
assert_equal(Rational(1,3), (now_date + duration ) - now_date)
|
283
|
+
assert_equal(Rational(1,1), (now_date + duration * 3) - now_date)
|
284
|
+
|
285
|
+
stop = start + When.Duration('P1DT2H3M4S')
|
286
|
+
assert_equal(93784, stop-start)
|
287
|
+
|
288
|
+
assert_raises(TypeError) {
|
289
|
+
stop = start + When.Duration('P2M1DT2H3M4S')
|
290
|
+
}
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
class PeriodDuration < MiniTest::TestCase
|
295
|
+
def test__period_duration
|
296
|
+
period = When.Duration('P2Y3M4D')
|
297
|
+
[[-2, 2], [-1, 3], [0, 4]].each do |sample|
|
298
|
+
assert_equal(sample[1], period[sample[0]])
|
299
|
+
end
|
300
|
+
period = When.Duration('PT5H6M7S')
|
301
|
+
[[1, 5], [2, 6], [3, 7]].each do |sample|
|
302
|
+
assert_equal(sample[1], period[sample[0]])
|
303
|
+
end
|
304
|
+
period = When.Duration('P2Y3M4DT5H6M7S')
|
305
|
+
[[-2, 2], [-1, 3], [0, 4], [1, 5], [2, 6], [3, 7]].each do |sample|
|
306
|
+
assert_equal(sample[1], period[sample[0]])
|
307
|
+
end
|
308
|
+
period = When.Duration('P8W9D')
|
309
|
+
[[-0.5, 8], [0, 8*7+9]].each do |sample|
|
310
|
+
assert_equal(sample[1], period[sample[0]])
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
def test__period_duration_diff
|
315
|
+
date1 = When.when?('2012-07-01')
|
316
|
+
date2 = When.when?('2012-07-02')
|
317
|
+
duration = date2 - date1
|
318
|
+
assert_equal('P1D', duration.to_s)
|
319
|
+
assert_equal(When::TM::PeriodDuration, duration.class)
|
320
|
+
|
321
|
+
if Object.const_defined?(:TZInfo)
|
322
|
+
time = When.when?('2013-03-10T01:00:00', :tz=>'America/New_York')
|
323
|
+
assert_equal('2013-03-10T02:30:00-04:00', (time + When.Duration('PT1.5H')).to_s) # ��ʂ�1.5����
|
324
|
+
else
|
325
|
+
puts
|
326
|
+
puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
|
327
|
+
end
|
328
|
+
|
329
|
+
vcal = When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
|
330
|
+
time = When.when?('2013-03-10T01:00:00', :clock=>vcal['America/New_York'])
|
331
|
+
assert_equal('2013-03-10T02:30:00-04:00', (time + When.Duration('PT1.5H')).to_s) # ��ʂ�1.5����
|
332
|
+
end
|
333
|
+
|
334
|
+
Sample10 = %w(2013-01-31 2013-02-28 2013-03-31 2013-04-30 2013-05-31
|
335
|
+
2013-06-30 2013-07-31 2013-08-31 2013-09-30 2013-10-31)
|
336
|
+
|
337
|
+
Sample12 = %w(2013-01-31 2013-02-28 2013-03-31 2013-04-30 2013-05-31 2013-06-30
|
338
|
+
2013-07-31 2013-08-31 2013-09-30 2013-10-31 2013-11-30 2013-12-31)
|
339
|
+
|
340
|
+
def test__duration_each
|
341
|
+
sample = Sample10.dup
|
342
|
+
When::P1M.enum_for(When.when?('2013-01-31'), :forward, 10).each do |date|
|
343
|
+
assert_equal(sample.shift, date.to_s)
|
344
|
+
end
|
345
|
+
|
346
|
+
count = 0
|
347
|
+
(When.when?('2013-01-31') ^ When::P1M).each({:count_limit=>0}) do |date|
|
348
|
+
count += 1
|
349
|
+
end
|
350
|
+
assert_equal(0, count)
|
351
|
+
|
352
|
+
sample = Sample10.dup
|
353
|
+
(When.when?('2013-01-31') ^ When::P1M).each({:count_limit=>10}) do |date|
|
354
|
+
assert_equal(sample.shift, date.to_s)
|
355
|
+
end
|
356
|
+
|
357
|
+
sample = Sample12.dup
|
358
|
+
(When.when?('2013-01-31') ^ When::P1M).each({:until=>When.when?('2013-12-31')}) do |date|
|
359
|
+
assert_equal(sample.shift, date.to_s)
|
360
|
+
end
|
361
|
+
|
362
|
+
sample = Sample12.reverse
|
363
|
+
(When.when?('2013-12-31') ^ -When::P1M).each({:until=>When.when?('2013-01-31')}) do |date|
|
364
|
+
assert_equal(sample.shift, date.to_s)
|
365
|
+
end
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
class IntervalLength < MiniTest::TestCase
|
370
|
+
def test__interval_length
|
371
|
+
[
|
372
|
+
['7E-3s', 7, 3, 10, 'second', '7E-3s' ],
|
373
|
+
['8X-2m', 8, 2, 60, 'minute', '8X-2m' ],
|
374
|
+
['6(12)7D', 6, -7, 12, 'day', '6(12)+7D' ],
|
375
|
+
['1(16)4*10S', 1, -4, 16, '10', '1(16)+4*10S']
|
376
|
+
].each do |sample|
|
377
|
+
interval = When.Duration(sample[0])
|
378
|
+
assert_equal(sample[1..5], [interval.value, interval.factor, interval.radix, interval.unit, interval.to_s])
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
def test__interval_length_diff
|
383
|
+
time1 = When.when?('2012-07-01T01:23:45+09:00')
|
384
|
+
time2 = When.when?('2012-07-02T01:23:45+09:00')
|
385
|
+
duration = time2 - time1
|
386
|
+
assert_equal('86401.0s', duration.to_s)
|
387
|
+
assert_equal(When::TM::IntervalLength, duration.class)
|
388
|
+
|
389
|
+
if Object.const_defined?(:TZInfo)
|
390
|
+
time = When.when?('2013-03-10T01:00:00', :tz=>'America/New_York')
|
391
|
+
assert_equal('2013-03-10T03:30:00-04:00', (time + When.Duration('1.5h')).to_s) # �����I��1.5����
|
392
|
+
else
|
393
|
+
puts
|
394
|
+
puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
|
395
|
+
end
|
396
|
+
|
397
|
+
vcal = When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
|
398
|
+
time = When.when?('2013-03-10T01:00:00', :clock=>vcal['America/New_York'])
|
399
|
+
assert_equal('2013-03-10T03:30:00-04:00', (time + When.Duration('1.5h')).to_s) # �����I��1.5����
|
400
|
+
end
|
401
|
+
end
|
402
|
+
end
|