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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -23
  3. data/lib/when_exe/ephemeris/moon.rb +333 -333
  4. data/lib/when_exe/linkeddata.rb +0 -1
  5. data/lib/when_exe/locales/encoding_conversion.rb +134 -134
  6. data/lib/when_exe/locales/iast.rb +90 -90
  7. data/lib/when_exe/locales/transliteration_table.rb +62 -62
  8. data/lib/when_exe/parts/method_cash.rb +224 -224
  9. data/lib/when_exe/region/chinese/calendars.rb +1016 -1016
  10. data/lib/when_exe/region/geologicalage.rb +1 -1
  11. data/lib/when_exe/region/japanese/calendars.rb +397 -397
  12. data/lib/when_exe/region/japanese/eclipses.rb +1194 -1194
  13. data/lib/when_exe/region/japanese/nihon_shoki.rb +70 -70
  14. data/lib/when_exe/region/korean.rb +384 -384
  15. data/lib/when_exe/region/ryukyu.rb +101 -101
  16. data/lib/when_exe/tmposition.rb +2 -2
  17. data/lib/when_exe/tmreference.rb +3 -3
  18. data/lib/when_exe/version.rb +1 -1
  19. data/test/scripts/geometric_complex.rb +41 -41
  20. data/test/scripts/korea.rb +59 -59
  21. data/test/scripts/thai.rb +36 -36
  22. data/test/test/basictypes.rb +431 -431
  23. data/test/test/calendarnote.rb +86 -86
  24. data/test/test/calendartypes.rb +97 -97
  25. data/test/test/coordinates.rb +397 -397
  26. data/test/test/ephemeris.rb +115 -115
  27. data/test/test/ephemeris/moon.rb +14 -14
  28. data/test/test/ephemeris/planets.rb +14 -14
  29. data/test/test/ephemeris/sun.rb +14 -14
  30. data/test/test/inspect.rb +153 -153
  31. data/test/test/parts.rb +488 -488
  32. data/test/test/region/armenian.rb +20 -20
  33. data/test/test/region/bahai.rb +58 -58
  34. data/test/test/region/balinese.rb +34 -34
  35. data/test/test/region/chinese.rb +229 -229
  36. data/test/test/region/christian.rb +226 -226
  37. data/test/test/region/coptic.rb +27 -27
  38. data/test/test/region/discordian.rb +20 -20
  39. data/test/test/region/french.rb +33 -33
  40. data/test/test/region/geologicalage.rb +17 -17
  41. data/test/test/region/iran.rb +54 -54
  42. data/test/test/region/islamic.rb +54 -54
  43. data/test/test/region/japanese.rb +261 -261
  44. data/test/test/region/jewish.rb +63 -63
  45. data/test/test/region/shire.rb +58 -58
  46. data/test/test/region/swedish.rb +45 -45
  47. data/test/test/region/thai.rb +116 -116
  48. data/test/test/region/tibetan.rb +30 -30
  49. data/test/test/region/vietnamese.rb +102 -102
  50. data/test/test/region/zoroastrian.rb +58 -58
  51. data/test/test/timestandard.rb +81 -81
  52. data/test/test/tmobjects.rb +402 -402
  53. data/test/test/tmreference.rb +157 -157
  54. metadata +4 -88
