when_exe 0.3.6 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +171 -0
  3. data/lib/when_exe.rb +78 -47
  4. data/lib/when_exe/basictypes.rb +752 -747
  5. data/lib/when_exe/calendarnote.rb +805 -801
  6. data/lib/when_exe/calendartypes.rb +1583 -1531
  7. data/lib/when_exe/coordinates.rb +16 -15
  8. data/lib/when_exe/core/duration.rb +114 -110
  9. data/lib/when_exe/core/extension.rb +504 -504
  10. data/lib/when_exe/ephemeris.rb +1917 -1913
  11. data/lib/when_exe/ephemeris/moon.rb +333 -333
  12. data/lib/when_exe/ephemeris/notes.rb +389 -387
  13. data/lib/when_exe/ephemeris/planets.rb +585 -585
  14. data/lib/when_exe/ephemeris/sun.rb +214 -214
  15. data/lib/when_exe/googlecalendar.rb +144 -140
  16. data/lib/when_exe/icalendar.rb +1636 -1636
  17. data/lib/when_exe/inspect.rb +46 -22
  18. data/lib/when_exe/locales/akt.rb +176 -176
  19. data/lib/when_exe/locales/encoding_conversion.rb +134 -126
  20. data/lib/when_exe/locales/iast.rb +90 -90
  21. data/lib/when_exe/locales/locale.rb +750 -746
  22. data/lib/when_exe/locales/transliteration_table.rb +62 -62
  23. data/lib/when_exe/mini_application.rb +307 -305
  24. data/lib/when_exe/parts/enumerator.rb +2 -2
  25. data/lib/when_exe/parts/geometric_complex.rb +397 -397
  26. data/lib/when_exe/parts/method_cash.rb +224 -224
  27. data/lib/when_exe/parts/resource.rb +1069 -1071
  28. data/lib/when_exe/parts/timezone.rb +240 -230
  29. data/lib/when_exe/region/armenian.rb +56 -56
  30. data/lib/when_exe/region/babylonian.rb +405 -0
  31. data/lib/when_exe/region/bahai.rb +146 -146
  32. data/lib/when_exe/region/balinese.rb +622 -622
  33. data/lib/when_exe/region/chinese.rb +95 -25
  34. data/lib/when_exe/region/chinese/calendars.rb +1016 -1016
  35. data/lib/when_exe/region/chinese/epochs.rb +1 -1
  36. data/lib/when_exe/region/chinese/twins.rb +803 -795
  37. data/lib/when_exe/region/christian.rb +824 -824
  38. data/lib/when_exe/region/coptic.rb +106 -87
  39. data/lib/when_exe/region/discordian.rb +225 -225
  40. data/lib/when_exe/region/far_east.rb +188 -188
  41. data/lib/when_exe/region/french.rb +56 -56
  42. data/lib/when_exe/region/geologicalage.rb +639 -639
  43. data/lib/when_exe/region/goddess.rb +58 -58
  44. data/lib/when_exe/region/indian.rb +1254 -1251
  45. data/lib/when_exe/region/iranian.rb +8 -8
  46. data/lib/when_exe/region/islamic.rb +3 -3
  47. data/lib/when_exe/region/japanese.rb +93 -99
  48. data/lib/when_exe/region/japanese/calendars.rb +396 -397
  49. data/lib/when_exe/region/japanese/epochs.rb +26 -26
  50. data/lib/when_exe/region/japanese/nihon_shoki.rb +71 -71
  51. data/lib/when_exe/region/japanese/notes.rb +1383 -1386
  52. data/lib/when_exe/region/japanese/residues.rb +1306 -1306
  53. data/lib/when_exe/region/japanese/twins.rb +225 -225
  54. data/lib/when_exe/region/japanese/weeks.rb +112 -0
  55. data/lib/when_exe/region/javanese.rb +230 -230
  56. data/lib/when_exe/region/jewish.rb +126 -126
  57. data/lib/when_exe/region/korean.rb +378 -378
  58. data/lib/when_exe/region/m17n.rb +114 -113
  59. data/lib/when_exe/region/martian.rb +258 -255
  60. data/lib/when_exe/region/mayan.rb +32 -32
  61. data/lib/when_exe/region/residue.rb +89 -89
  62. data/lib/when_exe/region/roman.rb +36 -24
  63. data/lib/when_exe/region/ryukyu.rb +97 -97
  64. data/lib/when_exe/region/shire.rb +240 -240
  65. data/lib/when_exe/region/soviet.rb +209 -0
  66. data/lib/when_exe/region/symmetry.rb +50 -50
  67. data/lib/when_exe/region/thai.rb +336 -335
  68. data/lib/when_exe/region/tibetan.rb +316 -315
  69. data/lib/when_exe/region/vietnamese.rb +440 -439
  70. data/lib/when_exe/region/weekdate.rb +80 -80
  71. data/lib/when_exe/region/world.rb +175 -175
  72. data/lib/when_exe/region/yerm.rb +14 -14
  73. data/lib/when_exe/region/zoroastrian.rb +203 -203
  74. data/lib/when_exe/timestandard.rb +707 -681
  75. data/lib/when_exe/tmduration.rb +338 -330
  76. data/lib/when_exe/tmobjects.rb +1346 -1325
  77. data/lib/when_exe/tmposition.rb +2115 -2072
  78. data/lib/when_exe/tmreference.rb +1693 -1669
  79. data/lib/when_exe/version.rb +1 -1
  80. data/link_to_online_documents +1 -1
  81. data/test/examples/JapanHolidaysRFC6350.ics +1 -1
  82. data/test/test.rb +67 -61
  83. data/test/test/basictypes.rb +409 -409
  84. data/test/test/calendarnote.rb +86 -69
  85. data/test/test/calendartypes.rb +97 -97
  86. data/test/test/coordinates.rb +396 -396
  87. data/test/test/ephemeris.rb +83 -74
  88. data/test/test/ephemeris/moon.rb +14 -14
  89. data/test/test/ephemeris/planets.rb +14 -14
  90. data/test/test/ephemeris/sun.rb +14 -14
  91. data/test/test/googlecalendar.rb +194 -176
  92. data/test/test/icalendar.rb +867 -858
  93. data/test/test/inspect.rb +117 -117
  94. data/test/test/parts.rb +487 -487
  95. data/test/test/region/balinese.rb +34 -0
  96. data/test/test/region/chinese.rb +218 -206
  97. data/test/test/region/christian.rb +245 -245
  98. data/test/test/region/coptic.rb +27 -27
  99. data/test/test/region/french.rb +33 -33
  100. data/test/test/region/geologicalage.rb +17 -17
  101. data/test/test/region/indian.rb +57 -57
  102. data/test/test/region/iran.rb +54 -54
  103. data/test/test/region/islamic.rb +18 -18
  104. data/test/test/region/japanese.rb +237 -219
  105. data/test/test/region/jewish.rb +61 -61
  106. data/test/test/region/m17n.rb +184 -184
  107. data/test/test/region/mayan.rb +195 -195
  108. data/test/test/region/residue.rb +147 -139
  109. data/test/test/region/thai.rb +116 -116
  110. data/test/test/region/tibetan.rb +30 -30
  111. data/test/test/region/vietnamese.rb +102 -102
  112. data/test/test/region/yerm.rb +146 -146
  113. data/test/test/timestandard.rb +81 -81
  114. data/test/test/tmobjects.rb +328 -328
  115. data/test/test/tmposition.rb +397 -284
  116. data/test/test/tmreference.rb +157 -157
  117. metadata +13 -10
