when_exe 0.4.2 → 0.4.3

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 (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
@@ -1,86 +1,86 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
- Copyright (C) 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 MiniTest::CalendarNote
10
-
11
- class NotesContainer < MiniTest::TestCase
12
-
13
- def test__lunar_phases
14
- assert_equal([[{:note=>"月相", :value=>"朔(-233/3040)", :position=>"中段"}]],
15
- When.when?('承和2.4.2').notes(:notes=>'月相', :conditions=>{:shoyo=>true}))
16
- assert_equal([[{:note=>"月相", :value=>"望(1478.5/3040)", :position=>"中段"}]],
17
- When.when?('承和2.4.16').notes(:notes=>'月相', :conditions=>{:shoyo=>true}))
18
- all = {}
19
- assert_equal([[{:note=>"月相", :value=>"望(1478.5/3040)", :position=>"中段"}]],
20
- When.when?('承和2.4.16').notes(:notes=>'月相', :shoyo=>true, :persistence=>all))
21
- assert_equal({2026177=>[[{:note=>"月相", :value=>"望(1478.5/3040)", :position=>"中段"}]]}, all)
22
- end
23
-
24
- def test__solar_terms
25
- term = When.CalendarNote('SolarTerms').copy('term315')
26
- assert_equal('2014-02-03', term.term(When.when?('2014-1-1')).to_s)
27
- end
28
-
29
- def test__persistence
30
- all = {}
31
- notes0 = When.when?('平成25.9.22').notes(:persistence=>all)
32
- notes1 = When.when?('平成25.9.23').notes(:persistence=>all)
33
- notes2 = When.when?('平成25.9.24').notes(:persistence=>all)
34
- notes3 = When.when?('平成25.9.23').notes(:persistence=>all)
35
-
36
- [notes1, notes3].each do |notes|
37
- assert_equal(
38
- [[{:note=>"干支", :value=>"癸巳(29)", :position=>"共通"}],
39
- [{:note=>"月名", :value=>"September", :position=>"月建"}],
40
- [{:note=>"七曜", :value=>"Monday(0)", :position=>"共通"},
41
- {:note=>"干支", :value=>"壬辰(28)", :position=>"共通"},
42
- {:note=>"六曜", :value=>"友引", :position=>"民間"},
43
- {:note=>"廿四節気", :value=>"秋分(180)", :position=>"時候"},
44
- {:note=>"祝祭日", :value=>"秋分の日", :position=>"祝祭日"}]], notes)
45
- end
46
-
47
- assert_equal([["癸巳(29)"], ["September"], ["Monday(0)", "壬辰(28)", "友引", "秋分(180)", "秋分の日"]],
48
- notes1.simplify[:value])
49
-
50
- assert_equal([[{:note=>"月名", :value=>"September", :position=>"月建"}]], notes1.subset(:note=>/Month/))
51
- assert_equal([[{:note=>"干支", :value=>"癸巳(29)", :position=>"共通"}],
52
- [{:note=>"干支", :value=>"壬辰(28)", :position=>"共通"}]], notes1.subset(:note=>'干支'))
53
- assert_equal([[{:note=>"祝祭日", :value=>"秋分の日", :position=>"祝祭日"}]], notes1.subset(:value=>'秋分の日'))
54
- assert_equal(nil, notes1.subset(:value=>'春分の日'))
55
- assert_equal([[nil], [nil], [nil, nil, nil, nil, nil]], notes1.subset({:value=>'春分の日'}, false))
56
-
57
- assert_equal([2456558, 2456559, 2456560], all.keys)
58
- assert_equal({2456559=>"秋分の日"}, all.subset(:value=>'秋分の日').simplify[:value])
59
- end
60
-
61
- def test__holiday
62
- date1 = When.when?('平成25.9.23')
63
- date2 = When.when?('平成25.9.24')
64
- notes1 = date1.notes("祝祭日")
65
- assert_equal([[{:note=>"祝祭日", :value=>"秋分の日", :position=>"祝祭日"}]], notes1)
66
- assert_equal({:note=>"祝祭日", :value=>"秋分の日", :position=>"祝祭日"}, notes1.simplify)
67
- assert_equal(true, date1.is?({:note=>"祝祭日", :value=>"秋分の日"}))
68
- assert_equal(true, date1.is?("祝祭日"))
69
- assert_equal(true, date1.is?("秋分の日"))
70
- assert_equal(false, date2.is?("秋分の日"))
71
-
72
- note = When.CalendarNote('Japanese')
73
- assert_equal(true, note.note?(When.when?('2014-9-15'), '祝祭日'))
74
- assert_equal(true, note.note?(When.when?('2014-9-15'), {:notes=>'祝祭日', :value=>'敬老の日'}))
75
- assert_equal(false, note.note?(When.when?('2014-9-15'), {:notes=>'祝祭日', :value=>'敬老日'}))
76
- assert_equal('敬老の日', note.notes(When.when?('2014-9-15'), '祝祭日')[:value].simplify.to_s)
77
-
78
- assert_equal('五黄土星(4)', note.notes(When.when?('2014-1-1'), {:notes=>[['九星'],[],[]], :indices=>-2})[:value].simplify.to_s)
79
- assert_equal('一白水星(8)', note.notes(When.when?('2014-1-1'), {:notes=>[[],['九星'],[]], :indices=>-1})[:value].simplify.to_s)
80
- assert_equal('九紫火星(0)', note.notes(When.when?('2014-1-1'), {:notes=>'九星', :indices=> 0})[:value].simplify.to_s)
81
-
82
- assert_equal(true, When.CalendarNote('Christian').copy('christmas').include?(When.when?('2012-12-25')))
83
- end
84
- end
85
- end
86
-
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 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 MiniTest::CalendarNote
10
+
11
+ class NotesContainer < MiniTest::TestCase
12
+
13
+ def test__lunar_phases
14
+ assert_equal([[{:note=>"月相", :value=>"朔(-233/3040)", :position=>"中段"}]],
15
+ When.when?('承和2.4.2').notes(:notes=>'月相', :conditions=>{:shoyo=>true}))
16
+ assert_equal([[{:note=>"月相", :value=>"望(1478.5/3040)", :position=>"中段"}]],
17
+ When.when?('承和2.4.16').notes(:notes=>'月相', :conditions=>{:shoyo=>true}))
18
+ all = {}
19
+ assert_equal([[{:note=>"月相", :value=>"望(1478.5/3040)", :position=>"中段"}]],
20
+ When.when?('承和2.4.16').notes(:notes=>'月相', :shoyo=>true, :persistence=>all))
21
+ assert_equal({2026177=>[[{:note=>"月相", :value=>"望(1478.5/3040)", :position=>"中段"}]]}, all)
22
+ end
23
+
24
+ def test__solar_terms
25
+ term = When.CalendarNote('SolarTerms').copy('term315')
26
+ assert_equal('2014-02-03', term.term(When.when?('2014-1-1')).to_s)
27
+ end
28
+
29
+ def test__persistence
30
+ all = {}
31
+ notes0 = When.when?('平成25.9.22').notes(:persistence=>all)
32
+ notes1 = When.when?('平成25.9.23').notes(:persistence=>all)
33
+ notes2 = When.when?('平成25.9.24').notes(:persistence=>all)
34
+ notes3 = When.when?('平成25.9.23').notes(:persistence=>all)
35
+
36
+ [notes1, notes3].each do |notes|
37
+ assert_equal(
38
+ [[{:note=>"干支", :value=>"癸巳(29)", :position=>"共通"}],
39
+ [{:note=>"月名", :value=>"September", :position=>"月建"}],
40
+ [{:note=>"七曜", :value=>"Monday(0)", :position=>"共通"},
41
+ {:note=>"干支", :value=>"壬辰(28)", :position=>"共通"},
42
+ {:note=>"六曜", :value=>"友引", :position=>"民間"},
43
+ {:note=>"廿四節気", :value=>"秋分(180)", :position=>"時候"},
44
+ {:note=>"祝祭日", :value=>"秋分の日", :position=>"祝祭日"}]], notes)
45
+ end
46
+
47
+ assert_equal([["癸巳(29)"], ["September"], ["Monday(0)", "壬辰(28)", "友引", "秋分(180)", "秋分の日"]],
48
+ notes1.simplify[:value])
49
+
50
+ assert_equal([[{:note=>"月名", :value=>"September", :position=>"月建"}]], notes1.subset(:note=>/Month/))
51
+ assert_equal([[{:note=>"干支", :value=>"癸巳(29)", :position=>"共通"}],
52
+ [{:note=>"干支", :value=>"壬辰(28)", :position=>"共通"}]], notes1.subset(:note=>'干支'))
53
+ assert_equal([[{:note=>"祝祭日", :value=>"秋分の日", :position=>"祝祭日"}]], notes1.subset(:value=>'秋分の日'))
54
+ assert_equal(nil, notes1.subset(:value=>'春分の日'))
55
+ assert_equal([[nil], [nil], [nil, nil, nil, nil, nil]], notes1.subset({:value=>'春分の日'}, false))
56
+
57
+ assert_equal([2456558, 2456559, 2456560], all.keys)
58
+ assert_equal({2456559=>"秋分の日"}, all.subset(:value=>'秋分の日').simplify[:value])
59
+ end
60
+
61
+ def test__holiday
62
+ date1 = When.when?('平成25.9.23')
63
+ date2 = When.when?('平成25.9.24')
64
+ notes1 = date1.notes("祝祭日")
65
+ assert_equal([[{:note=>"祝祭日", :value=>"秋分の日", :position=>"祝祭日"}]], notes1)
66
+ assert_equal({:note=>"祝祭日", :value=>"秋分の日", :position=>"祝祭日"}, notes1.simplify)
67
+ assert_equal(true, date1.is?({:note=>"祝祭日", :value=>"秋分の日"}))
68
+ assert_equal(true, date1.is?("祝祭日"))
69
+ assert_equal(true, date1.is?("秋分の日"))
70
+ assert_equal(false, date2.is?("秋分の日"))
71
+
72
+ note = When.CalendarNote('Japanese')
73
+ assert_equal(true, note.note?(When.when?('2014-9-15'), '祝祭日'))
74
+ assert_equal(true, note.note?(When.when?('2014-9-15'), {:notes=>'祝祭日', :value=>'敬老の日'}))
75
+ assert_equal(false, note.note?(When.when?('2014-9-15'), {:notes=>'祝祭日', :value=>'敬老日'}))
76
+ assert_equal('敬老の日', note.notes(When.when?('2014-9-15'), '祝祭日')[:value].simplify.to_s)
77
+
78
+ assert_equal('五黄土星(4)', note.notes(When.when?('2014-1-1'), {:notes=>[['九星'],[],[]], :indices=>-2})[:value].simplify.to_s)
79
+ assert_equal('一白水星(8)', note.notes(When.when?('2014-1-1'), {:notes=>[[],['九星'],[]], :indices=>-1})[:value].simplify.to_s)
80
+ assert_equal('九紫火星(0)', note.notes(When.when?('2014-1-1'), {:notes=>'九星', :indices=> 0})[:value].simplify.to_s)
81
+
82
+ assert_equal(true, When.CalendarNote('Christian').copy('christmas').include?(When.when?('2012-12-25')))
83
+ end
84
+ end
85
+ end
86
+
@@ -1,97 +1,97 @@
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 MiniTest::CalendarTypes
10
-
11
- class UTC < MiniTest::TestCase
12
- def test__utc
13
- assert_equal("+00:00", When::UTC.tzname[0].to_s)
14
- end
15
- end
16
-
17
- class TableBased < MiniTest::TestCase
18
- def test_nothing
19
- end
20
- end
21
-
22
- class PatternTableBasedLuniSolar < MiniTest::TestCase
23
- def test__japanese
24
-
25
- frame = When.Resource('Japanese', '_c:')
26
- date = When.when?('16000101^Japanese')
27
- assert_equal(["1600-01-01", 2305493], [date.to_s, date.to_i])
28
- assert_equal(2305493, frame._coordinates_to_number(1600-454,0,0))
29
- assert_equal([1146, 0, 0], frame._number_to_coordinates(2305493))
30
-
31
- date = When.when?('0594-09=12^Japanese')
32
- assert_equal(["0594-09=12", 1938320], [date.to_s, date.to_i])
33
- assert_equal(594, date['YEAR'])
34
- assert_equal(When::BasicTypes::M17n, date.name('Month').class)
35
-
36
- result = []
37
- (date ^ When::TM::Calendar).each do |d|
38
- result << d.to_s
39
- end
40
- result.sort!
41
-
42
- sample = ["0594-09=12", "0594-11-02", "0594-11-02"] #TODO �Ȃ� Greg 2��?
43
- # assert_equal(sample, result)
44
- end
45
- end
46
-
47
- class CyclicTableBased < MiniTest::TestCase
48
- def test__islamic
49
- frame = When.Resource('_c:TabularIslamic')
50
- date = When.when?('00010101^TabularIslamic')
51
- assert_equal(["0001-01-01", 1948440], [date.to_s, date.to_i])
52
- assert_equal(1959071, frame._coordinates_to_number(31,0,0))
53
- assert_equal([31, 0, 0], frame._number_to_coordinates(1948440+10631))
54
- end
55
- end
56
-
57
- class SolarTerms < MiniTest::TestCase
58
-
59
- Sample = %w(2013-03-20 2013-06-21 2013-09-23 2013-12-22
60
- 2014-03-21 2014-06-21 2014-09-23 2014-12-22
61
- 2015-03-21 2015-06-22 2015-09-23 2015-12-22)
62
-
63
- def test__term
64
- note = When.CalendarNote('SolarTerms')
65
- assert_equal('2014-03-20', note.term(When.when?('2014-3-1'), [0,30]).to_s)
66
- When::TM::Clock.local_time = '+09:00'
67
- assert_equal('2014-03-21', note.term(When.when?('2014-3-1'), [0,30]).to_s)
68
- end
69
-
70
- def test__each
71
- When::TM::Clock.local_time = '+09:00'
72
- note = When.CalendarNote('SolarTerms')
73
- note_with_event = When.CalendarNote('SolarTerms?event=term0/90')
74
- today = When.when?('2013-03-01')
75
- last = When.when?('2016-01-01')
76
-
77
- sample = Sample.dup
78
- note_with_event.each(today) do |date|
79
- assert_equal(sample.shift, date.to_s)
80
- break if sample.empty?
81
- end
82
-
83
- sample = Sample.dup
84
- note_with_event.each(today...last) do |date|
85
- assert_equal(sample.shift, date.to_s)
86
- end
87
- assert_equal(true, sample.empty?)
88
-
89
- sample = Sample.dup
90
- note.each(today...last, {:event=>'term0/90', :count_limit=>4}) do |date|
91
- assert_equal(sample.shift, date.to_s)
92
- end
93
- assert_equal(Sample.length - 4, sample.length)
94
- end
95
- end
96
- end
97
-
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 MiniTest::CalendarTypes
10
+
11
+ class UTC < MiniTest::TestCase
12
+ def test__utc
13
+ assert_equal("+00:00", When::UTC.tzname[0].to_s)
14
+ end
15
+ end
16
+
17
+ class TableBased < MiniTest::TestCase
18
+ def test_nothing
19
+ end
20
+ end
21
+
22
+ class PatternTableBasedLuniSolar < MiniTest::TestCase
23
+ def test__japanese
24
+
25
+ frame = When.Resource('Japanese', '_c:')
26
+ date = When.when?('16000101^Japanese')
27
+ assert_equal(["1600-01-01", 2305493], [date.to_s, date.to_i])
28
+ assert_equal(2305493, frame._coordinates_to_number(1600-454,0,0))
29
+ assert_equal([1146, 0, 0], frame._number_to_coordinates(2305493))
30
+
31
+ date = When.when?('0594-09=12^Japanese')
32
+ assert_equal(["0594-09=12", 1938320], [date.to_s, date.to_i])
33
+ assert_equal(594, date['YEAR'])
34
+ assert_equal(When::BasicTypes::M17n, date.name('Month').class)
35
+
36
+ result = []
37
+ (date ^ When::TM::Calendar).each do |d|
38
+ result << d.to_s
39
+ end
40
+ result.sort!
41
+
42
+ sample = ["0594-09=12", "0594-11-02", "0594-11-02"] #TODO �Ȃ� Greg 2��?
43
+ # assert_equal(sample, result)
44
+ end
45
+ end
46
+
47
+ class CyclicTableBased < MiniTest::TestCase
48
+ def test__islamic
49
+ frame = When.Resource('_c:TabularIslamic')
50
+ date = When.when?('00010101^TabularIslamic')
51
+ assert_equal(["0001-01-01", 1948440], [date.to_s, date.to_i])
52
+ assert_equal(1959071, frame._coordinates_to_number(31,0,0))
53
+ assert_equal([31, 0, 0], frame._number_to_coordinates(1948440+10631))
54
+ end
55
+ end
56
+
57
+ class SolarTerms < MiniTest::TestCase
58
+
59
+ Sample = %w(2013-03-20 2013-06-21 2013-09-23 2013-12-22
60
+ 2014-03-21 2014-06-21 2014-09-23 2014-12-22
61
+ 2015-03-21 2015-06-22 2015-09-23 2015-12-22)
62
+
63
+ def test__term
64
+ note = When.CalendarNote('SolarTerms')
65
+ assert_equal('2014-03-20', note.term(When.when?('2014-3-1'), [0,30]).to_s)
66
+ When::TM::Clock.local_time = '+09:00'
67
+ assert_equal('2014-03-21', note.term(When.when?('2014-3-1'), [0,30]).to_s)
68
+ end
69
+
70
+ def test__each
71
+ When::TM::Clock.local_time = '+09:00'
72
+ note = When.CalendarNote('SolarTerms')
73
+ note_with_event = When.CalendarNote('SolarTerms?event=term0/90')
74
+ today = When.when?('2013-03-01')
75
+ last = When.when?('2016-01-01')
76
+
77
+ sample = Sample.dup
78
+ note_with_event.each(today) do |date|
79
+ assert_equal(sample.shift, date.to_s)
80
+ break if sample.empty?
81
+ end
82
+
83
+ sample = Sample.dup
84
+ note_with_event.each(today...last) do |date|
85
+ assert_equal(sample.shift, date.to_s)
86
+ end
87
+ assert_equal(true, sample.empty?)
88
+
89
+ sample = Sample.dup
90
+ note.each(today...last, {:event=>'term0/90', :count_limit=>4}) do |date|
91
+ assert_equal(sample.shift, date.to_s)
92
+ end
93
+ assert_equal(Sample.length - 4, sample.length)
94
+ end
95
+ end
96
+ end
97
+
@@ -1,397 +1,397 @@
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 MiniTest::Coordinates
10
-
11
- #
12
- # 剰余類
13
- #
14
- class Residue < MiniTest::TestCase
15
-
16
- def test__intersection
17
- r1 = When::Coordinates::Residue.new(3,10)
18
- r2 = When::Coordinates::Residue.new(5,12)
19
- r3 = When::Coordinates::Residue.new(6,12)
20
- r = r1 & r2
21
- assert_equal([53,60], [r.remainder, r.divisor])
22
- assert_nil(r1 & r3)
23
-
24
- r4 = When::Coordinates::Residue.new(2,7)
25
- date1 = When.when?(2440587.5)
26
- assert_equal(2440593.5, (date1 & r4).to_f)
27
-
28
- r5 = When::Coordinates::Residue.new(3,7)
29
- date2 = When.when?("19820606^^Julian")
30
- assert_equal("1982-06-11", (date2 & r5).to_s)
31
- assert_equal("1982-06-11", (r5 & date2).to_s)
32
-
33
- assert_equal("1982-06-10T00:00:00.00Z", (r5 & Time.utc(1982,6,6)).to_s)
34
- if ::Object.const_defined?(:Date) && Date.respond_to?(:civil)
35
- assert_equal("1982-06-24", (r5 & Date.new(1982,6,6,Date::JULIAN)).to_s)
36
- end
37
-
38
- date3 = When.when?("19820606T021540+0900^^Julian")
39
- [[-5, "1979-06-06T02:15:40+09:00"],
40
- [-4, "1980-06-06T02:15:40+09:00"],
41
- [-3, "1981-06-06T02:15:40+09:00"],
42
- [-2, "1922-06-06T02:15:40+09:00"],
43
- [-1, "1923-06-06T02:15:40+09:00"],
44
- [ 0, "1984-06-06T02:15:40+09:00"],
45
- [ 1, "1985-06-06T02:15:40+09:00"],
46
- [ 2, "1986-06-06T02:15:40+09:00"],
47
- [ 3, "1987-06-06T02:15:40+09:00"],
48
- [ 4, "1988-06-06T02:15:40+09:00"],
49
- [ 5, "1989-06-06T02:15:40+09:00"]].each do |sample|
50
- r6 = When::Coordinates::Residue.new(sample[0], 60, {'year'=>4})
51
- assert_equal(sample[1], (date3 & r6).to_s)
52
- assert_equal(sample[1], (r6 & date3).to_s)
53
- end
54
-
55
- kanshi = When.Resource("_co:Residue?divisor=60&year=4&day=11")
56
- date = When.when?("19820606T021540+0900^^Julian")
57
- assert_equal("1982-07-27T02:15:40+09:00", (date & kanshi.to('day')).to_s)
58
- assert_equal("1985-06-06T02:15:40+09:00", (date & kanshi.to('year')[1]).to_s)
59
-
60
- week = When.Resource("_co:Residue?divisor=7")
61
- [[0, "1982-06-08T02:15:40+09:00"],
62
- [1, "1982-06-09T02:15:40+09:00"],
63
- [2, "1982-06-10T02:15:40+09:00"],
64
- [3, "1982-06-11T02:15:40+09:00"],
65
- [4, "1982-06-12T02:15:40+09:00"],
66
- [5, "1982-06-06T02:15:40+09:00"],
67
- [6, "1982-06-07T02:15:40+09:00"],
68
- [7, "1982-06-15T02:15:40+09:00"]].each do |sample|
69
- assert_equal(sample[1], (date & week[sample[0]]).to_s)
70
- end
71
- end
72
-
73
- class BestRationalApproximations < MiniTest::TestCase
74
- def test__continued_fraction
75
- it = When.Resource("_co:Residue?remainder=365.2421875&divisor=1").each
76
- [[365, 1], [1461, 4], [10592, 29], [12053, 33], [46751, 128]].each do |ratio|
77
- assert_equal(ratio, it.next[0..1])
78
- end
79
- end
80
- end
81
-
82
- class Enumerator < MiniTest::TestCase
83
- def test_nothing
84
- end
85
- end
86
- end
87
-
88
- # 暦座標番号
89
- class Index < MiniTest::TestCase
90
- def test__trunk
91
- month = When::Coordinates::Index.new({:label=>'month', :unit=>12, :base=>1,
92
- :trunk => %w(January February March April May June July August September October November December).map {|v| When.m17n(v)}})
93
- assert_equal({
94
- 1=>"January",
95
- 2=>"February",
96
- 3=>"March",
97
- 4=>"April",
98
- 5=>"May",
99
- 6=>"June",
100
- 7=>"July",
101
- 8=>"August",
102
- 9=>"September",
103
- 10=>"October",
104
- 11=>"November",
105
- 12=>"December"
106
- }, month.trunk)
107
- end
108
- end
109
-
110
- # 暦座標要素
111
- class Pair < MiniTest::TestCase
112
- def test_nothing
113
- end
114
- end
115
-
116
- class Temporal < MiniTest::TestCase
117
- def test__validate
118
-
119
- midJulian = When.Resource("_c:Julian?border=[0,3,25]")
120
- # assert_equal([0, 3, 25], midJulian.border)
121
-
122
- mDate = When.when?('20100324', {:frame=>midJulian})
123
- assert_equal("2009=03-24", mDate.to_s)
124
-
125
- assert_equal("2010-05-11", When.when?('2010-05-11').to_s)
126
- assert_equal("2010=05-11", When.when?('2010=05-11').to_s)
127
-
128
- date1 =When.when?("M32.01.01")
129
- date2 =When.when?("M34.05.05")
130
- assert_equal("M34(1901).05.05", date2.to_s)
131
- assert_equal("M35(1902).05.05", (date2+When::Duration('P1Y')).to_s)
132
- assert_equal("S06(1931).05.05", (date2+When::Duration('P30Y')).to_s)
133
-
134
- assert_equal(2426467, (date2+When::Duration('P30Y')).to_i)
135
- sample = [
136
- ["ModernJapanese1931.05.05", false],
137
- ["S06(1931).05.05", true]
138
- ]
139
- ((date2+When::Duration('P30Y')).scan(When.Resource('ModernJapanese', '_e:'))).each do |d|
140
- assert_equal(sample.shift, [d.to_s, d.leaf?])
141
- end
142
-
143
- sample = [
144
- ["S06(1931).05.05", true]
145
- ]
146
- ((date2+When::Duration('P30Y'))^When.Resource('ModernJapanese', '_e:')).each do |d|
147
- assert_equal(sample.shift, [d.to_s, d.leaf?])
148
- end
149
-
150
- sample =[
151
- ["明治", "http://ja.wikipedia.org/wiki/%E6%98%8E%E6%B2%BB"],
152
- ["Meiji", "http://en.wikipedia.org/wiki/Meiji_period"],
153
- ["M", "http://ja.wikipedia.org/wiki/%E6%98%8E%E6%B2%BB"],
154
- ["大正", "http://ja.wikipedia.org/wiki/%E5%A4%A7%E6%AD%A3"],
155
- ["Taishō", "http://en.wikipedia.org/wiki/Taish%C5%8D_period"],
156
- ["T", "http://ja.wikipedia.org/wiki/%E5%A4%A7%E6%AD%A3"],
157
- ["昭和", "http://ja.wikipedia.org/wiki/%E6%98%AD%E5%92%8C"],
158
- ["Shōwa", "http://en.wikipedia.org/wiki/Sh%C5%8Dwa_period"],
159
- ["S", "http://ja.wikipedia.org/wiki/%E6%98%AD%E5%92%8C"],
160
- ["平成", "http://ja.wikipedia.org/wiki/%E5%B9%B3%E6%88%90"],
161
- ["Heisei", "http://en.wikipedia.org/wiki/Heisei_period"],
162
- ["H", "http://ja.wikipedia.org/wiki/%E5%B9%B3%E6%88%90"]
163
- ]
164
- ['明治', '大正', '昭和', '平成'].each do |nengo|
165
- era = When::era(nengo)
166
- ['ja', 'en', 'alias'].each do |lang|
167
- assert_equal(sample.shift, [era[0].label.translate(lang), era[0].label.reference(lang)])
168
- end
169
- end
170
-
171
- sample =[
172
- ["明治天皇", "http://ja.wikipedia.org/wiki/%E6%98%8E%E6%B2%BB%E5%A4%A9%E7%9A%87"],
173
- ["Emperor_Meiji", "http://en.wikipedia.org/wiki/Emperor_Meiji"],
174
- ["大正天皇", "http://ja.wikipedia.org/wiki/%E5%A4%A7%E6%AD%A3%E5%A4%A9%E7%9A%87"],
175
- ["Emperor_Taishō", "http://en.wikipedia.org/wiki/Emperor_Taish%C5%8D"],
176
- ["昭和天皇", "http://ja.wikipedia.org/wiki/%E6%98%AD%E5%92%8C%E5%A4%A9%E7%9A%87"],
177
- ["Emperor_Shōwa", "http://en.wikipedia.org/wiki/Emperor_Sh%C5%8Dwa"],
178
- ["今上天皇", "http://ja.wikipedia.org/wiki/%E6%98%8E%E4%BB%81"],
179
- ["Emperor_Kinjō", "http://en.wikipedia.org/wiki/Akihito"]
180
- ]
181
- ['明治', '大正', '昭和', '平成'].each do |nengo|
182
- name = When.when?(nengo + '06.01.01').query['name']
183
- ['ja', 'en'].each do |lang|
184
- assert_equal(sample.shift, [name.translate(lang), name.reference(lang)])
185
- end
186
- end
187
-
188
- assert_equal("昭和02(1927).03.01", When.when?('大正16.2.29').to_s)
189
- assert_equal({"name"=>"大正天皇", "period"=>nil, "area"=>"日本"}, When::era('大正')[0].options)
190
- end
191
- end
192
-
193
- #
194
- # 空間位置
195
- #
196
- class Spatial < MiniTest::TestCase
197
- Indian = [
198
- ["CentralIndia",
199
- "インド中部",
200
- nil,
201
- 23.15 + 1.0/30,
202
- 82.5],
203
- ["NorthIndia",
204
- "インド北部",
205
- nil,
206
- 29.0,
207
- 82.5],
208
- ["Agra",
209
- "アーグラ",
210
- "http://en.wikipedia.org/wiki/Agra",
211
- 27.2,
212
- 78.0],
213
- ["Ahmedabad",
214
- "アフマダーバード",
215
- "http://en.wikipedia.org/wiki/Ahmedabad",
216
- 23.0,
217
- 72.6],
218
- ["Ajmer",
219
- "アジメール",
220
- "http://en.wikipedia.org/wiki/Ajmer",
221
- 26.5,
222
- 74.6],
223
- ["Aligarh",
224
- "アリーガル",
225
- "http://en.wikipedia.org/wiki/Aligarh",
226
- 27.9,
227
- 78.1],
228
- ["Amritsar",
229
- "アムリトサル",
230
- "http://en.wikipedia.org/wiki/Amritsar",
231
- 31.6,
232
- 74.9],
233
- ["Bangalore",
234
- "バンガロール",
235
- "http://en.wikipedia.org/wiki/Bangalore",
236
- 13.0,
237
- 77.6],
238
- ["Bhuvaneswar",
239
- "ブヴァネーシュヴァル",
240
- "http://en.wikipedia.org/wiki/Bhuvaneswar",
241
- 20.2,
242
- 85.8],
243
- ["Chennai",
244
- "チェンナイ",
245
- "http://en.wikipedia.org/wiki/Chennai",
246
- 13.1,
247
- 80.3],
248
- ["Colombo",
249
- "コロンボ",
250
- "http://en.wikipedia.org/wiki/Colombo",
251
- 6.9,
252
- 79.9],
253
- ["Dacca",
254
- "ダッカ",
255
- "http://en.wikipedia.org/wiki/Dacca",
256
- 23.7,
257
- 90.4],
258
- ["Delhi",
259
- "デリー",
260
- "http://en.wikipedia.org/wiki/Delhi",
261
- 28.6,
262
- 77.2],
263
- ["Hyderabad",
264
- "ハイデラバード",
265
- "http://en.wikipedia.org/wiki/Hyderabad",
266
- 17.4,
267
- 78.5],
268
- ["Jaipur",
269
- "ジャイプル",
270
- "http://en.wikipedia.org/wiki/Jaipur",
271
- 26.9,
272
- 75.8],
273
- ["Kathmandu",
274
- "カトマンズ",
275
- "http://en.wikipedia.org/wiki/Kathmandu",
276
- 27.7,
277
- 85.2],
278
- ["Kochi",
279
- "コーチ",
280
- "http://en.wikipedia.org/wiki/Kochi",
281
- 10.0,
282
- 76.2],
283
- ["Kolkata",
284
- "コルカタ",
285
- "http://en.wikipedia.org/wiki/Kolkata",
286
- 22.6,
287
- 88.4],
288
- ["Lahor",
289
- "ラホール",
290
- "http://en.wikipedia.org/wiki/Lahor",
291
- 31.6,
292
- 74.3],
293
- ["Mathura",
294
- "マトゥラー",
295
- "http://en.wikipedia.org/wiki/Mathura",
296
- 27.5,
297
- 77.7],
298
- ["Mumbai",
299
- "ムンバイ",
300
- "http://en.wikipedia.org/wiki/Mumbai",
301
- 19.0,
302
- 72.8],
303
- ["Mysore",
304
- "マイソール",
305
- "http://en.wikipedia.org/wiki/Mysore",
306
- 12.3,
307
- 76.6],
308
- ["Patna",
309
- "パトナ",
310
- "http://en.wikipedia.org/wiki/Patna",
311
- 25.6,
312
- 85.1],
313
- ["Pune",
314
- "プネー",
315
- "http://en.wikipedia.org/wiki/Pune",
316
- 18.5,
317
- 73.9],
318
- ["Srinagar",
319
- "シュリーナガル",
320
- "http://en.wikipedia.org/wiki/Srinagar",
321
- 34.1,
322
- 74.8],
323
- ["Thiruvananthapuram",
324
- "ティルヴァナンタプラム",
325
- "http://en.wikipedia.org/wiki/Thiruvananthapuram",
326
- 8.5,
327
- 77.0],
328
- ["Varanasi",
329
- "ワーラーナシー",
330
- "http://en.wikipedia.org/wiki/Varanasi",
331
- 25.3,
332
- 83.0],
333
- ["Ujjain",
334
- "ウッジャイン",
335
- "http://en.wikipedia.org/wiki/Ujjain",
336
- 23.2,
337
- 75.8]
338
- ]
339
-
340
- def test__inner_representation
341
- location = When.Resource("examples/sample.xml?lat=35&long=135")
342
- assert_equal( 7875.0, location.lat)
343
- assert_equal(30375.0, location.long)
344
- assert_equal( '35.0000N', location.lat_s)
345
- assert_equal('135.0000E', location.long_s)
346
- if Object.const_defined?(:JSON)
347
- location = When.Resource("examples/sample.json?lat=40")
348
- assert_equal( 9000.0, location.lat)
349
- assert_equal(31433.32625, location.long)
350
- assert_equal( '40.0000N', location.lat_s)
351
- assert_equal('139.421322E',location.long_s)
352
- else
353
- puts
354
- puts "Tests for JSON have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
355
- end
356
- end
357
-
358
- def test__reference
359
- location = When.Resource("_co:Spatial?label=Kyoto&long=136&lat=30&ref=(http://)")
360
- assert_equal("http://", location.ref)
361
- end
362
-
363
- def test__surface_radius
364
- location = When.Resource("_co:Spatial?label=Kyoto&long=136&lat=30&ref=(http://)")
365
- assert_equal(6378.14, location.surface_radius)
366
- end
367
-
368
- def test__spatial_m17n
369
- ['_co:Indian', 'examples/Spatial.m17n'].each do |iri|
370
- samples = Indian.dup
371
- assert_equal(samples.size, When.Resource(iri).child.size)
372
- When.Resource(iri).child.each do |obj|
373
- name = obj.label
374
- sample = samples.shift.dup
375
- sample << iri.sub(/_co:/, 'http://hosi.org/When/Coordinates/') + '::' + sample[0]
376
- assert_equal(sample,
377
- [name.label,
378
- name.translate('ja'),
379
- name.reference('en'),
380
- obj.lat / When::Coordinates::Spatial::DEGREE,
381
- obj.long / When::Coordinates::Spatial::DEGREE,
382
- obj.iri])
383
- end
384
- end
385
- end
386
-
387
- def test__to_dms
388
- assert_equal(+135.9, When::Coordinates.to_deg("東経135度54分", 'EW'))
389
- assert_equal(+135.9, When::Coordinates.to_deg("135度54分E", 'EW'))
390
- assert_equal(+135.9, When::Coordinates.to_deg("135.5400E", 'EW'))
391
- assert_equal(+135.9, When::Coordinates.to_deg("E135.5400", 'EW'))
392
- assert_equal("135.5400E", When::Coordinates.to_dms(+135.9, 'EW'))
393
- assert_equal( "35.3936N", When::Coordinates.to_dms(+35.66, 'NS'))
394
- end
395
- end
396
- end
397
-
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 MiniTest::Coordinates
10
+
11
+ #
12
+ # 剰余類
13
+ #
14
+ class Residue < MiniTest::TestCase
15
+
16
+ def test__intersection
17
+ r1 = When::Coordinates::Residue.new(3,10)
18
+ r2 = When::Coordinates::Residue.new(5,12)
19
+ r3 = When::Coordinates::Residue.new(6,12)
20
+ r = r1 & r2
21
+ assert_equal([53,60], [r.remainder, r.divisor])
22
+ assert_nil(r1 & r3)
23
+
24
+ r4 = When::Coordinates::Residue.new(2,7)
25
+ date1 = When.when?(2440587.5)
26
+ assert_equal(2440593.5, (date1 & r4).to_f)
27
+
28
+ r5 = When::Coordinates::Residue.new(3,7)
29
+ date2 = When.when?("19820606^^Julian")
30
+ assert_equal("1982-06-11", (date2 & r5).to_s)
31
+ assert_equal("1982-06-11", (r5 & date2).to_s)
32
+
33
+ assert_equal("1982-06-10T00:00:00.00Z", (r5 & Time.utc(1982,6,6)).to_s)
34
+ if ::Object.const_defined?(:Date) && Date.respond_to?(:civil)
35
+ assert_equal("1982-06-24", (r5 & Date.new(1982,6,6,Date::JULIAN)).to_s)
36
+ end
37
+
38
+ date3 = When.when?("19820606T021540+0900^^Julian")
39
+ [[-5, "1979-06-06T02:15:40+09:00"],
40
+ [-4, "1980-06-06T02:15:40+09:00"],
41
+ [-3, "1981-06-06T02:15:40+09:00"],
42
+ [-2, "1922-06-06T02:15:40+09:00"],
43
+ [-1, "1923-06-06T02:15:40+09:00"],
44
+ [ 0, "1984-06-06T02:15:40+09:00"],
45
+ [ 1, "1985-06-06T02:15:40+09:00"],
46
+ [ 2, "1986-06-06T02:15:40+09:00"],
47
+ [ 3, "1987-06-06T02:15:40+09:00"],
48
+ [ 4, "1988-06-06T02:15:40+09:00"],
49
+ [ 5, "1989-06-06T02:15:40+09:00"]].each do |sample|
50
+ r6 = When::Coordinates::Residue.new(sample[0], 60, {'year'=>4})
51
+ assert_equal(sample[1], (date3 & r6).to_s)
52
+ assert_equal(sample[1], (r6 & date3).to_s)
53
+ end
54
+
55
+ kanshi = When.Resource("_co:Residue?divisor=60&year=4&day=11")
56
+ date = When.when?("19820606T021540+0900^^Julian")
57
+ assert_equal("1982-07-27T02:15:40+09:00", (date & kanshi.to('day')).to_s)
58
+ assert_equal("1985-06-06T02:15:40+09:00", (date & kanshi.to('year')[1]).to_s)
59
+
60
+ week = When.Resource("_co:Residue?divisor=7")
61
+ [[0, "1982-06-08T02:15:40+09:00"],
62
+ [1, "1982-06-09T02:15:40+09:00"],
63
+ [2, "1982-06-10T02:15:40+09:00"],
64
+ [3, "1982-06-11T02:15:40+09:00"],
65
+ [4, "1982-06-12T02:15:40+09:00"],
66
+ [5, "1982-06-06T02:15:40+09:00"],
67
+ [6, "1982-06-07T02:15:40+09:00"],
68
+ [7, "1982-06-15T02:15:40+09:00"]].each do |sample|
69
+ assert_equal(sample[1], (date & week[sample[0]]).to_s)
70
+ end
71
+ end
72
+
73
+ class BestRationalApproximations < MiniTest::TestCase
74
+ def test__continued_fraction
75
+ it = When.Resource("_co:Residue?remainder=365.2421875&divisor=1").each
76
+ [[365, 1], [1461, 4], [10592, 29], [12053, 33], [46751, 128]].each do |ratio|
77
+ assert_equal(ratio, it.next[0..1])
78
+ end
79
+ end
80
+ end
81
+
82
+ class Enumerator < MiniTest::TestCase
83
+ def test_nothing
84
+ end
85
+ end
86
+ end
87
+
88
+ # 暦座標番号
89
+ class Index < MiniTest::TestCase
90
+ def test__trunk
91
+ month = When::Coordinates::Index.new({:label=>'month', :unit=>12, :base=>1,
92
+ :trunk => %w(January February March April May June July August September October November December).map {|v| When.m17n(v)}})
93
+ assert_equal({
94
+ 1=>"January",
95
+ 2=>"February",
96
+ 3=>"March",
97
+ 4=>"April",
98
+ 5=>"May",
99
+ 6=>"June",
100
+ 7=>"July",
101
+ 8=>"August",
102
+ 9=>"September",
103
+ 10=>"October",
104
+ 11=>"November",
105
+ 12=>"December"
106
+ }, month.trunk)
107
+ end
108
+ end
109
+
110
+ # 暦座標要素
111
+ class Pair < MiniTest::TestCase
112
+ def test_nothing
113
+ end
114
+ end
115
+
116
+ class Temporal < MiniTest::TestCase
117
+ def test__validate
118
+
119
+ midJulian = When.Resource("_c:Julian?border=[0,3,25]")
120
+ # assert_equal([0, 3, 25], midJulian.border)
121
+
122
+ mDate = When.when?('20100324', {:frame=>midJulian})
123
+ assert_equal("2009=03-24", mDate.to_s)
124
+
125
+ assert_equal("2010-05-11", When.when?('2010-05-11').to_s)
126
+ assert_equal("2010=05-11", When.when?('2010=05-11').to_s)
127
+
128
+ date1 =When.when?("M32.01.01")
129
+ date2 =When.when?("M34.05.05")
130
+ assert_equal("M34(1901).05.05", date2.to_s)
131
+ assert_equal("M35(1902).05.05", (date2+When::Duration('P1Y')).to_s)
132
+ assert_equal("S06(1931).05.05", (date2+When::Duration('P30Y')).to_s)
133
+
134
+ assert_equal(2426467, (date2+When::Duration('P30Y')).to_i)
135
+ sample = [
136
+ ["ModernJapanese1931.05.05", false],
137
+ ["S06(1931).05.05", true]
138
+ ]
139
+ ((date2+When::Duration('P30Y')).scan(When.Resource('ModernJapanese', '_e:'))).each do |d|
140
+ assert_equal(sample.shift, [d.to_s, d.leaf?])
141
+ end
142
+
143
+ sample = [
144
+ ["S06(1931).05.05", true]
145
+ ]
146
+ ((date2+When::Duration('P30Y'))^When.Resource('ModernJapanese', '_e:')).each do |d|
147
+ assert_equal(sample.shift, [d.to_s, d.leaf?])
148
+ end
149
+
150
+ sample =[
151
+ ["明治", "http://ja.wikipedia.org/wiki/%E6%98%8E%E6%B2%BB"],
152
+ ["Meiji", "http://en.wikipedia.org/wiki/Meiji_period"],
153
+ ["M", "http://ja.wikipedia.org/wiki/%E6%98%8E%E6%B2%BB"],
154
+ ["大正", "http://ja.wikipedia.org/wiki/%E5%A4%A7%E6%AD%A3"],
155
+ ["Taishō", "http://en.wikipedia.org/wiki/Taish%C5%8D_period"],
156
+ ["T", "http://ja.wikipedia.org/wiki/%E5%A4%A7%E6%AD%A3"],
157
+ ["昭和", "http://ja.wikipedia.org/wiki/%E6%98%AD%E5%92%8C"],
158
+ ["Shōwa", "http://en.wikipedia.org/wiki/Sh%C5%8Dwa_period"],
159
+ ["S", "http://ja.wikipedia.org/wiki/%E6%98%AD%E5%92%8C"],
160
+ ["平成", "http://ja.wikipedia.org/wiki/%E5%B9%B3%E6%88%90"],
161
+ ["Heisei", "http://en.wikipedia.org/wiki/Heisei_period"],
162
+ ["H", "http://ja.wikipedia.org/wiki/%E5%B9%B3%E6%88%90"]
163
+ ]
164
+ ['明治', '大正', '昭和', '平成'].each do |nengo|
165
+ era = When::era(nengo)
166
+ ['ja', 'en', 'alias'].each do |lang|
167
+ assert_equal(sample.shift, [era[0].label.translate(lang), era[0].label.reference(lang)])
168
+ end
169
+ end
170
+
171
+ sample =[
172
+ ["明治天皇", "http://ja.wikipedia.org/wiki/%E6%98%8E%E6%B2%BB%E5%A4%A9%E7%9A%87"],
173
+ ["Emperor_Meiji", "http://en.wikipedia.org/wiki/Emperor_Meiji"],
174
+ ["大正天皇", "http://ja.wikipedia.org/wiki/%E5%A4%A7%E6%AD%A3%E5%A4%A9%E7%9A%87"],
175
+ ["Emperor_Taishō", "http://en.wikipedia.org/wiki/Emperor_Taish%C5%8D"],
176
+ ["昭和天皇", "http://ja.wikipedia.org/wiki/%E6%98%AD%E5%92%8C%E5%A4%A9%E7%9A%87"],
177
+ ["Emperor_Shōwa", "http://en.wikipedia.org/wiki/Emperor_Sh%C5%8Dwa"],
178
+ ["今上天皇", "http://ja.wikipedia.org/wiki/%E6%98%8E%E4%BB%81"],
179
+ ["Emperor_Kinjō", "http://en.wikipedia.org/wiki/Akihito"]
180
+ ]
181
+ ['明治', '大正', '昭和', '平成'].each do |nengo|
182
+ name = When.when?(nengo + '06.01.01').query['name']
183
+ ['ja', 'en'].each do |lang|
184
+ assert_equal(sample.shift, [name.translate(lang), name.reference(lang)])
185
+ end
186
+ end
187
+
188
+ assert_equal("昭和02(1927).03.01", When.when?('大正16.2.29').to_s)
189
+ assert_equal({"name"=>"大正天皇", "period"=>nil, "area"=>"日本"}, When::era('大正')[0].options)
190
+ end
191
+ end
192
+
193
+ #
194
+ # 空間位置
195
+ #
196
+ class Spatial < MiniTest::TestCase
197
+ Indian = [
198
+ ["CentralIndia",
199
+ "インド中部",
200
+ nil,
201
+ 23.15 + 1.0/30,
202
+ 82.5],
203
+ ["NorthIndia",
204
+ "インド北部",
205
+ nil,
206
+ 29.0,
207
+ 82.5],
208
+ ["Agra",
209
+ "アーグラ",
210
+ "http://en.wikipedia.org/wiki/Agra",
211
+ 27.2,
212
+ 78.0],
213
+ ["Ahmedabad",
214
+ "アフマダーバード",
215
+ "http://en.wikipedia.org/wiki/Ahmedabad",
216
+ 23.0,
217
+ 72.6],
218
+ ["Ajmer",
219
+ "アジメール",
220
+ "http://en.wikipedia.org/wiki/Ajmer",
221
+ 26.5,
222
+ 74.6],
223
+ ["Aligarh",
224
+ "アリーガル",
225
+ "http://en.wikipedia.org/wiki/Aligarh",
226
+ 27.9,
227
+ 78.1],
228
+ ["Amritsar",
229
+ "アムリトサル",
230
+ "http://en.wikipedia.org/wiki/Amritsar",
231
+ 31.6,
232
+ 74.9],
233
+ ["Bangalore",
234
+ "バンガロール",
235
+ "http://en.wikipedia.org/wiki/Bangalore",
236
+ 13.0,
237
+ 77.6],
238
+ ["Bhuvaneswar",
239
+ "ブヴァネーシュヴァル",
240
+ "http://en.wikipedia.org/wiki/Bhuvaneswar",
241
+ 20.2,
242
+ 85.8],
243
+ ["Chennai",
244
+ "チェンナイ",
245
+ "http://en.wikipedia.org/wiki/Chennai",
246
+ 13.1,
247
+ 80.3],
248
+ ["Colombo",
249
+ "コロンボ",
250
+ "http://en.wikipedia.org/wiki/Colombo",
251
+ 6.9,
252
+ 79.9],
253
+ ["Dacca",
254
+ "ダッカ",
255
+ "http://en.wikipedia.org/wiki/Dacca",
256
+ 23.7,
257
+ 90.4],
258
+ ["Delhi",
259
+ "デリー",
260
+ "http://en.wikipedia.org/wiki/Delhi",
261
+ 28.6,
262
+ 77.2],
263
+ ["Hyderabad",
264
+ "ハイデラバード",
265
+ "http://en.wikipedia.org/wiki/Hyderabad",
266
+ 17.4,
267
+ 78.5],
268
+ ["Jaipur",
269
+ "ジャイプル",
270
+ "http://en.wikipedia.org/wiki/Jaipur",
271
+ 26.9,
272
+ 75.8],
273
+ ["Kathmandu",
274
+ "カトマンズ",
275
+ "http://en.wikipedia.org/wiki/Kathmandu",
276
+ 27.7,
277
+ 85.2],
278
+ ["Kochi",
279
+ "コーチ",
280
+ "http://en.wikipedia.org/wiki/Kochi",
281
+ 10.0,
282
+ 76.2],
283
+ ["Kolkata",
284
+ "コルカタ",
285
+ "http://en.wikipedia.org/wiki/Kolkata",
286
+ 22.6,
287
+ 88.4],
288
+ ["Lahor",
289
+ "ラホール",
290
+ "http://en.wikipedia.org/wiki/Lahor",
291
+ 31.6,
292
+ 74.3],
293
+ ["Mathura",
294
+ "マトゥラー",
295
+ "http://en.wikipedia.org/wiki/Mathura",
296
+ 27.5,
297
+ 77.7],
298
+ ["Mumbai",
299
+ "ムンバイ",
300
+ "http://en.wikipedia.org/wiki/Mumbai",
301
+ 19.0,
302
+ 72.8],
303
+ ["Mysore",
304
+ "マイソール",
305
+ "http://en.wikipedia.org/wiki/Mysore",
306
+ 12.3,
307
+ 76.6],
308
+ ["Patna",
309
+ "パトナ",
310
+ "http://en.wikipedia.org/wiki/Patna",
311
+ 25.6,
312
+ 85.1],
313
+ ["Pune",
314
+ "プネー",
315
+ "http://en.wikipedia.org/wiki/Pune",
316
+ 18.5,
317
+ 73.9],
318
+ ["Srinagar",
319
+ "シュリーナガル",
320
+ "http://en.wikipedia.org/wiki/Srinagar",
321
+ 34.1,
322
+ 74.8],
323
+ ["Thiruvananthapuram",
324
+ "ティルヴァナンタプラム",
325
+ "http://en.wikipedia.org/wiki/Thiruvananthapuram",
326
+ 8.5,
327
+ 77.0],
328
+ ["Varanasi",
329
+ "ワーラーナシー",
330
+ "http://en.wikipedia.org/wiki/Varanasi",
331
+ 25.3,
332
+ 83.0],
333
+ ["Ujjain",
334
+ "ウッジャイン",
335
+ "http://en.wikipedia.org/wiki/Ujjain",
336
+ 23.2,
337
+ 75.8]
338
+ ]
339
+
340
+ def test__inner_representation
341
+ location = When.Resource("examples/sample.xml?lat=35&long=135")
342
+ assert_equal( 7875.0, location.lat)
343
+ assert_equal(30375.0, location.long)
344
+ assert_equal( '35.0000N', location.lat_s)
345
+ assert_equal('135.0000E', location.long_s)
346
+ if Object.const_defined?(:JSON)
347
+ location = When.Resource("examples/sample.json?lat=40")
348
+ assert_equal( 9000.0, location.lat)
349
+ assert_equal(31433.32625, location.long)
350
+ assert_equal( '40.0000N', location.lat_s)
351
+ assert_equal('139.421322E',location.long_s)
352
+ else
353
+ puts
354
+ puts "Tests for JSON have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
355
+ end
356
+ end
357
+
358
+ def test__reference
359
+ location = When.Resource("_co:Spatial?label=Kyoto&long=136&lat=30&ref=(http://)")
360
+ assert_equal("http://", location.ref)
361
+ end
362
+
363
+ def test__surface_radius
364
+ location = When.Resource("_co:Spatial?label=Kyoto&long=136&lat=30&ref=(http://)")
365
+ assert_equal(6378.14, location.surface_radius)
366
+ end
367
+
368
+ def test__spatial_m17n
369
+ ['_co:Indian', 'examples/Spatial.m17n'].each do |iri|
370
+ samples = Indian.dup
371
+ assert_equal(samples.size, When.Resource(iri).child.size)
372
+ When.Resource(iri).child.each do |obj|
373
+ name = obj.label
374
+ sample = samples.shift.dup
375
+ sample << iri.sub(/_co:/, 'http://hosi.org/When/Coordinates/') + '::' + sample[0]
376
+ assert_equal(sample,
377
+ [name.label,
378
+ name.translate('ja'),
379
+ name.reference('en'),
380
+ obj.lat / When::Coordinates::Spatial::DEGREE,
381
+ obj.long / When::Coordinates::Spatial::DEGREE,
382
+ obj.iri])
383
+ end
384
+ end
385
+ end
386
+
387
+ def test__to_dms
388
+ assert_equal(+135.9, When::Coordinates.to_deg("東経135度54分", 'EW'))
389
+ assert_equal(+135.9, When::Coordinates.to_deg("135度54分E", 'EW'))
390
+ assert_equal(+135.9, When::Coordinates.to_deg("135.5400E", 'EW'))
391
+ assert_equal(+135.9, When::Coordinates.to_deg("E135.5400", 'EW'))
392
+ assert_equal("135.5400E", When::Coordinates.to_dms(+135.9, 'EW'))
393
+ assert_equal( "35.3936N", When::Coordinates.to_dms(+35.66, 'NS'))
394
+ end
395
+ end
396
+ end
397
+