data/test/test/parts.rb CHANGED
@@ -1,488 +1,488 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
- Copyright (C) 2011-2014 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 When::Parts
10
- class GeometricComplex
11
- def ==(other)
12
- return false unless other.kind_of?(self.class)
13
- return self.node == other.node && self.reverse == other.reverse
14
- end
15
- end
16
- end
17
-
18
- module MiniTest::Parts
19
-
20
- class MethodCash < MiniTest::TestCase
21
- class A
22
- include When::Parts::MethodCash
23
-
24
- def func_0_(x)
25
- #pp ['--0--',x]
26
- return x**2
27
- end
28
-
29
- def func_0_setup(k, x)
30
- #pp ['-0-setup-',k,x]
31
- @_m_cash_["func_0"][k] ||= x**2
32
- end
33
-
34
- def func_1_(x)
35
- #pp ['--1--',x]
36
- return x**4
37
- end
38
-
39
- def _from_to_to_(x,y)
40
- #pp ['--2--',x, y]
41
- return 10 * x + y
42
- end
43
-
44
- def _to_to_from_(x)
45
- #pp ['--3--',x]
46
- return x.divmod(10)
47
- end
48
-
49
- def cash
50
- @_m_cash_
51
- end
52
- end
53
-
54
- class B < A
55
- def initialize
56
- @_m_cash_lock_ = Mutex.new
57
- end
58
- end
59
-
60
- def test__method_cash
61
- [A, B].each do |klass|
62
- c = klass.new
63
- assert_equal(4, c.func_0(2))
64
- assert_equal(4, c.func_0(2))
65
- assert_equal({"func_0"=>{2=>4}}, c.cash)
66
- assert_equal(16, c.func_1(2))
67
- assert_equal(16, c.func_1(2))
68
- assert_equal({"func_1"=>{2=>16}, "func_0"=>{2=>4}}, c.cash)
69
- assert_equal(34, c._from_to_to(3,4))
70
- assert_equal([3, 4], c._to_to_from(34))
71
- assert_equal([3, 3], c._to_to_from(33))
72
- assert_equal({"func_1"=>{2=>16}, "func_0"=>{2=>4},
73
- "_from_to_to"=>{[3, 3]=>[33], [3, 4]=>34}, "_to_to_from"=>{33=>[3, 3], 34=>[3, 4]}}, c.cash)
74
- end
75
- end
76
- end
77
-
78
- class Locale < MiniTest::TestCase
79
- Term1 = When.m17n('Tokyo', 'zip')
80
- Term2 = When.m17n(<<LABEL, <<NS, <<LOCALE)
81
- [
82
- Getsuyou
83
- Monday
84
- ]
85
- LABEL
86
- ISO, jwiki=http://ja.wikipedia.org/wiki/, ewiki=http://en.wikipedia.org/wiki/
87
- NS
88
- =jwiki:, en=ewiki:
89
- LOCALE
90
- Term3 = When.Resource('_co:Common::Week::Monday::Monday')
91
-
92
- def test__locale
93
- assert_equal("Tokyo", Term1.translate('en_US'))
94
- assert_equal("Monday", Term2.translate('en_US'))
95
- assert_equal("Monday", Term3.translate('en_US'))
96
- end
97
-
98
- def test__reference
99
- assert_equal(nil, Term1.reference('ja_JP'))
100
- assert_equal(nil, Term1.reference('en_US'))
101
- assert_equal("http://ja.wikipedia.org/wiki/Getsuyou", Term2.reference('ja_JP'))
102
- assert_equal("http://en.wikipedia.org/wiki/Monday", Term2.reference('en_US'))
103
- assert_equal("http://ja.wikipedia.org/wiki/%E6%9C%88%E6%9B%9C%E6%97%A5", Term3.reference('ja_JP'))
104
- end
105
-
106
- def test__labels
107
- assert_equal({""=>"Tokyo"}, Term1.names)
108
- assert_equal({""=>"Getsuyou", "en"=>"Monday"}, Term2.names)
109
- # assert_equal({""=>"Monday", "ja"=>"月曜日"}, Term3.names)
110
- end
111
-
112
- def test__link
113
- assert_equal({},Term1.link)
114
- assert_equal({""=>"http://ja.wikipedia.org/wiki/Getsuyou",
115
- "en"=>"http://en.wikipedia.org/wiki/Monday"}, Term2.link)
116
- assert_equal({"ja"=>"http://ja.wikipedia.org/wiki/%E6%9C%88%E6%9B%9C%E6%97%A5",
117
- ""=>"http://en.wikipedia.org/wiki/Monday"}, Term3.link)
118
- end
119
-
120
- def test__prefix
121
- date = When.when?('0594-09=12^Japanese')
122
- assert_equal(["閏九月", String], [date.name('Month').label.to_s, date.name('Month').label.class])
123
- assert_equal(["閏九月", String], [date.name('Month').to_s, date.name('Month').to_s.class])
124
- assert_equal("http://ja.wikipedia.org/wiki/%E9%96%8F", date.name('Month').reference('ja'))
125
- assert_equal("閏九月", date.name('Month').translate('日本語'))
126
- assert_equal("閏長月", date.name('Month').translate('alias'))
127
- assert_equal("Intercalary Month 9", date.name('Month').translate('en_US'))
128
- end
129
-
130
- def test__split
131
- assert_equal(['' ], When::Locale._split(''))
132
- assert_equal(['3.14' ], When::Locale._split('3.14'))
133
- assert_equal(['3.14', ''], When::Locale._split('3.14,'))
134
- assert_equal(['', '3.14'], When::Locale._split(',3.14'))
135
- assert_equal(['3.14', ' "3.14,159"'], When::Locale._split('3.14, "3.14,159"'))
136
- assert_equal(['3.14', ' "3.14\\"159"'], When::Locale._split('3.14, "3.14\\"159"'))
137
- end
138
- end
139
-
140
- class Resource < MiniTest::TestCase
141
- def test_nothing
142
- end
143
- end
144
-
145
- class Enumerator < MiniTest::TestCase
146
-
147
- def test_nothing
148
- end
149
-
150
- class Array < MiniTest::TestCase
151
- def test_nothing
152
- end
153
- end
154
-
155
- class Integrated < MiniTest::TestCase
156
- def test_nothing
157
- end
158
- end
159
- end
160
-
161
- class GeometricComplex < MiniTest::TestCase
162
-
163
- def test__include
164
-
165
- sample = [false, false, false, false, false]
166
- complex = When::Parts::GeometricComplex.new(false)
167
- assert_equal(nil, complex.exclude_end?)
168
- (1..5).each do |i|
169
- assert_equal(sample.shift, complex.include?(i))
170
- end
171
-
172
- sample = [true, true, true, true, true]
173
- complex = When::Parts::GeometricComplex.new(true)
174
- assert_equal(nil, complex.exclude_end?)
175
- (1..5).each do |i|
176
- assert_equal(sample.shift, complex.include?(i))
177
- end
178
-
179
- sample = [false, true, true, true, false]
180
- complex = When::Parts::GeometricComplex.new(2..4)
181
- assert_equal(false, complex.exclude_end?)
182
- (1..5).each do |i|
183
- assert_equal(sample.shift, complex.include?(i))
184
- end
185
-
186
- sample = [false, true, true, false, false]
187
- complex = When::Parts::GeometricComplex.new(2...4)
188
- assert_equal(true, complex.exclude_end?)
189
- (1..5).each do |i|
190
- assert_equal(sample.shift, complex.include?(i))
191
- end
192
-
193
- sample = [true, false, false, false, true]
194
- complex = -When::Parts::GeometricComplex.new(2..4)
195
- assert_equal(true, complex.exclude_end?)
196
- (1..5).each do |i|
197
- assert_equal(sample.shift, complex.include?(i))
198
- end
199
-
200
- sample = [true, false, false, true, true]
201
- complex = -When::Parts::GeometricComplex.new(2...4)
202
- assert_equal(false, complex.exclude_end?)
203
- (1..5).each do |i|
204
- assert_equal(sample.shift, complex.include?(i))
205
- end
206
-
207
- period_1_2 = When::Parts::GeometricComplex.new(1..2)
208
- period_2_3 = When::Parts::GeometricComplex.new(2..3)
209
- period_3_4 = When::Parts::GeometricComplex.new(3..4)
210
- period_4_5 = When::Parts::GeometricComplex.new(4..5)
211
- period_5_6 = When::Parts::GeometricComplex.new(5..6)
212
-
213
- period_2_4 = When::Parts::GeometricComplex.new(2..4)
214
- period_3_6 = When::Parts::GeometricComplex.new(3..6)
215
- period_4_6 = When::Parts::GeometricComplex.new(4..6)
216
- period_1_6 = When::Parts::GeometricComplex.new(1..6)
217
-
218
- [[false, period_1_2, period_4_6],
219
- [false, period_1_2, period_2_4],
220
- [false, period_2_4, period_3_6],
221
- [false, period_2_3, period_2_4],
222
- [true, period_2_4, period_2_3],
223
-
224
- [false, period_2_4, period_1_6],
225
- [true, period_1_6, period_2_4],
226
- [true, period_2_4, period_2_4],
227
-
228
- [false, period_3_6, period_2_4],
229
- [false, period_3_4, period_2_4],
230
- [true, period_2_4, period_3_4],
231
- [false, period_4_5, period_2_4],
232
- [false, period_5_6, period_2_4]].each do |sample|
233
- assert_equal(sample[0], sample[1].include?(sample[2]))
234
- end
235
-
236
- period_1_2 = When::Parts::GeometricComplex.new(1...2)
237
- period_2_3 = When::Parts::GeometricComplex.new(2...3)
238
- period_3_4 = When::Parts::GeometricComplex.new(3...4)
239
- period_4_5 = When::Parts::GeometricComplex.new(4...5)
240
- period_5_6 = When::Parts::GeometricComplex.new(5...6)
241
-
242
- period_2_4 = When::Parts::GeometricComplex.new(2...4)
243
- period_3_6 = When::Parts::GeometricComplex.new(3...6)
244
- period_4_6 = When::Parts::GeometricComplex.new(4...6)
245
- period_1_6 = When::Parts::GeometricComplex.new(1...6)
246
-
247
- [[false, period_1_2, period_4_6],
248
- [false, period_1_2, period_2_4],
249
- [false, period_2_4, period_3_6],
250
- [false, period_2_3, period_2_4],
251
- [true, period_2_4, period_2_3],
252
-
253
- [false, period_2_4, period_1_6],
254
- [true, period_1_6, period_2_4],
255
- [true, period_2_4, period_2_4],
256
-
257
- [false, period_3_6, period_2_4],
258
- [false, period_3_4, period_2_4],
259
- [true, period_2_4, period_3_4],
260
- [false, period_4_5, period_2_4],
261
- [false, period_5_6, period_2_4]].each do |sample|
262
- assert_equal(sample[0], sample[1].include?(sample[2]))
263
- end
264
-
265
- period_1_2 = -When::Parts::GeometricComplex.new(1..2)
266
- period_2_3 = -When::Parts::GeometricComplex.new(2..3)
267
- period_3_4 = -When::Parts::GeometricComplex.new(3..4)
268
- period_4_5 = -When::Parts::GeometricComplex.new(4..5)
269
- period_5_6 = -When::Parts::GeometricComplex.new(5..6)
270
-
271
- period_2_4 = -When::Parts::GeometricComplex.new(2..4)
272
- period_3_6 = -When::Parts::GeometricComplex.new(3..6)
273
- period_4_6 = -When::Parts::GeometricComplex.new(4..6)
274
- period_1_6 = -When::Parts::GeometricComplex.new(1..6)
275
-
276
- [[false, period_4_6, period_1_2],
277
- [false, period_2_4, period_1_2],
278
- [false, period_3_6, period_2_4],
279
- [false, period_2_4, period_2_3],
280
- [true, period_2_3, period_2_4],
281
-
282
- [false, period_1_6, period_2_4],
283
- [true, period_2_4, period_1_6],
284
- [true, period_2_4, period_2_4],
285
-
286
- [false, period_2_4, period_3_6],
287
- [false, period_2_4, period_3_4],
288
- [true, period_3_4, period_2_4],
289
- [false, period_2_4, period_4_5],
290
- [false, period_2_4, period_5_6]].each do |sample|
291
- assert_equal(sample[0], sample[1].include?(sample[2]))
292
- end
293
-
294
- period_1_2 = -When::Parts::GeometricComplex.new(1...2)
295
- period_2_3 = -When::Parts::GeometricComplex.new(2...3)
296
- period_3_4 = -When::Parts::GeometricComplex.new(3...4)
297
- period_4_5 = -When::Parts::GeometricComplex.new(4...5)
298
- period_5_6 = -When::Parts::GeometricComplex.new(5...6)
299
-
300
- period_2_4 = -When::Parts::GeometricComplex.new(2...4)
301
- period_3_6 = -When::Parts::GeometricComplex.new(3...6)
302
- period_4_6 = -When::Parts::GeometricComplex.new(4...6)
303
- period_1_6 = -When::Parts::GeometricComplex.new(1...6)
304
-
305
- [[false, period_4_6, period_1_2],
306
- [false, period_2_4, period_1_2],
307
- [false, period_3_6, period_2_4],
308
- [false, period_2_4, period_2_3],
309
- [true, period_2_3, period_2_4],
310
-
311
- [false, period_1_6, period_2_4],
312
- [true, period_2_4, period_1_6],
313
- [true, period_2_4, period_2_4],
314
-
315
- [false, period_2_4, period_3_6],
316
- [false, period_2_4, period_3_4],
317
- [true, period_3_4, period_2_4],
318
- [false, period_2_4, period_4_5],
319
- [false, period_2_4, period_5_6]].each do |sample|
320
- assert_equal(sample[0], sample[1].include?(sample[2]))
321
- end
322
- end
323
-
324
- def test__union
325
-
326
- sample = [false, true, false, true, true, false]
327
- complex = When::Parts::GeometricComplex.new(3..4)
328
- complex |= 1
329
- (0..5).each do |i|
330
- assert_equal(sample.shift, complex.include?(i))
331
- end
332
-
333
- sample = [true, false, true, false, false, true]
334
- complex = When::Parts::GeometricComplex.new(3..4)
335
- complex |= 1
336
- complex = -complex
337
- (0..5).each do |i|
338
- assert_equal(sample.shift, complex.include?(i))
339
- end
340
-
341
- sample = [false, true, false, true, false, false]
342
- complex = When::Parts::GeometricComplex.new(3...4)
343
- complex |= 1
344
- (0..5).each do |i|
345
- assert_equal(sample.shift, complex.include?(i))
346
- end
347
-
348
- sample = [true, false, true, false, true, true]
349
- complex = When::Parts::GeometricComplex.new(3...4)
350
- complex |= 1
351
- complex = -complex
352
- (0..5).each do |i|
353
- assert_equal(sample.shift, complex.include?(i))
354
- end
355
-
356
- complex = When::Parts::GeometricComplex.new(3..5)
357
- (3..5).each do |i|
358
- union = complex | i
359
- assert_equal(complex, union)
360
- end
361
-
362
- assert_equal(When::Parts::GeometricComplex.new(3..5),
363
- When::Parts::GeometricComplex.new(3...5) | 5)
364
-
365
- null = When::Parts::GeometricComplex.new(false)
366
- all = When::Parts::GeometricComplex.new(true)
367
- period_1_2 = When::Parts::GeometricComplex.new(1..2)
368
- period_2_3 = When::Parts::GeometricComplex.new(2..3)
369
- period_3_4 = When::Parts::GeometricComplex.new(3..4)
370
- period_4_5 = When::Parts::GeometricComplex.new(4..5)
371
- period_5_6 = When::Parts::GeometricComplex.new(5..6)
372
-
373
- period_1_4 = When::Parts::GeometricComplex.new(1..4)
374
- period_2_4 = When::Parts::GeometricComplex.new(2..4)
375
- period_2_5 = When::Parts::GeometricComplex.new(2..5)
376
- period_2_6 = When::Parts::GeometricComplex.new(2..6)
377
- period_3_6 = When::Parts::GeometricComplex.new(3..6)
378
- period_4_6 = When::Parts::GeometricComplex.new(4..6)
379
- period_1_6 = When::Parts::GeometricComplex.new(1..6)
380
-
381
- period_1_2_4_6 = When::Parts::GeometricComplex.new([[1,true],[2,true],[4,true],[6,true]])
382
- period_2_4_5_6 = When::Parts::GeometricComplex.new([[2,true],[4,true],[5,true],[6,true]])
383
-
384
- [[period_1_2_4_6, null, period_1_2_4_6],
385
- [period_1_2_4_6, period_1_2_4_6, null],
386
- [all, all, period_1_2_4_6],
387
- [all, period_1_2_4_6, all],
388
- [period_1_2_4_6, period_1_2, period_4_6],
389
- [period_1_4, period_1_2, period_2_4],
390
- [period_2_6, period_2_4, period_3_6],
391
- [period_2_4, period_2_3, period_2_4],
392
- [period_2_4, period_2_4, period_2_3],
393
-
394
- [period_1_6, period_2_4, period_1_6],
395
- [period_1_6, period_1_6, period_2_4],
396
- [period_2_4, period_2_4, period_2_4],
397
-
398
- [period_2_6, period_3_6, period_2_4],
399
- [period_2_4, period_3_4, period_2_4],
400
- [period_2_4, period_2_4, period_3_4],
401
- [period_2_5, period_4_5, period_2_4],
402
- [period_2_4_5_6, period_5_6, period_2_4]].each do |sample|
403
- assert_equal(sample[0], sample[1] | sample[2])
404
- end
405
-
406
- period_1_2 = When::Parts::GeometricComplex.new(1...2)
407
- period_2_3 = When::Parts::GeometricComplex.new(2...3)
408
- period_3_4 = When::Parts::GeometricComplex.new(3...4)
409
- period_4_5 = When::Parts::GeometricComplex.new(4...5)
410
- period_5_6 = When::Parts::GeometricComplex.new(5...6)
411
-
412
- period_1_4 = When::Parts::GeometricComplex.new(1...4)
413
- period_2_4 = When::Parts::GeometricComplex.new(2...4)
414
- period_2_5 = When::Parts::GeometricComplex.new(2...5)
415
- period_2_6 = When::Parts::GeometricComplex.new(2...6)
416
- period_3_6 = When::Parts::GeometricComplex.new(3...6)
417
- period_4_6 = When::Parts::GeometricComplex.new(4...6)
418
- period_1_6 = When::Parts::GeometricComplex.new(1...6)
419
-
420
- period_1_2_4_6 = When::Parts::GeometricComplex.new([[1,true],[2,false],[4,true],[6,false]])
421
- period_2_4_5_6 = When::Parts::GeometricComplex.new([[2,true],[4,false],[5,true],[6,false]])
422
-
423
- [[period_1_2_4_6, null, period_1_2_4_6],
424
- [period_1_2_4_6, period_1_2_4_6, null],
425
- [all, all, period_1_2_4_6],
426
- [all, period_1_2_4_6, all],
427
- [period_1_2_4_6, period_1_2, period_4_6],
428
- [period_1_4, period_1_2, period_2_4],
429
- [period_2_6, period_2_4, period_3_6],
430
- [period_2_4, period_2_3, period_2_4],
431
- [period_2_4, period_2_4, period_2_3],
432
-
433
- [period_1_6, period_2_4, period_1_6],
434
- [period_1_6, period_1_6, period_2_4],
435
- [period_2_4, period_2_4, period_2_4],
436
-
437
- [period_2_6, period_3_6, period_2_4],
438
- [period_2_4, period_3_4, period_2_4],
439
- [period_2_4, period_2_4, period_3_4],
440
- [period_2_5, period_4_5, period_2_4],
441
- [period_2_4_5_6, period_5_6, period_2_4]].each do |sample|
442
- assert_equal(sample[0], sample[1] | sample[2])
443
- end
444
- end
445
-
446
- def test__include_in_sample
447
- range_1_4 = When::Parts::GeometricComplex.new(1,4)
448
- range_2_2 = When::Parts::GeometricComplex.new(2)
449
- range_2_3 = When::Parts::GeometricComplex.new(2,3)
450
- range_2_5 = When::Parts::GeometricComplex.new(2,5)
451
- range_4_4 = When::Parts::GeometricComplex.new(4)
452
- assert_equal(true, range_1_4.include?(range_2_2))
453
- assert_equal(true, range_1_4.include?(range_2_3))
454
- assert_equal(false, range_1_4.include?(range_2_5))
455
- assert_equal(false, range_1_4.include?(range_4_4))
456
- end
457
-
458
- def test__union_in_sample
459
- #range_null = When::Parts::GeometricComplex.new()
460
- #range_1_1 = When::Parts::GeometricComplex.new(1)
461
- range_1_4 = When::Parts::GeometricComplex.new(1,4)
462
- range_2_2 = When::Parts::GeometricComplex.new(2)
463
- range_2_3 = When::Parts::GeometricComplex.new(2,3)
464
- range_2_5 = When::Parts::GeometricComplex.new(2,5)
465
- range_4_4 = When::Parts::GeometricComplex.new(4)
466
- assert_equal("1...4", range_1_4.to_s)
467
- assert_equal("2...3", range_2_3.to_s)
468
- sample = [1, 2, 3]
469
- range_1_4.each {|x| assert_equal(sample.shift, x)}
470
- assert_equal("4..4", range_4_4.to_s)
471
- assert_equal("1...4", (range_1_4 | range_2_3).to_s)
472
- range_1_5 = range_1_4 | range_2_5
473
- assert_equal("1...5", range_1_5.to_s)
474
- assert_equal("1..4", (range_1_4 | range_4_4).to_s)
475
- reverse_all = When::Parts::GeometricComplex.new(true)
476
- reverse_1_4 = When::Parts::GeometricComplex.new(1,4, true)
477
- reverse_2_3 = When::Parts::GeometricComplex.new(2,3, true)
478
- reverse_2_5 = When::Parts::GeometricComplex.new(2,5, true)
479
- assert_equal("1..4", reverse_1_4.to_s)
480
- assert_equal("2..3", reverse_2_3.to_s)
481
- unless Float::INFINITY == Float::MAX
482
- assert_equal("-Infinity..Infinity", reverse_all.to_s)
483
- assert_equal("-Infinity..Infinity", (reverse_2_3 | range_2_3).to_s)
484
- end
485
- assert_equal("1..2", (reverse_1_4 | range_2_5).to_s)
486
- end
487
- end
488
- end
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2011-2014 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 When::Parts
10
+ class GeometricComplex
11
+ def ==(other)
12
+ return false unless other.kind_of?(self.class)
13
+ return self.node == other.node && self.reverse == other.reverse
14
+ end
15
+ end
16
+ end
17
+
18
+ module MiniTest::Parts
19
+
20
+ class MethodCash < MiniTest::TestCase
21
+ class A
22
+ include When::Parts::MethodCash
23
+
24
+ def func_0_(x)
25
+ #pp ['--0--',x]
26
+ return x**2
27
+ end
28
+
29
+ def func_0_setup(k, x)
30
+ #pp ['-0-setup-',k,x]
31
+ @_m_cash_["func_0"][k] ||= x**2
32
+ end
33
+
34
+ def func_1_(x)
35
+ #pp ['--1--',x]
36
+ return x**4
37
+ end
38
+
39
+ def _from_to_to_(x,y)
40
+ #pp ['--2--',x, y]
41
+ return 10 * x + y
42
+ end
43
+
44
+ def _to_to_from_(x)
45
+ #pp ['--3--',x]
46
+ return x.divmod(10)
47
+ end
48
+
49
+ def cash
50
+ @_m_cash_
51
+ end
52
+ end
53
+
54
+ class B < A
55
+ def initialize
56
+ @_m_cash_lock_ = Mutex.new
57
+ end
58
+ end
59
+
60
+ def test__method_cash
61
+ [A, B].each do |klass|
62
+ c = klass.new
63
+ assert_equal(4, c.func_0(2))
64
+ assert_equal(4, c.func_0(2))
65
+ assert_equal({"func_0"=>{2=>4}}, c.cash)
66
+ assert_equal(16, c.func_1(2))
67
+ assert_equal(16, c.func_1(2))
68
+ assert_equal({"func_1"=>{2=>16}, "func_0"=>{2=>4}}, c.cash)
69
+ assert_equal(34, c._from_to_to(3,4))
70
+ assert_equal([3, 4], c._to_to_from(34))
71
+ assert_equal([3, 3], c._to_to_from(33))
72
+ assert_equal({"func_1"=>{2=>16}, "func_0"=>{2=>4},
73
+ "_from_to_to"=>{[3, 3]=>[33], [3, 4]=>34}, "_to_to_from"=>{33=>[3, 3], 34=>[3, 4]}}, c.cash)
74
+ end
75
+ end
76
+ end
77
+
78
+ class Locale < MiniTest::TestCase
79
+ Term1 = When.m17n('Tokyo', 'zip')
80
+ Term2 = When.m17n(<<LABEL, <<NS, <<LOCALE)
81
+ [
82
+ Getsuyou
83
+ Monday
84
+ ]
85
+ LABEL
86
+ ISO, jwiki=http://ja.wikipedia.org/wiki/, ewiki=http://en.wikipedia.org/wiki/
87
+ NS
88
+ =jwiki:, en=ewiki:
89
+ LOCALE
90
+ Term3 = When.Resource('_co:Common::Week::Monday::Monday')
91
+
92
+ def test__locale
93
+ assert_equal("Tokyo", Term1.translate('en_US'))
94
+ assert_equal("Monday", Term2.translate('en_US'))
95
+ assert_equal("Monday", Term3.translate('en_US'))
96
+ end
97
+
98
+ def test__reference
99
+ assert_equal(nil, Term1.reference('ja_JP'))
100
+ assert_equal(nil, Term1.reference('en_US'))
101
+ assert_equal("http://ja.wikipedia.org/wiki/Getsuyou", Term2.reference('ja_JP'))
102
+ assert_equal("http://en.wikipedia.org/wiki/Monday", Term2.reference('en_US'))
103
+ assert_equal("http://ja.wikipedia.org/wiki/%E6%9C%88%E6%9B%9C%E6%97%A5", Term3.reference('ja_JP'))
104
+ end
105
+
106
+ def test__labels
107
+ assert_equal({""=>"Tokyo"}, Term1.names)
108
+ assert_equal({""=>"Getsuyou", "en"=>"Monday"}, Term2.names)
109
+ # assert_equal({""=>"Monday", "ja"=>"月曜日"}, Term3.names)
110
+ end
111
+
112
+ def test__link
113
+ assert_equal({},Term1.link)
114
+ assert_equal({""=>"http://ja.wikipedia.org/wiki/Getsuyou",
115
+ "en"=>"http://en.wikipedia.org/wiki/Monday"}, Term2.link)
116
+ assert_equal({"ja"=>"http://ja.wikipedia.org/wiki/%E6%9C%88%E6%9B%9C%E6%97%A5",
117
+ ""=>"http://en.wikipedia.org/wiki/Monday"}, Term3.link)
118
+ end
119
+
120
+ def test__prefix
121
+ date = When.when?('0594-09=12^Japanese')
122
+ assert_equal(["閏九月", String], [date.name('Month').label.to_s, date.name('Month').label.class])
123
+ assert_equal(["閏九月", String], [date.name('Month').to_s, date.name('Month').to_s.class])
124
+ assert_equal("http://ja.wikipedia.org/wiki/%E9%96%8F", date.name('Month').reference('ja'))
125
+ assert_equal("閏九月", date.name('Month').translate('日本語'))
126
+ assert_equal("閏長月", date.name('Month').translate('alias'))
127
+ assert_equal("Intercalary Month 9", date.name('Month').translate('en_US'))
128
+ end
129
+
130
+ def test__split
131
+ assert_equal(['' ], When::Locale._split(''))
132
+ assert_equal(['3.14' ], When::Locale._split('3.14'))
133
+ assert_equal(['3.14', ''], When::Locale._split('3.14,'))
134
+ assert_equal(['', '3.14'], When::Locale._split(',3.14'))
135
+ assert_equal(['3.14', ' "3.14,159"'], When::Locale._split('3.14, "3.14,159"'))
136
+ assert_equal(['3.14', ' "3.14\\"159"'], When::Locale._split('3.14, "3.14\\"159"'))
137
+ end
138
+ end
139
+
140
+ class Resource < MiniTest::TestCase
141
+ def test_nothing
142
+ end
143
+ end
144
+
145
+ class Enumerator < MiniTest::TestCase
146
+
147
+ def test_nothing
148
+ end
149
+
150
+ class Array < MiniTest::TestCase
151
+ def test_nothing
152
+ end
153
+ end
154
+
155
+ class Integrated < MiniTest::TestCase
156
+ def test_nothing
157
+ end
158
+ end
159
+ end
160
+
161
+ class GeometricComplex < MiniTest::TestCase
162
+
163
+ def test__include
164
+
165
+ sample = [false, false, false, false, false]
166
+ complex = When::Parts::GeometricComplex.new(false)
167
+ assert_equal(nil, complex.exclude_end?)
168
+ (1..5).each do |i|
169
+ assert_equal(sample.shift, complex.include?(i))
170
+ end
171
+
172
+ sample = [true, true, true, true, true]
173
+ complex = When::Parts::GeometricComplex.new(true)
174
+ assert_equal(nil, complex.exclude_end?)
175
+ (1..5).each do |i|
176
+ assert_equal(sample.shift, complex.include?(i))
177
+ end
178
+
179
+ sample = [false, true, true, true, false]
180
+ complex = When::Parts::GeometricComplex.new(2..4)
181
+ assert_equal(false, complex.exclude_end?)
182
+ (1..5).each do |i|
183
+ assert_equal(sample.shift, complex.include?(i))
184
+ end
185
+
186
+ sample = [false, true, true, false, false]
187
+ complex = When::Parts::GeometricComplex.new(2...4)
188
+ assert_equal(true, complex.exclude_end?)
189
+ (1..5).each do |i|
190
+ assert_equal(sample.shift, complex.include?(i))
191
+ end
192
+
193
+ sample = [true, false, false, false, true]
194
+ complex = -When::Parts::GeometricComplex.new(2..4)
195
+ assert_equal(true, complex.exclude_end?)
196
+ (1..5).each do |i|
197
+ assert_equal(sample.shift, complex.include?(i))
198
+ end
199
+
200
+ sample = [true, false, false, true, true]
201
+ complex = -When::Parts::GeometricComplex.new(2...4)
202
+ assert_equal(false, complex.exclude_end?)
203
+ (1..5).each do |i|
204
+ assert_equal(sample.shift, complex.include?(i))
205
+ end
206
+
207
+ period_1_2 = When::Parts::GeometricComplex.new(1..2)
208
+ period_2_3 = When::Parts::GeometricComplex.new(2..3)
209
+ period_3_4 = When::Parts::GeometricComplex.new(3..4)
210
+ period_4_5 = When::Parts::GeometricComplex.new(4..5)
211
+ period_5_6 = When::Parts::GeometricComplex.new(5..6)
212
+
213
+ period_2_4 = When::Parts::GeometricComplex.new(2..4)
214
+ period_3_6 = When::Parts::GeometricComplex.new(3..6)
215
+ period_4_6 = When::Parts::GeometricComplex.new(4..6)
216
+ period_1_6 = When::Parts::GeometricComplex.new(1..6)
217
+
218
+ [[false, period_1_2, period_4_6],
219
+ [false, period_1_2, period_2_4],
220
+ [false, period_2_4, period_3_6],
221
+ [false, period_2_3, period_2_4],
222
+ [true, period_2_4, period_2_3],
223
+
224
+ [false, period_2_4, period_1_6],
225
+ [true, period_1_6, period_2_4],
226
+ [true, period_2_4, period_2_4],
227
+
228
+ [false, period_3_6, period_2_4],
229
+ [false, period_3_4, period_2_4],
230
+ [true, period_2_4, period_3_4],
231
+ [false, period_4_5, period_2_4],
232
+ [false, period_5_6, period_2_4]].each do |sample|
233
+ assert_equal(sample[0], sample[1].include?(sample[2]))
234
+ end
235
+
236
+ period_1_2 = When::Parts::GeometricComplex.new(1...2)
237
+ period_2_3 = When::Parts::GeometricComplex.new(2...3)
238
+ period_3_4 = When::Parts::GeometricComplex.new(3...4)
239
+ period_4_5 = When::Parts::GeometricComplex.new(4...5)
240
+ period_5_6 = When::Parts::GeometricComplex.new(5...6)
241
+
242
+ period_2_4 = When::Parts::GeometricComplex.new(2...4)
243
+ period_3_6 = When::Parts::GeometricComplex.new(3...6)
244
+ period_4_6 = When::Parts::GeometricComplex.new(4...6)
245
+ period_1_6 = When::Parts::GeometricComplex.new(1...6)
246
+
247
+ [[false, period_1_2, period_4_6],
248
+ [false, period_1_2, period_2_4],
249
+ [false, period_2_4, period_3_6],
250
+ [false, period_2_3, period_2_4],
251
+ [true, period_2_4, period_2_3],
252
+
253
+ [false, period_2_4, period_1_6],
254
+ [true, period_1_6, period_2_4],
255
+ [true, period_2_4, period_2_4],
256
+
257
+ [false, period_3_6, period_2_4],
258
+ [false, period_3_4, period_2_4],
259
+ [true, period_2_4, period_3_4],
260
+ [false, period_4_5, period_2_4],
261
+ [false, period_5_6, period_2_4]].each do |sample|
262
+ assert_equal(sample[0], sample[1].include?(sample[2]))
263
+ end
264
+
265
+ period_1_2 = -When::Parts::GeometricComplex.new(1..2)
266
+ period_2_3 = -When::Parts::GeometricComplex.new(2..3)
267
+ period_3_4 = -When::Parts::GeometricComplex.new(3..4)
268
+ period_4_5 = -When::Parts::GeometricComplex.new(4..5)
269
+ period_5_6 = -When::Parts::GeometricComplex.new(5..6)
270
+
271
+ period_2_4 = -When::Parts::GeometricComplex.new(2..4)
272
+ period_3_6 = -When::Parts::GeometricComplex.new(3..6)
273
+ period_4_6 = -When::Parts::GeometricComplex.new(4..6)
274
+ period_1_6 = -When::Parts::GeometricComplex.new(1..6)
275
+
276
+ [[false, period_4_6, period_1_2],
277
+ [false, period_2_4, period_1_2],
278
+ [false, period_3_6, period_2_4],
279
+ [false, period_2_4, period_2_3],
280
+ [true, period_2_3, period_2_4],
281
+
282
+ [false, period_1_6, period_2_4],
283
+ [true, period_2_4, period_1_6],
284
+ [true, period_2_4, period_2_4],
285
+
286
+ [false, period_2_4, period_3_6],
287
+ [false, period_2_4, period_3_4],
288
+ [true, period_3_4, period_2_4],
289
+ [false, period_2_4, period_4_5],
290
+ [false, period_2_4, period_5_6]].each do |sample|
291
+ assert_equal(sample[0], sample[1].include?(sample[2]))
292
+ end
293
+
294
+ period_1_2 = -When::Parts::GeometricComplex.new(1...2)
295
+ period_2_3 = -When::Parts::GeometricComplex.new(2...3)
296
+ period_3_4 = -When::Parts::GeometricComplex.new(3...4)
297
+ period_4_5 = -When::Parts::GeometricComplex.new(4...5)
298
+ period_5_6 = -When::Parts::GeometricComplex.new(5...6)
299
+
300
+ period_2_4 = -When::Parts::GeometricComplex.new(2...4)
301
+ period_3_6 = -When::Parts::GeometricComplex.new(3...6)
302
+ period_4_6 = -When::Parts::GeometricComplex.new(4...6)
303
+ period_1_6 = -When::Parts::GeometricComplex.new(1...6)
304
+
305
+ [[false, period_4_6, period_1_2],
306
+ [false, period_2_4, period_1_2],
307
+ [false, period_3_6, period_2_4],
308
+ [false, period_2_4, period_2_3],
309
+ [true, period_2_3, period_2_4],
310
+
311
+ [false, period_1_6, period_2_4],
312
+ [true, period_2_4, period_1_6],
313
+ [true, period_2_4, period_2_4],
314
+
315
+ [false, period_2_4, period_3_6],
316
+ [false, period_2_4, period_3_4],
317
+ [true, period_3_4, period_2_4],
318
+ [false, period_2_4, period_4_5],
319
+ [false, period_2_4, period_5_6]].each do |sample|
320
+ assert_equal(sample[0], sample[1].include?(sample[2]))
321
+ end
322
+ end
323
+
324
+ def test__union
325
+
326
+ sample = [false, true, false, true, true, false]
327
+ complex = When::Parts::GeometricComplex.new(3..4)
328
+ complex |= 1
329
+ (0..5).each do |i|
330
+ assert_equal(sample.shift, complex.include?(i))
331
+ end
332
+
333
+ sample = [true, false, true, false, false, true]
334
+ complex = When::Parts::GeometricComplex.new(3..4)
335
+ complex |= 1
336
+ complex = -complex
337
+ (0..5).each do |i|
338
+ assert_equal(sample.shift, complex.include?(i))
339
+ end
340
+
341
+ sample = [false, true, false, true, false, false]
342
+ complex = When::Parts::GeometricComplex.new(3...4)
343
+ complex |= 1
344
+ (0..5).each do |i|
345
+ assert_equal(sample.shift, complex.include?(i))
346
+ end
347
+
348
+ sample = [true, false, true, false, true, true]
349
+ complex = When::Parts::GeometricComplex.new(3...4)
350
+ complex |= 1
351
+ complex = -complex
352
+ (0..5).each do |i|
353
+ assert_equal(sample.shift, complex.include?(i))
354
+ end
355
+
356
+ complex = When::Parts::GeometricComplex.new(3..5)
357
+ (3..5).each do |i|
358
+ union = complex | i
359
+ assert_equal(complex, union)
360
+ end
361
+
362
+ assert_equal(When::Parts::GeometricComplex.new(3..5),
363
+ When::Parts::GeometricComplex.new(3...5) | 5)
364
+
365
+ null = When::Parts::GeometricComplex.new(false)
366
+ all = When::Parts::GeometricComplex.new(true)
367
+ period_1_2 = When::Parts::GeometricComplex.new(1..2)
368
+ period_2_3 = When::Parts::GeometricComplex.new(2..3)
369
+ period_3_4 = When::Parts::GeometricComplex.new(3..4)
370
+ period_4_5 = When::Parts::GeometricComplex.new(4..5)
371
+ period_5_6 = When::Parts::GeometricComplex.new(5..6)
372
+
373
+ period_1_4 = When::Parts::GeometricComplex.new(1..4)
374
+ period_2_4 = When::Parts::GeometricComplex.new(2..4)
375
+ period_2_5 = When::Parts::GeometricComplex.new(2..5)
376
+ period_2_6 = When::Parts::GeometricComplex.new(2..6)
377
+ period_3_6 = When::Parts::GeometricComplex.new(3..6)
378
+ period_4_6 = When::Parts::GeometricComplex.new(4..6)
379
+ period_1_6 = When::Parts::GeometricComplex.new(1..6)
380
+
381
+ period_1_2_4_6 = When::Parts::GeometricComplex.new([[1,true],[2,true],[4,true],[6,true]])
382
+ period_2_4_5_6 = When::Parts::GeometricComplex.new([[2,true],[4,true],[5,true],[6,true]])
383
+
384
+ [[period_1_2_4_6, null, period_1_2_4_6],
385
+ [period_1_2_4_6, period_1_2_4_6, null],
386
+ [all, all, period_1_2_4_6],
387
+ [all, period_1_2_4_6, all],
388
+ [period_1_2_4_6, period_1_2, period_4_6],
389
+ [period_1_4, period_1_2, period_2_4],
390
+ [period_2_6, period_2_4, period_3_6],
391
+ [period_2_4, period_2_3, period_2_4],
392
+ [period_2_4, period_2_4, period_2_3],
393
+
394
+ [period_1_6, period_2_4, period_1_6],
395
+ [period_1_6, period_1_6, period_2_4],
396
+ [period_2_4, period_2_4, period_2_4],
397
+
398
+ [period_2_6, period_3_6, period_2_4],
399
+ [period_2_4, period_3_4, period_2_4],
400
+ [period_2_4, period_2_4, period_3_4],
401
+ [period_2_5, period_4_5, period_2_4],
402
+ [period_2_4_5_6, period_5_6, period_2_4]].each do |sample|
403
+ assert_equal(sample[0], sample[1] | sample[2])
404
+ end
405
+
406
+ period_1_2 = When::Parts::GeometricComplex.new(1...2)
407
+ period_2_3 = When::Parts::GeometricComplex.new(2...3)
408
+ period_3_4 = When::Parts::GeometricComplex.new(3...4)
409
+ period_4_5 = When::Parts::GeometricComplex.new(4...5)
410
+ period_5_6 = When::Parts::GeometricComplex.new(5...6)
411
+
412
+ period_1_4 = When::Parts::GeometricComplex.new(1...4)
413
+ period_2_4 = When::Parts::GeometricComplex.new(2...4)
414
+ period_2_5 = When::Parts::GeometricComplex.new(2...5)
415
+ period_2_6 = When::Parts::GeometricComplex.new(2...6)
416
+ period_3_6 = When::Parts::GeometricComplex.new(3...6)
417
+ period_4_6 = When::Parts::GeometricComplex.new(4...6)
418
+ period_1_6 = When::Parts::GeometricComplex.new(1...6)
419
+
420
+ period_1_2_4_6 = When::Parts::GeometricComplex.new([[1,true],[2,false],[4,true],[6,false]])
421
+ period_2_4_5_6 = When::Parts::GeometricComplex.new([[2,true],[4,false],[5,true],[6,false]])
422
+
423
+ [[period_1_2_4_6, null, period_1_2_4_6],
424
+ [period_1_2_4_6, period_1_2_4_6, null],
425
+ [all, all, period_1_2_4_6],
426
+ [all, period_1_2_4_6, all],
427
+ [period_1_2_4_6, period_1_2, period_4_6],
428
+ [period_1_4, period_1_2, period_2_4],
429
+ [period_2_6, period_2_4, period_3_6],
430
+ [period_2_4, period_2_3, period_2_4],
431
+ [period_2_4, period_2_4, period_2_3],
432
+
433
+ [period_1_6, period_2_4, period_1_6],
434
+ [period_1_6, period_1_6, period_2_4],
435
+ [period_2_4, period_2_4, period_2_4],
436
+
437
+ [period_2_6, period_3_6, period_2_4],
438
+ [period_2_4, period_3_4, period_2_4],
439
+ [period_2_4, period_2_4, period_3_4],
440
+ [period_2_5, period_4_5, period_2_4],
441
+ [period_2_4_5_6, period_5_6, period_2_4]].each do |sample|
442
+ assert_equal(sample[0], sample[1] | sample[2])
443
+ end
444
+ end
445
+
446
+ def test__include_in_sample
447
+ range_1_4 = When::Parts::GeometricComplex.new(1,4)
448
+ range_2_2 = When::Parts::GeometricComplex.new(2)
449
+ range_2_3 = When::Parts::GeometricComplex.new(2,3)
450
+ range_2_5 = When::Parts::GeometricComplex.new(2,5)
451
+ range_4_4 = When::Parts::GeometricComplex.new(4)
452
+ assert_equal(true, range_1_4.include?(range_2_2))
453
+ assert_equal(true, range_1_4.include?(range_2_3))
454
+ assert_equal(false, range_1_4.include?(range_2_5))
455
+ assert_equal(false, range_1_4.include?(range_4_4))
456
+ end
457
+
458
+ def test__union_in_sample
459
+ #range_null = When::Parts::GeometricComplex.new()
460
+ #range_1_1 = When::Parts::GeometricComplex.new(1)
461
+ range_1_4 = When::Parts::GeometricComplex.new(1,4)
462
+ range_2_2 = When::Parts::GeometricComplex.new(2)
463
+ range_2_3 = When::Parts::GeometricComplex.new(2,3)
464
+ range_2_5 = When::Parts::GeometricComplex.new(2,5)
465
+ range_4_4 = When::Parts::GeometricComplex.new(4)
466
+ assert_equal("1...4", range_1_4.to_s)
467
+ assert_equal("2...3", range_2_3.to_s)
468
+ sample = [1, 2, 3]
469
+ range_1_4.each {|x| assert_equal(sample.shift, x)}
470
+ assert_equal("4..4", range_4_4.to_s)
471
+ assert_equal("1...4", (range_1_4 | range_2_3).to_s)
472
+ range_1_5 = range_1_4 | range_2_5
473
+ assert_equal("1...5", range_1_5.to_s)
474
+ assert_equal("1..4", (range_1_4 | range_4_4).to_s)
475
+ reverse_all = When::Parts::GeometricComplex.new(true)
476
+ reverse_1_4 = When::Parts::GeometricComplex.new(1,4, true)
477
+ reverse_2_3 = When::Parts::GeometricComplex.new(2,3, true)
478
+ reverse_2_5 = When::Parts::GeometricComplex.new(2,5, true)
479
+ assert_equal("1..4", reverse_1_4.to_s)
480
+ assert_equal("2..3", reverse_2_3.to_s)
481
+ unless Float::INFINITY == Float::MAX
482
+ assert_equal("-Infinity..Infinity", reverse_all.to_s)
483
+ assert_equal("-Infinity..Infinity", (reverse_2_3 | range_2_3).to_s)
484
+ end
485
+ assert_equal("1..2", (reverse_1_4 | range_2_5).to_s)
486
+ end
487
+ end
488
+ end