@@ -1,328 +1,328 @@
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 Test::TM
10
-
11
- #
12
- # (5.2) Temporal Objects Package
13
- #
14
- #
15
-
16
- class Separation < Test::Unit::TestCase
17
- def test_nothing
18
- end
19
- end
20
-
21
- class Order < Test::Unit::TestCase
22
- def test_nothing
23
- end
24
- end
25
-
26
- class RelativePosition < Test::Unit::TestCase
27
- def test_nothing
28
- end
29
- end
30
-
31
- class Object < Test::Unit::TestCase
32
- def test_nothing
33
- end
34
- end
35
-
36
- class Complex < Test::Unit::TestCase
37
- def test_nothing
38
- end
39
- end
40
-
41
- class TopologicalComplex < Test::Unit::TestCase
42
- def test_nothing
43
- end
44
- end
45
-
46
- class Primitive < Test::Unit::TestCase
47
- def test_nothing
48
- end
49
- end
50
-
51
- class GeometricPrimitive < Test::Unit::TestCase
52
- def test_nothing
53
- end
54
- end
55
-
56
- class Instant < Test::Unit::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 < Test::Unit::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 < Test::Unit::TestCase
216
- def test_nothing
217
- end
218
- end
219
-
220
- class Node < Test::Unit::TestCase
221
- def test_nothing
222
- end
223
- end
224
-
225
- class Edge < Test::Unit::TestCase
226
- def test_nothing
227
- end
228
- end
229
-
230
- class Duration < Test::Unit::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.4)
270
- stop = start + duration
271
- assert_equal((RUBY_VERSION.to_f<1.9 ? 93784.4 : 93784), stop-start)
272
- assert_raise(TypeError) {
273
- ::Date.today + duration
274
- }
275
- require 'when_exe/core/duration'
276
- stop = start + duration
277
- assert_equal(93784.4, 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_raise(TypeError) {
289
- stop = start + When.Duration('P2M1DT2H3M4S')
290
- }
291
- end
292
- end
293
-
294
- class PeriodDuration < Test::Unit::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
- end
314
-
315
- class IntervalLength < Test::Unit::TestCase
316
- def test__interval_length
317
- [
318
- ['7E-3s', 7, 3, 10, 'second', '7E-3s' ],
319
- ['8X-2m', 8, 2, 60, 'minute', '8X-2m' ],
320
- ['6(12)7D', 6, -7, 12, 'day', '6(12)+7D' ],
321
- ['1(16)4*10S', 1, -4, 16, '10', '1(16)+4*10S']
322
- ].each do |sample|
323
- interval = When.Duration(sample[0])
324
- assert_equal(sample[1..5], [interval.value, interval.factor, interval.radix, interval.unit, interval.to_s])
325
- end
326
- end
327
- end
328
- 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
+ end
314
+
315
+ class IntervalLength < MiniTest::TestCase
316
+ def test__interval_length
317
+ [
318
+ ['7E-3s', 7, 3, 10, 'second', '7E-3s' ],
319
+ ['8X-2m', 8, 2, 60, 'minute', '8X-2m' ],
320
+ ['6(12)7D', 6, -7, 12, 'day', '6(12)+7D' ],
321
+ ['1(16)4*10S', 1, -4, 16, '10', '1(16)+4*10S']
322
+ ].each do |sample|
323
+ interval = When.Duration(sample[0])
324
+ assert_equal(sample[1..5], [interval.value, interval.factor, interval.radix, interval.unit, interval.to_s])
325
+ end
326
+ end
327
+ end
328
+ end