when_exe 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +171 -0
- data/lib/when_exe.rb +78 -47
- data/lib/when_exe/basictypes.rb +752 -747
- data/lib/when_exe/calendarnote.rb +805 -801
- data/lib/when_exe/calendartypes.rb +1583 -1531
- data/lib/when_exe/coordinates.rb +16 -15
- data/lib/when_exe/core/duration.rb +114 -110
- data/lib/when_exe/core/extension.rb +504 -504
- data/lib/when_exe/ephemeris.rb +1917 -1913
- data/lib/when_exe/ephemeris/moon.rb +333 -333
- data/lib/when_exe/ephemeris/notes.rb +389 -387
- data/lib/when_exe/ephemeris/planets.rb +585 -585
- data/lib/when_exe/ephemeris/sun.rb +214 -214
- data/lib/when_exe/googlecalendar.rb +144 -140
- data/lib/when_exe/icalendar.rb +1636 -1636
- data/lib/when_exe/inspect.rb +46 -22
- data/lib/when_exe/locales/akt.rb +176 -176
- data/lib/when_exe/locales/encoding_conversion.rb +134 -126
- data/lib/when_exe/locales/iast.rb +90 -90
- data/lib/when_exe/locales/locale.rb +750 -746
- data/lib/when_exe/locales/transliteration_table.rb +62 -62
- data/lib/when_exe/mini_application.rb +307 -305
- data/lib/when_exe/parts/enumerator.rb +2 -2
- data/lib/when_exe/parts/geometric_complex.rb +397 -397
- data/lib/when_exe/parts/method_cash.rb +224 -224
- data/lib/when_exe/parts/resource.rb +1069 -1071
- data/lib/when_exe/parts/timezone.rb +240 -230
- data/lib/when_exe/region/armenian.rb +56 -56
- data/lib/when_exe/region/babylonian.rb +405 -0
- data/lib/when_exe/region/bahai.rb +146 -146
- data/lib/when_exe/region/balinese.rb +622 -622
- data/lib/when_exe/region/chinese.rb +95 -25
- data/lib/when_exe/region/chinese/calendars.rb +1016 -1016
- data/lib/when_exe/region/chinese/epochs.rb +1 -1
- data/lib/when_exe/region/chinese/twins.rb +803 -795
- data/lib/when_exe/region/christian.rb +824 -824
- data/lib/when_exe/region/coptic.rb +106 -87
- data/lib/when_exe/region/discordian.rb +225 -225
- data/lib/when_exe/region/far_east.rb +188 -188
- data/lib/when_exe/region/french.rb +56 -56
- data/lib/when_exe/region/geologicalage.rb +639 -639
- data/lib/when_exe/region/goddess.rb +58 -58
- data/lib/when_exe/region/indian.rb +1254 -1251
- data/lib/when_exe/region/iranian.rb +8 -8
- data/lib/when_exe/region/islamic.rb +3 -3
- data/lib/when_exe/region/japanese.rb +93 -99
- data/lib/when_exe/region/japanese/calendars.rb +396 -397
- data/lib/when_exe/region/japanese/epochs.rb +26 -26
- data/lib/when_exe/region/japanese/nihon_shoki.rb +71 -71
- data/lib/when_exe/region/japanese/notes.rb +1383 -1386
- data/lib/when_exe/region/japanese/residues.rb +1306 -1306
- data/lib/when_exe/region/japanese/twins.rb +225 -225
- data/lib/when_exe/region/japanese/weeks.rb +112 -0
- data/lib/when_exe/region/javanese.rb +230 -230
- data/lib/when_exe/region/jewish.rb +126 -126
- data/lib/when_exe/region/korean.rb +378 -378
- data/lib/when_exe/region/m17n.rb +114 -113
- data/lib/when_exe/region/martian.rb +258 -255
- data/lib/when_exe/region/mayan.rb +32 -32
- data/lib/when_exe/region/residue.rb +89 -89
- data/lib/when_exe/region/roman.rb +36 -24
- data/lib/when_exe/region/ryukyu.rb +97 -97
- data/lib/when_exe/region/shire.rb +240 -240
- data/lib/when_exe/region/soviet.rb +209 -0
- data/lib/when_exe/region/symmetry.rb +50 -50
- data/lib/when_exe/region/thai.rb +336 -335
- data/lib/when_exe/region/tibetan.rb +316 -315
- data/lib/when_exe/region/vietnamese.rb +440 -439
- data/lib/when_exe/region/weekdate.rb +80 -80
- data/lib/when_exe/region/world.rb +175 -175
- data/lib/when_exe/region/yerm.rb +14 -14
- data/lib/when_exe/region/zoroastrian.rb +203 -203
- data/lib/when_exe/timestandard.rb +707 -681
- data/lib/when_exe/tmduration.rb +338 -330
- data/lib/when_exe/tmobjects.rb +1346 -1325
- data/lib/when_exe/tmposition.rb +2115 -2072
- data/lib/when_exe/tmreference.rb +1693 -1669
- data/lib/when_exe/version.rb +1 -1
- data/link_to_online_documents +1 -1
- data/test/examples/JapanHolidaysRFC6350.ics +1 -1
- data/test/test.rb +67 -61
- data/test/test/basictypes.rb +409 -409
- data/test/test/calendarnote.rb +86 -69
- data/test/test/calendartypes.rb +97 -97
- data/test/test/coordinates.rb +396 -396
- data/test/test/ephemeris.rb +83 -74
- data/test/test/ephemeris/moon.rb +14 -14
- data/test/test/ephemeris/planets.rb +14 -14
- data/test/test/ephemeris/sun.rb +14 -14
- data/test/test/googlecalendar.rb +194 -176
- data/test/test/icalendar.rb +867 -858
- data/test/test/inspect.rb +117 -117
- data/test/test/parts.rb +487 -487
- data/test/test/region/balinese.rb +34 -0
- data/test/test/region/chinese.rb +218 -206
- data/test/test/region/christian.rb +245 -245
- data/test/test/region/coptic.rb +27 -27
- data/test/test/region/french.rb +33 -33
- data/test/test/region/geologicalage.rb +17 -17
- data/test/test/region/indian.rb +57 -57
- data/test/test/region/iran.rb +54 -54
- data/test/test/region/islamic.rb +18 -18
- data/test/test/region/japanese.rb +237 -219
- data/test/test/region/jewish.rb +61 -61
- data/test/test/region/m17n.rb +184 -184
- data/test/test/region/mayan.rb +195 -195
- data/test/test/region/residue.rb +147 -139
- data/test/test/region/thai.rb +116 -116
- data/test/test/region/tibetan.rb +30 -30
- data/test/test/region/vietnamese.rb +102 -102
- data/test/test/region/yerm.rb +146 -146
- data/test/test/timestandard.rb +81 -81
- data/test/test/tmobjects.rb +328 -328
- data/test/test/tmposition.rb +397 -284
- data/test/test/tmreference.rb +157 -157
- metadata +13 -10
data/test/test/inspect.rb
CHANGED
@@ -1,117 +1,117 @@
|
|
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
|
10
|
-
|
11
|
-
class Inspect <
|
12
|
-
|
13
|
-
def test__strftime_1
|
14
|
-
ns = 'ISO, jwiki=http://ja.wikipedia.org/wiki/, ewiki=http://en.wikipedia.org/wiki/'
|
15
|
-
locale = '=jwiki:, en=ewiki:'
|
16
|
-
term1 = When::BasicTypes::M17n.new('[月曜, Monday]', ns, locale)
|
17
|
-
term2 = When::BasicTypes::M17n.new('[です, It is]', ns, locale)
|
18
|
-
form = When::BasicTypes::M17n.new('[%s%s%2d:, %2$s %1$s%3$2d-]', ns, locale)
|
19
|
-
assert_equal(["月曜です 1%", "It is Monday 1%"],
|
20
|
-
['ja_JP', 'en_US'].map {|c| (form % [term1, term2, When::Coordinates::Pair.new(1,-2)]).translate(c)})
|
21
|
-
|
22
|
-
pair11 = When::Coordinates::Pair.new(1,1)
|
23
|
-
assert_equal("2:", "%d:" % pair11)
|
24
|
-
assert_equal("2=", "%d=" % pair11)
|
25
|
-
assert_equal("1=", When.m17n("%d:") % pair11)
|
26
|
-
|
27
|
-
date = When.when?('2011-02-28T12:34:56+09:00')
|
28
|
-
assert_equal(["February", {""=>"February", "ja"=>"2月"}], [date.name(-1).to_s, date.name(-1).names])
|
29
|
-
assert_equal("Mon Feb 28 12:34:56 +0900 2011", date.strftime('%+'))
|
30
|
-
|
31
|
-
date = When.when?('2011-05-17T12:34:56', {:clock=>'+09:00'})
|
32
|
-
# assert_equal("5月", date.strftime('%.2b').translate('ja'))
|
33
|
-
assert_equal("05", date.strftime('%m'))
|
34
|
-
assert_equal("Tue May 17 12:34:56 +0900 2011", date.strftime('%+'))
|
35
|
-
# assert_equal("火 5月 17 12:34:56 +0900 2011", date.strftime('%+').translate('ja'))
|
36
|
-
|
37
|
-
clock = When.Clock('+09:00')
|
38
|
-
#pp clock.to_s
|
39
|
-
assert_equal("+09:00", clock.label.to_s)
|
40
|
-
assert_equal(nil, clock.referenceEvent)
|
41
|
-
assert_equal("T00+09:00", clock.referenceTime.to_s)
|
42
|
-
assert_equal("T*15:00:00Z", clock.utcReference.to_s)
|
43
|
-
end
|
44
|
-
|
45
|
-
def test__strftime_2
|
46
|
-
[['%c', 'ja', '2012/04/03 10:14:00'], ['%c', 'fr', '03 avril 2012 10:14:00'],
|
47
|
-
['%x', 'ja', '2012/04/03' ], ['%x', 'fr', '03/04/2012' ],
|
48
|
-
['%X', 'ja', '10:14:00' ], ['%X', 'fr', '10:14:00' ]
|
49
|
-
].each do |sample|
|
50
|
-
assert_equal(sample[2], When.when?('2012-4-3T10:14:00').
|
51
|
-
strftime(sample[0], sample[1]))
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def test__strftime_3
|
56
|
-
[['DateTime', 'ja', '2012/04/03 10:14:00' ], ['DateTime', 'fr', '03 avril 2012 10:14:00' ],
|
57
|
-
['DateTimeLong', 'ja', '2012年04月03日(火) 10時14分00秒 +0000'], ['DateTimeLong', 'fr', 'mardi 03 avril 2012 10:14'],
|
58
|
-
['DateTimeShort', 'ja', '12/04/03 10:14' ], ['DateTimeShort', 'fr', '03 avr 10:14' ],
|
59
|
-
['Date', 'ja', '2012/04/03' ], ['Date', 'fr', '03/04/2012' ],
|
60
|
-
['DateLong', 'ja', '2012年04月03日(火)' ], ['DateLong', 'fr', ' 3 avril 2012' ],
|
61
|
-
['DateShort', 'ja', '04/03' ], ['DateShort', 'fr', ' 3 avr' ],
|
62
|
-
['Time', 'ja', '10:14:00' ], ['Time', 'fr', '10:14:00' ]
|
63
|
-
].each do |sample|
|
64
|
-
assert_equal(sample[2], When.when?('2012-4-3T10:14:00').
|
65
|
-
strftime(When.Resource('_m:CalendarFormats::'+sample[0]), sample[1]))
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def test__name
|
70
|
-
month = When.when?('AP1393.1.1T12:34:56').name('month')
|
71
|
-
assert_equal("فروردین", month.translate('ar'))
|
72
|
-
end
|
73
|
-
|
74
|
-
def test__coordinates
|
75
|
-
date = When.when?('2012.3=16T12:34:56', {:frame=>When::CalendarTypes::ChineseLuniSolar.new({'time_basis'=>'+09:00'})})
|
76
|
-
assert_equal(2012, date.year )
|
77
|
-
assert_equal(When::Coordinates::Pair.new(3,1), date.month)
|
78
|
-
assert_equal( 16, date.day )
|
79
|
-
assert_equal( 12, date.hour )
|
80
|
-
assert_equal( 34, date.minute)
|
81
|
-
assert_equal( 56, date.second)
|
82
|
-
assert_equal( 4, date.ymon )
|
83
|
-
assert_equal( 105, date.yday )
|
84
|
-
assert_equal( 16, date.mday )
|
85
|
-
assert_equal( 0, date.wday )
|
86
|
-
end
|
87
|
-
|
88
|
-
def mweek(dow, day)
|
89
|
-
dow = (dow + 1) % 7
|
90
|
-
w,d = (day - 1).divmod(7)
|
91
|
-
(d < dow) ? w : w+1
|
92
|
-
end
|
93
|
-
|
94
|
-
def test__term
|
95
|
-
# [13,14,15].each do |d|
|
96
|
-
# 7.times do |i|
|
97
|
-
# p [d, i, mweek(i, d)]
|
98
|
-
# end
|
99
|
-
# end
|
100
|
-
# raise
|
101
|
-
format = ['%U %w %W %j', '%G-W%V-%u']
|
102
|
-
7.times do |i|
|
103
|
-
2.times do |k|
|
104
|
-
[ '1-1' , '1-2' , '1-3' , '1-4' , '1-5' , '1-6' , '1-7' , '1-8' ,
|
105
|
-
'12-24','12-25','12-26','12-27','12-28','12-29','12-30','12-31',].each do |m|
|
106
|
-
date1 = When.when?("#{2000+4*i+k}-#{m}")
|
107
|
-
expr0 = format.map {|f| date1.to_date.strftime(f)}
|
108
|
-
date2 = When.when?(expr0[1])
|
109
|
-
expr1 = format.map {|f| date1.strftime(f)}
|
110
|
-
expr2 = format.map {|f| date2.strftime(f)}
|
111
|
-
assert_equal([expr0,expr0,mweek(date1.to_i % 7, date1.day)], [expr1,expr2,date1.mweek])
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
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 MiniTest
|
10
|
+
|
11
|
+
class Inspect < MiniTest::TestCase
|
12
|
+
|
13
|
+
def test__strftime_1
|
14
|
+
ns = 'ISO, jwiki=http://ja.wikipedia.org/wiki/, ewiki=http://en.wikipedia.org/wiki/'
|
15
|
+
locale = '=jwiki:, en=ewiki:'
|
16
|
+
term1 = When::BasicTypes::M17n.new('[月曜, Monday]', ns, locale)
|
17
|
+
term2 = When::BasicTypes::M17n.new('[です, It is]', ns, locale)
|
18
|
+
form = When::BasicTypes::M17n.new('[%s%s%2d:, %2$s %1$s%3$2d-]', ns, locale)
|
19
|
+
assert_equal(["月曜です 1%", "It is Monday 1%"],
|
20
|
+
['ja_JP', 'en_US'].map {|c| (form % [term1, term2, When::Coordinates::Pair.new(1,-2)]).translate(c)})
|
21
|
+
|
22
|
+
pair11 = When::Coordinates::Pair.new(1,1)
|
23
|
+
assert_equal("2:", "%d:" % pair11)
|
24
|
+
assert_equal("2=", "%d=" % pair11)
|
25
|
+
assert_equal("1=", When.m17n("%d:") % pair11)
|
26
|
+
|
27
|
+
date = When.when?('2011-02-28T12:34:56+09:00')
|
28
|
+
assert_equal(["February", {""=>"February", "ja"=>"2月"}], [date.name(-1).to_s, date.name(-1).names])
|
29
|
+
assert_equal("Mon Feb 28 12:34:56 +0900 2011", date.strftime('%+'))
|
30
|
+
|
31
|
+
date = When.when?('2011-05-17T12:34:56', {:clock=>'+09:00'})
|
32
|
+
# assert_equal("5月", date.strftime('%.2b').translate('ja'))
|
33
|
+
assert_equal("05", date.strftime('%m'))
|
34
|
+
assert_equal("Tue May 17 12:34:56 +0900 2011", date.strftime('%+'))
|
35
|
+
# assert_equal("火 5月 17 12:34:56 +0900 2011", date.strftime('%+').translate('ja'))
|
36
|
+
|
37
|
+
clock = When.Clock('+09:00')
|
38
|
+
#pp clock.to_s
|
39
|
+
assert_equal("+09:00", clock.label.to_s)
|
40
|
+
assert_equal(nil, clock.referenceEvent)
|
41
|
+
assert_equal("T00+09:00", clock.referenceTime.to_s)
|
42
|
+
assert_equal("T*15:00:00Z", clock.utcReference.to_s)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test__strftime_2
|
46
|
+
[['%c', 'ja', '2012/04/03 10:14:00'], ['%c', 'fr', '03 avril 2012 10:14:00'],
|
47
|
+
['%x', 'ja', '2012/04/03' ], ['%x', 'fr', '03/04/2012' ],
|
48
|
+
['%X', 'ja', '10:14:00' ], ['%X', 'fr', '10:14:00' ]
|
49
|
+
].each do |sample|
|
50
|
+
assert_equal(sample[2], When.when?('2012-4-3T10:14:00').
|
51
|
+
strftime(sample[0], sample[1]))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test__strftime_3
|
56
|
+
[['DateTime', 'ja', '2012/04/03 10:14:00' ], ['DateTime', 'fr', '03 avril 2012 10:14:00' ],
|
57
|
+
['DateTimeLong', 'ja', '2012年04月03日(火) 10時14分00秒 +0000'], ['DateTimeLong', 'fr', 'mardi 03 avril 2012 10:14'],
|
58
|
+
['DateTimeShort', 'ja', '12/04/03 10:14' ], ['DateTimeShort', 'fr', '03 avr 10:14' ],
|
59
|
+
['Date', 'ja', '2012/04/03' ], ['Date', 'fr', '03/04/2012' ],
|
60
|
+
['DateLong', 'ja', '2012年04月03日(火)' ], ['DateLong', 'fr', ' 3 avril 2012' ],
|
61
|
+
['DateShort', 'ja', '04/03' ], ['DateShort', 'fr', ' 3 avr' ],
|
62
|
+
['Time', 'ja', '10:14:00' ], ['Time', 'fr', '10:14:00' ]
|
63
|
+
].each do |sample|
|
64
|
+
assert_equal(sample[2], When.when?('2012-4-3T10:14:00').
|
65
|
+
strftime(When.Resource('_m:CalendarFormats::'+sample[0]), sample[1]))
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test__name
|
70
|
+
month = When.when?('AP1393.1.1T12:34:56').name('month')
|
71
|
+
assert_equal("فروردین", month.translate('ar'))
|
72
|
+
end
|
73
|
+
|
74
|
+
def test__coordinates
|
75
|
+
date = When.when?('2012.3=16T12:34:56', {:frame=>When::CalendarTypes::ChineseLuniSolar.new({'time_basis'=>'+09:00'})})
|
76
|
+
assert_equal(2012, date.year )
|
77
|
+
assert_equal(When::Coordinates::Pair.new(3,1), date.month)
|
78
|
+
assert_equal( 16, date.day )
|
79
|
+
assert_equal( 12, date.hour )
|
80
|
+
assert_equal( 34, date.minute)
|
81
|
+
assert_equal( 56, date.second)
|
82
|
+
assert_equal( 4, date.ymon )
|
83
|
+
assert_equal( 105, date.yday )
|
84
|
+
assert_equal( 16, date.mday )
|
85
|
+
assert_equal( 0, date.wday )
|
86
|
+
end
|
87
|
+
|
88
|
+
def mweek(dow, day)
|
89
|
+
dow = (dow + 1) % 7
|
90
|
+
w,d = (day - 1).divmod(7)
|
91
|
+
(d < dow) ? w : w+1
|
92
|
+
end
|
93
|
+
|
94
|
+
def test__term
|
95
|
+
# [13,14,15].each do |d|
|
96
|
+
# 7.times do |i|
|
97
|
+
# p [d, i, mweek(i, d)]
|
98
|
+
# end
|
99
|
+
# end
|
100
|
+
# raise
|
101
|
+
format = ['%U %w %W %j', '%G-W%V-%u']
|
102
|
+
7.times do |i|
|
103
|
+
2.times do |k|
|
104
|
+
[ '1-1' , '1-2' , '1-3' , '1-4' , '1-5' , '1-6' , '1-7' , '1-8' ,
|
105
|
+
'12-24','12-25','12-26','12-27','12-28','12-29','12-30','12-31',].each do |m|
|
106
|
+
date1 = When.when?("#{2000+4*i+k}-#{m}")
|
107
|
+
expr0 = format.map {|f| date1.to_date.strftime(f)}
|
108
|
+
date2 = When.when?(expr0[1])
|
109
|
+
expr1 = format.map {|f| date1.strftime(f)}
|
110
|
+
expr2 = format.map {|f| date2.strftime(f)}
|
111
|
+
assert_equal([expr0,expr0,mweek(date1.to_i % 7, date1.day)], [expr1,expr2,date1.mweek])
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/test/test/parts.rb
CHANGED
@@ -1,487 +1,487 @@
|
|
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
|
19
|
-
|
20
|
-
class MethodCash <
|
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 <
|
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("Intercalary Month 9", date.name('Month').translate('en_US'))
|
127
|
-
end
|
128
|
-
|
129
|
-
def test__split
|
130
|
-
assert_equal(['' ], When::Locale._split(''))
|
131
|
-
assert_equal(['3.14' ], When::Locale._split('3.14'))
|
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', ' "3.14,159"'], When::Locale._split('3.14, "3.14,159"'))
|
135
|
-
assert_equal(['3.14', ' "3.14\\"159"'], When::Locale._split('3.14, "3.14\\"159"'))
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
class Resource <
|
140
|
-
def test_nothing
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
class Enumerator <
|
145
|
-
|
146
|
-
def test_nothing
|
147
|
-
end
|
148
|
-
|
149
|
-
class Array <
|
150
|
-
def test_nothing
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
class Integrated <
|
155
|
-
def test_nothing
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
class GeometricComplex <
|
161
|
-
|
162
|
-
def test__include
|
163
|
-
|
164
|
-
sample = [false, false, false, false, false]
|
165
|
-
complex = When::Parts::GeometricComplex.new(false)
|
166
|
-
assert_equal(nil, complex.exclude_end?)
|
167
|
-
(1..5).each do |i|
|
168
|
-
assert_equal(sample.shift, complex.include?(i))
|
169
|
-
end
|
170
|
-
|
171
|
-
sample = [true, true, true, true, true]
|
172
|
-
complex = When::Parts::GeometricComplex.new(true)
|
173
|
-
assert_equal(nil, complex.exclude_end?)
|
174
|
-
(1..5).each do |i|
|
175
|
-
assert_equal(sample.shift, complex.include?(i))
|
176
|
-
end
|
177
|
-
|
178
|
-
sample = [false, true, true, true, false]
|
179
|
-
complex = When::Parts::GeometricComplex.new(2..4)
|
180
|
-
assert_equal(false, complex.exclude_end?)
|
181
|
-
(1..5).each do |i|
|
182
|
-
assert_equal(sample.shift, complex.include?(i))
|
183
|
-
end
|
184
|
-
|
185
|
-
sample = [false, true, true, false, false]
|
186
|
-
complex = When::Parts::GeometricComplex.new(2...4)
|
187
|
-
assert_equal(true, complex.exclude_end?)
|
188
|
-
(1..5).each do |i|
|
189
|
-
assert_equal(sample.shift, complex.include?(i))
|
190
|
-
end
|
191
|
-
|
192
|
-
sample = [true, false, false, false, true]
|
193
|
-
complex = -When::Parts::GeometricComplex.new(2..4)
|
194
|
-
assert_equal(true, complex.exclude_end?)
|
195
|
-
(1..5).each do |i|
|
196
|
-
assert_equal(sample.shift, complex.include?(i))
|
197
|
-
end
|
198
|
-
|
199
|
-
sample = [true, false, false, true, true]
|
200
|
-
complex = -When::Parts::GeometricComplex.new(2...4)
|
201
|
-
assert_equal(false, complex.exclude_end?)
|
202
|
-
(1..5).each do |i|
|
203
|
-
assert_equal(sample.shift, complex.include?(i))
|
204
|
-
end
|
205
|
-
|
206
|
-
period_1_2 = When::Parts::GeometricComplex.new(1..2)
|
207
|
-
period_2_3 = When::Parts::GeometricComplex.new(2..3)
|
208
|
-
period_3_4 = When::Parts::GeometricComplex.new(3..4)
|
209
|
-
period_4_5 = When::Parts::GeometricComplex.new(4..5)
|
210
|
-
period_5_6 = When::Parts::GeometricComplex.new(5..6)
|
211
|
-
|
212
|
-
period_2_4 = When::Parts::GeometricComplex.new(2..4)
|
213
|
-
period_3_6 = When::Parts::GeometricComplex.new(3..6)
|
214
|
-
period_4_6 = When::Parts::GeometricComplex.new(4..6)
|
215
|
-
period_1_6 = When::Parts::GeometricComplex.new(1..6)
|
216
|
-
|
217
|
-
[[false, period_1_2, period_4_6],
|
218
|
-
[false, period_1_2, period_2_4],
|
219
|
-
[false, period_2_4, period_3_6],
|
220
|
-
[false, period_2_3, period_2_4],
|
221
|
-
[true, period_2_4, period_2_3],
|
222
|
-
|
223
|
-
[false, period_2_4, period_1_6],
|
224
|
-
[true, period_1_6, period_2_4],
|
225
|
-
[true, period_2_4, period_2_4],
|
226
|
-
|
227
|
-
[false, period_3_6, period_2_4],
|
228
|
-
[false, period_3_4, period_2_4],
|
229
|
-
[true, period_2_4, period_3_4],
|
230
|
-
[false, period_4_5, period_2_4],
|
231
|
-
[false, period_5_6, period_2_4]].each do |sample|
|
232
|
-
assert_equal(sample[0], sample[1].include?(sample[2]))
|
233
|
-
end
|
234
|
-
|
235
|
-
period_1_2 = When::Parts::GeometricComplex.new(1...2)
|
236
|
-
period_2_3 = When::Parts::GeometricComplex.new(2...3)
|
237
|
-
period_3_4 = When::Parts::GeometricComplex.new(3...4)
|
238
|
-
period_4_5 = When::Parts::GeometricComplex.new(4...5)
|
239
|
-
period_5_6 = When::Parts::GeometricComplex.new(5...6)
|
240
|
-
|
241
|
-
period_2_4 = When::Parts::GeometricComplex.new(2...4)
|
242
|
-
period_3_6 = When::Parts::GeometricComplex.new(3...6)
|
243
|
-
period_4_6 = When::Parts::GeometricComplex.new(4...6)
|
244
|
-
period_1_6 = When::Parts::GeometricComplex.new(1...6)
|
245
|
-
|
246
|
-
[[false, period_1_2, period_4_6],
|
247
|
-
[false, period_1_2, period_2_4],
|
248
|
-
[false, period_2_4, period_3_6],
|
249
|
-
[false, period_2_3, period_2_4],
|
250
|
-
[true, period_2_4, period_2_3],
|
251
|
-
|
252
|
-
[false, period_2_4, period_1_6],
|
253
|
-
[true, period_1_6, period_2_4],
|
254
|
-
[true, period_2_4, period_2_4],
|
255
|
-
|
256
|
-
[false, period_3_6, period_2_4],
|
257
|
-
[false, period_3_4, period_2_4],
|
258
|
-
[true, period_2_4, period_3_4],
|
259
|
-
[false, period_4_5, period_2_4],
|
260
|
-
[false, period_5_6, period_2_4]].each do |sample|
|
261
|
-
assert_equal(sample[0], sample[1].include?(sample[2]))
|
262
|
-
end
|
263
|
-
|
264
|
-
period_1_2 = -When::Parts::GeometricComplex.new(1..2)
|
265
|
-
period_2_3 = -When::Parts::GeometricComplex.new(2..3)
|
266
|
-
period_3_4 = -When::Parts::GeometricComplex.new(3..4)
|
267
|
-
period_4_5 = -When::Parts::GeometricComplex.new(4..5)
|
268
|
-
period_5_6 = -When::Parts::GeometricComplex.new(5..6)
|
269
|
-
|
270
|
-
period_2_4 = -When::Parts::GeometricComplex.new(2..4)
|
271
|
-
period_3_6 = -When::Parts::GeometricComplex.new(3..6)
|
272
|
-
period_4_6 = -When::Parts::GeometricComplex.new(4..6)
|
273
|
-
period_1_6 = -When::Parts::GeometricComplex.new(1..6)
|
274
|
-
|
275
|
-
[[false, period_4_6, period_1_2],
|
276
|
-
[false, period_2_4, period_1_2],
|
277
|
-
[false, period_3_6, period_2_4],
|
278
|
-
[false, period_2_4, period_2_3],
|
279
|
-
[true, period_2_3, period_2_4],
|
280
|
-
|
281
|
-
[false, period_1_6, period_2_4],
|
282
|
-
[true, period_2_4, period_1_6],
|
283
|
-
[true, period_2_4, period_2_4],
|
284
|
-
|
285
|
-
[false, period_2_4, period_3_6],
|
286
|
-
[false, period_2_4, period_3_4],
|
287
|
-
[true, period_3_4, period_2_4],
|
288
|
-
[false, period_2_4, period_4_5],
|
289
|
-
[false, period_2_4, period_5_6]].each do |sample|
|
290
|
-
assert_equal(sample[0], sample[1].include?(sample[2]))
|
291
|
-
end
|
292
|
-
|
293
|
-
period_1_2 = -When::Parts::GeometricComplex.new(1...2)
|
294
|
-
period_2_3 = -When::Parts::GeometricComplex.new(2...3)
|
295
|
-
period_3_4 = -When::Parts::GeometricComplex.new(3...4)
|
296
|
-
period_4_5 = -When::Parts::GeometricComplex.new(4...5)
|
297
|
-
period_5_6 = -When::Parts::GeometricComplex.new(5...6)
|
298
|
-
|
299
|
-
period_2_4 = -When::Parts::GeometricComplex.new(2...4)
|
300
|
-
period_3_6 = -When::Parts::GeometricComplex.new(3...6)
|
301
|
-
period_4_6 = -When::Parts::GeometricComplex.new(4...6)
|
302
|
-
period_1_6 = -When::Parts::GeometricComplex.new(1...6)
|
303
|
-
|
304
|
-
[[false, period_4_6, period_1_2],
|
305
|
-
[false, period_2_4, period_1_2],
|
306
|
-
[false, period_3_6, period_2_4],
|
307
|
-
[false, period_2_4, period_2_3],
|
308
|
-
[true, period_2_3, period_2_4],
|
309
|
-
|
310
|
-
[false, period_1_6, period_2_4],
|
311
|
-
[true, period_2_4, period_1_6],
|
312
|
-
[true, period_2_4, period_2_4],
|
313
|
-
|
314
|
-
[false, period_2_4, period_3_6],
|
315
|
-
[false, period_2_4, period_3_4],
|
316
|
-
[true, period_3_4, period_2_4],
|
317
|
-
[false, period_2_4, period_4_5],
|
318
|
-
[false, period_2_4, period_5_6]].each do |sample|
|
319
|
-
assert_equal(sample[0], sample[1].include?(sample[2]))
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
def test__union
|
324
|
-
|
325
|
-
sample = [false, true, false, true, true, false]
|
326
|
-
complex = When::Parts::GeometricComplex.new(3..4)
|
327
|
-
complex |= 1
|
328
|
-
(0..5).each do |i|
|
329
|
-
assert_equal(sample.shift, complex.include?(i))
|
330
|
-
end
|
331
|
-
|
332
|
-
sample = [true, false, true, false, false, true]
|
333
|
-
complex = When::Parts::GeometricComplex.new(3..4)
|
334
|
-
complex |= 1
|
335
|
-
complex = -complex
|
336
|
-
(0..5).each do |i|
|
337
|
-
assert_equal(sample.shift, complex.include?(i))
|
338
|
-
end
|
339
|
-
|
340
|
-
sample = [false, true, false, true, false, false]
|
341
|
-
complex = When::Parts::GeometricComplex.new(3...4)
|
342
|
-
complex |= 1
|
343
|
-
(0..5).each do |i|
|
344
|
-
assert_equal(sample.shift, complex.include?(i))
|
345
|
-
end
|
346
|
-
|
347
|
-
sample = [true, false, true, false, true, true]
|
348
|
-
complex = When::Parts::GeometricComplex.new(3...4)
|
349
|
-
complex |= 1
|
350
|
-
complex = -complex
|
351
|
-
(0..5).each do |i|
|
352
|
-
assert_equal(sample.shift, complex.include?(i))
|
353
|
-
end
|
354
|
-
|
355
|
-
complex = When::Parts::GeometricComplex.new(3..5)
|
356
|
-
(3..5).each do |i|
|
357
|
-
union = complex | i
|
358
|
-
assert_equal(complex, union)
|
359
|
-
end
|
360
|
-
|
361
|
-
assert_equal(When::Parts::GeometricComplex.new(3..5),
|
362
|
-
When::Parts::GeometricComplex.new(3...5) | 5)
|
363
|
-
|
364
|
-
null = When::Parts::GeometricComplex.new(false)
|
365
|
-
all = When::Parts::GeometricComplex.new(true)
|
366
|
-
period_1_2 = When::Parts::GeometricComplex.new(1..2)
|
367
|
-
period_2_3 = When::Parts::GeometricComplex.new(2..3)
|
368
|
-
period_3_4 = When::Parts::GeometricComplex.new(3..4)
|
369
|
-
period_4_5 = When::Parts::GeometricComplex.new(4..5)
|
370
|
-
period_5_6 = When::Parts::GeometricComplex.new(5..6)
|
371
|
-
|
372
|
-
period_1_4 = When::Parts::GeometricComplex.new(1..4)
|
373
|
-
period_2_4 = When::Parts::GeometricComplex.new(2..4)
|
374
|
-
period_2_5 = When::Parts::GeometricComplex.new(2..5)
|
375
|
-
period_2_6 = When::Parts::GeometricComplex.new(2..6)
|
376
|
-
period_3_6 = When::Parts::GeometricComplex.new(3..6)
|
377
|
-
period_4_6 = When::Parts::GeometricComplex.new(4..6)
|
378
|
-
period_1_6 = When::Parts::GeometricComplex.new(1..6)
|
379
|
-
|
380
|
-
period_1_2_4_6 = When::Parts::GeometricComplex.new([[1,true],[2,true],[4,true],[6,true]])
|
381
|
-
period_2_4_5_6 = When::Parts::GeometricComplex.new([[2,true],[4,true],[5,true],[6,true]])
|
382
|
-
|
383
|
-
[[period_1_2_4_6, null, period_1_2_4_6],
|
384
|
-
[period_1_2_4_6, period_1_2_4_6, null],
|
385
|
-
[all, all, period_1_2_4_6],
|
386
|
-
[all, period_1_2_4_6, all],
|
387
|
-
[period_1_2_4_6, period_1_2, period_4_6],
|
388
|
-
[period_1_4, period_1_2, period_2_4],
|
389
|
-
[period_2_6, period_2_4, period_3_6],
|
390
|
-
[period_2_4, period_2_3, period_2_4],
|
391
|
-
[period_2_4, period_2_4, period_2_3],
|
392
|
-
|
393
|
-
[period_1_6, period_2_4, period_1_6],
|
394
|
-
[period_1_6, period_1_6, period_2_4],
|
395
|
-
[period_2_4, period_2_4, period_2_4],
|
396
|
-
|
397
|
-
[period_2_6, period_3_6, period_2_4],
|
398
|
-
[period_2_4, period_3_4, period_2_4],
|
399
|
-
[period_2_4, period_2_4, period_3_4],
|
400
|
-
[period_2_5, period_4_5, period_2_4],
|
401
|
-
[period_2_4_5_6, period_5_6, period_2_4]].each do |sample|
|
402
|
-
assert_equal(sample[0], sample[1] | sample[2])
|
403
|
-
end
|
404
|
-
|
405
|
-
period_1_2 = When::Parts::GeometricComplex.new(1...2)
|
406
|
-
period_2_3 = When::Parts::GeometricComplex.new(2...3)
|
407
|
-
period_3_4 = When::Parts::GeometricComplex.new(3...4)
|
408
|
-
period_4_5 = When::Parts::GeometricComplex.new(4...5)
|
409
|
-
period_5_6 = When::Parts::GeometricComplex.new(5...6)
|
410
|
-
|
411
|
-
period_1_4 = When::Parts::GeometricComplex.new(1...4)
|
412
|
-
period_2_4 = When::Parts::GeometricComplex.new(2...4)
|
413
|
-
period_2_5 = When::Parts::GeometricComplex.new(2...5)
|
414
|
-
period_2_6 = When::Parts::GeometricComplex.new(2...6)
|
415
|
-
period_3_6 = When::Parts::GeometricComplex.new(3...6)
|
416
|
-
period_4_6 = When::Parts::GeometricComplex.new(4...6)
|
417
|
-
period_1_6 = When::Parts::GeometricComplex.new(1...6)
|
418
|
-
|
419
|
-
period_1_2_4_6 = When::Parts::GeometricComplex.new([[1,true],[2,false],[4,true],[6,false]])
|
420
|
-
period_2_4_5_6 = When::Parts::GeometricComplex.new([[2,true],[4,false],[5,true],[6,false]])
|
421
|
-
|
422
|
-
[[period_1_2_4_6, null, period_1_2_4_6],
|
423
|
-
[period_1_2_4_6, period_1_2_4_6, null],
|
424
|
-
[all, all, period_1_2_4_6],
|
425
|
-
[all, period_1_2_4_6, all],
|
426
|
-
[period_1_2_4_6, period_1_2, period_4_6],
|
427
|
-
[period_1_4, period_1_2, period_2_4],
|
428
|
-
[period_2_6, period_2_4, period_3_6],
|
429
|
-
[period_2_4, period_2_3, period_2_4],
|
430
|
-
[period_2_4, period_2_4, period_2_3],
|
431
|
-
|
432
|
-
[period_1_6, period_2_4, period_1_6],
|
433
|
-
[period_1_6, period_1_6, period_2_4],
|
434
|
-
[period_2_4, period_2_4, period_2_4],
|
435
|
-
|
436
|
-
[period_2_6, period_3_6, period_2_4],
|
437
|
-
[period_2_4, period_3_4, period_2_4],
|
438
|
-
[period_2_4, period_2_4, period_3_4],
|
439
|
-
[period_2_5, period_4_5, period_2_4],
|
440
|
-
[period_2_4_5_6, period_5_6, period_2_4]].each do |sample|
|
441
|
-
assert_equal(sample[0], sample[1] | sample[2])
|
442
|
-
end
|
443
|
-
end
|
444
|
-
|
445
|
-
def test__include_in_sample
|
446
|
-
range_1_4 = When::Parts::GeometricComplex.new(1,4)
|
447
|
-
range_2_2 = When::Parts::GeometricComplex.new(2)
|
448
|
-
range_2_3 = When::Parts::GeometricComplex.new(2,3)
|
449
|
-
range_2_5 = When::Parts::GeometricComplex.new(2,5)
|
450
|
-
range_4_4 = When::Parts::GeometricComplex.new(4)
|
451
|
-
assert_equal(true, range_1_4.include?(range_2_2))
|
452
|
-
assert_equal(true, range_1_4.include?(range_2_3))
|
453
|
-
assert_equal(false, range_1_4.include?(range_2_5))
|
454
|
-
assert_equal(false, range_1_4.include?(range_4_4))
|
455
|
-
end
|
456
|
-
|
457
|
-
def test__union_in_sample
|
458
|
-
#range_null = When::Parts::GeometricComplex.new()
|
459
|
-
#range_1_1 = When::Parts::GeometricComplex.new(1)
|
460
|
-
range_1_4 = When::Parts::GeometricComplex.new(1,4)
|
461
|
-
range_2_2 = When::Parts::GeometricComplex.new(2)
|
462
|
-
range_2_3 = When::Parts::GeometricComplex.new(2,3)
|
463
|
-
range_2_5 = When::Parts::GeometricComplex.new(2,5)
|
464
|
-
range_4_4 = When::Parts::GeometricComplex.new(4)
|
465
|
-
assert_equal("1...4", range_1_4.to_s)
|
466
|
-
assert_equal("2...3", range_2_3.to_s)
|
467
|
-
sample = [1, 2, 3]
|
468
|
-
range_1_4.each {|x| assert_equal(sample.shift, x)}
|
469
|
-
assert_equal("4..4", range_4_4.to_s)
|
470
|
-
assert_equal("1...4", (range_1_4 | range_2_3).to_s)
|
471
|
-
range_1_5 = range_1_4 | range_2_5
|
472
|
-
assert_equal("1...5", range_1_5.to_s)
|
473
|
-
assert_equal("1..4", (range_1_4 | range_4_4).to_s)
|
474
|
-
reverse_all = When::Parts::GeometricComplex.new(true)
|
475
|
-
reverse_1_4 = When::Parts::GeometricComplex.new(1,4, true)
|
476
|
-
reverse_2_3 = When::Parts::GeometricComplex.new(2,3, true)
|
477
|
-
reverse_2_5 = When::Parts::GeometricComplex.new(2,5, true)
|
478
|
-
assert_equal("1..4", reverse_1_4.to_s)
|
479
|
-
assert_equal("2..3", reverse_2_3.to_s)
|
480
|
-
unless Float::INFINITY == Float::MAX
|
481
|
-
assert_equal("-Infinity..Infinity", reverse_all.to_s)
|
482
|
-
assert_equal("-Infinity..Infinity", (reverse_2_3 | range_2_3).to_s)
|
483
|
-
end
|
484
|
-
assert_equal("1..2", (reverse_1_4 | range_2_5).to_s)
|
485
|
-
end
|
486
|
-
end
|
487
|
-
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("Intercalary Month 9", date.name('Month').translate('en_US'))
|
127
|
+
end
|
128
|
+
|
129
|
+
def test__split
|
130
|
+
assert_equal(['' ], When::Locale._split(''))
|
131
|
+
assert_equal(['3.14' ], When::Locale._split('3.14'))
|
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', ' "3.14,159"'], When::Locale._split('3.14, "3.14,159"'))
|
135
|
+
assert_equal(['3.14', ' "3.14\\"159"'], When::Locale._split('3.14, "3.14\\"159"'))
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
class Resource < MiniTest::TestCase
|
140
|
+
def test_nothing
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
class Enumerator < MiniTest::TestCase
|
145
|
+
|
146
|
+
def test_nothing
|
147
|
+
end
|
148
|
+
|
149
|
+
class Array < MiniTest::TestCase
|
150
|
+
def test_nothing
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
class Integrated < MiniTest::TestCase
|
155
|
+
def test_nothing
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
class GeometricComplex < MiniTest::TestCase
|
161
|
+
|
162
|
+
def test__include
|
163
|
+
|
164
|
+
sample = [false, false, false, false, false]
|
165
|
+
complex = When::Parts::GeometricComplex.new(false)
|
166
|
+
assert_equal(nil, complex.exclude_end?)
|
167
|
+
(1..5).each do |i|
|
168
|
+
assert_equal(sample.shift, complex.include?(i))
|
169
|
+
end
|
170
|
+
|
171
|
+
sample = [true, true, true, true, true]
|
172
|
+
complex = When::Parts::GeometricComplex.new(true)
|
173
|
+
assert_equal(nil, complex.exclude_end?)
|
174
|
+
(1..5).each do |i|
|
175
|
+
assert_equal(sample.shift, complex.include?(i))
|
176
|
+
end
|
177
|
+
|
178
|
+
sample = [false, true, true, true, false]
|
179
|
+
complex = When::Parts::GeometricComplex.new(2..4)
|
180
|
+
assert_equal(false, complex.exclude_end?)
|
181
|
+
(1..5).each do |i|
|
182
|
+
assert_equal(sample.shift, complex.include?(i))
|
183
|
+
end
|
184
|
+
|
185
|
+
sample = [false, true, true, false, false]
|
186
|
+
complex = When::Parts::GeometricComplex.new(2...4)
|
187
|
+
assert_equal(true, complex.exclude_end?)
|
188
|
+
(1..5).each do |i|
|
189
|
+
assert_equal(sample.shift, complex.include?(i))
|
190
|
+
end
|
191
|
+
|
192
|
+
sample = [true, false, false, false, true]
|
193
|
+
complex = -When::Parts::GeometricComplex.new(2..4)
|
194
|
+
assert_equal(true, complex.exclude_end?)
|
195
|
+
(1..5).each do |i|
|
196
|
+
assert_equal(sample.shift, complex.include?(i))
|
197
|
+
end
|
198
|
+
|
199
|
+
sample = [true, false, false, true, true]
|
200
|
+
complex = -When::Parts::GeometricComplex.new(2...4)
|
201
|
+
assert_equal(false, complex.exclude_end?)
|
202
|
+
(1..5).each do |i|
|
203
|
+
assert_equal(sample.shift, complex.include?(i))
|
204
|
+
end
|
205
|
+
|
206
|
+
period_1_2 = When::Parts::GeometricComplex.new(1..2)
|
207
|
+
period_2_3 = When::Parts::GeometricComplex.new(2..3)
|
208
|
+
period_3_4 = When::Parts::GeometricComplex.new(3..4)
|
209
|
+
period_4_5 = When::Parts::GeometricComplex.new(4..5)
|
210
|
+
period_5_6 = When::Parts::GeometricComplex.new(5..6)
|
211
|
+
|
212
|
+
period_2_4 = When::Parts::GeometricComplex.new(2..4)
|
213
|
+
period_3_6 = When::Parts::GeometricComplex.new(3..6)
|
214
|
+
period_4_6 = When::Parts::GeometricComplex.new(4..6)
|
215
|
+
period_1_6 = When::Parts::GeometricComplex.new(1..6)
|
216
|
+
|
217
|
+
[[false, period_1_2, period_4_6],
|
218
|
+
[false, period_1_2, period_2_4],
|
219
|
+
[false, period_2_4, period_3_6],
|
220
|
+
[false, period_2_3, period_2_4],
|
221
|
+
[true, period_2_4, period_2_3],
|
222
|
+
|
223
|
+
[false, period_2_4, period_1_6],
|
224
|
+
[true, period_1_6, period_2_4],
|
225
|
+
[true, period_2_4, period_2_4],
|
226
|
+
|
227
|
+
[false, period_3_6, period_2_4],
|
228
|
+
[false, period_3_4, period_2_4],
|
229
|
+
[true, period_2_4, period_3_4],
|
230
|
+
[false, period_4_5, period_2_4],
|
231
|
+
[false, period_5_6, period_2_4]].each do |sample|
|
232
|
+
assert_equal(sample[0], sample[1].include?(sample[2]))
|
233
|
+
end
|
234
|
+
|
235
|
+
period_1_2 = When::Parts::GeometricComplex.new(1...2)
|
236
|
+
period_2_3 = When::Parts::GeometricComplex.new(2...3)
|
237
|
+
period_3_4 = When::Parts::GeometricComplex.new(3...4)
|
238
|
+
period_4_5 = When::Parts::GeometricComplex.new(4...5)
|
239
|
+
period_5_6 = When::Parts::GeometricComplex.new(5...6)
|
240
|
+
|
241
|
+
period_2_4 = When::Parts::GeometricComplex.new(2...4)
|
242
|
+
period_3_6 = When::Parts::GeometricComplex.new(3...6)
|
243
|
+
period_4_6 = When::Parts::GeometricComplex.new(4...6)
|
244
|
+
period_1_6 = When::Parts::GeometricComplex.new(1...6)
|
245
|
+
|
246
|
+
[[false, period_1_2, period_4_6],
|
247
|
+
[false, period_1_2, period_2_4],
|
248
|
+
[false, period_2_4, period_3_6],
|
249
|
+
[false, period_2_3, period_2_4],
|
250
|
+
[true, period_2_4, period_2_3],
|
251
|
+
|
252
|
+
[false, period_2_4, period_1_6],
|
253
|
+
[true, period_1_6, period_2_4],
|
254
|
+
[true, period_2_4, period_2_4],
|
255
|
+
|
256
|
+
[false, period_3_6, period_2_4],
|
257
|
+
[false, period_3_4, period_2_4],
|
258
|
+
[true, period_2_4, period_3_4],
|
259
|
+
[false, period_4_5, period_2_4],
|
260
|
+
[false, period_5_6, period_2_4]].each do |sample|
|
261
|
+
assert_equal(sample[0], sample[1].include?(sample[2]))
|
262
|
+
end
|
263
|
+
|
264
|
+
period_1_2 = -When::Parts::GeometricComplex.new(1..2)
|
265
|
+
period_2_3 = -When::Parts::GeometricComplex.new(2..3)
|
266
|
+
period_3_4 = -When::Parts::GeometricComplex.new(3..4)
|
267
|
+
period_4_5 = -When::Parts::GeometricComplex.new(4..5)
|
268
|
+
period_5_6 = -When::Parts::GeometricComplex.new(5..6)
|
269
|
+
|
270
|
+
period_2_4 = -When::Parts::GeometricComplex.new(2..4)
|
271
|
+
period_3_6 = -When::Parts::GeometricComplex.new(3..6)
|
272
|
+
period_4_6 = -When::Parts::GeometricComplex.new(4..6)
|
273
|
+
period_1_6 = -When::Parts::GeometricComplex.new(1..6)
|
274
|
+
|
275
|
+
[[false, period_4_6, period_1_2],
|
276
|
+
[false, period_2_4, period_1_2],
|
277
|
+
[false, period_3_6, period_2_4],
|
278
|
+
[false, period_2_4, period_2_3],
|
279
|
+
[true, period_2_3, period_2_4],
|
280
|
+
|
281
|
+
[false, period_1_6, period_2_4],
|
282
|
+
[true, period_2_4, period_1_6],
|
283
|
+
[true, period_2_4, period_2_4],
|
284
|
+
|
285
|
+
[false, period_2_4, period_3_6],
|
286
|
+
[false, period_2_4, period_3_4],
|
287
|
+
[true, period_3_4, period_2_4],
|
288
|
+
[false, period_2_4, period_4_5],
|
289
|
+
[false, period_2_4, period_5_6]].each do |sample|
|
290
|
+
assert_equal(sample[0], sample[1].include?(sample[2]))
|
291
|
+
end
|
292
|
+
|
293
|
+
period_1_2 = -When::Parts::GeometricComplex.new(1...2)
|
294
|
+
period_2_3 = -When::Parts::GeometricComplex.new(2...3)
|
295
|
+
period_3_4 = -When::Parts::GeometricComplex.new(3...4)
|
296
|
+
period_4_5 = -When::Parts::GeometricComplex.new(4...5)
|
297
|
+
period_5_6 = -When::Parts::GeometricComplex.new(5...6)
|
298
|
+
|
299
|
+
period_2_4 = -When::Parts::GeometricComplex.new(2...4)
|
300
|
+
period_3_6 = -When::Parts::GeometricComplex.new(3...6)
|
301
|
+
period_4_6 = -When::Parts::GeometricComplex.new(4...6)
|
302
|
+
period_1_6 = -When::Parts::GeometricComplex.new(1...6)
|
303
|
+
|
304
|
+
[[false, period_4_6, period_1_2],
|
305
|
+
[false, period_2_4, period_1_2],
|
306
|
+
[false, period_3_6, period_2_4],
|
307
|
+
[false, period_2_4, period_2_3],
|
308
|
+
[true, period_2_3, period_2_4],
|
309
|
+
|
310
|
+
[false, period_1_6, period_2_4],
|
311
|
+
[true, period_2_4, period_1_6],
|
312
|
+
[true, period_2_4, period_2_4],
|
313
|
+
|
314
|
+
[false, period_2_4, period_3_6],
|
315
|
+
[false, period_2_4, period_3_4],
|
316
|
+
[true, period_3_4, period_2_4],
|
317
|
+
[false, period_2_4, period_4_5],
|
318
|
+
[false, period_2_4, period_5_6]].each do |sample|
|
319
|
+
assert_equal(sample[0], sample[1].include?(sample[2]))
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
def test__union
|
324
|
+
|
325
|
+
sample = [false, true, false, true, true, false]
|
326
|
+
complex = When::Parts::GeometricComplex.new(3..4)
|
327
|
+
complex |= 1
|
328
|
+
(0..5).each do |i|
|
329
|
+
assert_equal(sample.shift, complex.include?(i))
|
330
|
+
end
|
331
|
+
|
332
|
+
sample = [true, false, true, false, false, true]
|
333
|
+
complex = When::Parts::GeometricComplex.new(3..4)
|
334
|
+
complex |= 1
|
335
|
+
complex = -complex
|
336
|
+
(0..5).each do |i|
|
337
|
+
assert_equal(sample.shift, complex.include?(i))
|
338
|
+
end
|
339
|
+
|
340
|
+
sample = [false, true, false, true, false, false]
|
341
|
+
complex = When::Parts::GeometricComplex.new(3...4)
|
342
|
+
complex |= 1
|
343
|
+
(0..5).each do |i|
|
344
|
+
assert_equal(sample.shift, complex.include?(i))
|
345
|
+
end
|
346
|
+
|
347
|
+
sample = [true, false, true, false, true, true]
|
348
|
+
complex = When::Parts::GeometricComplex.new(3...4)
|
349
|
+
complex |= 1
|
350
|
+
complex = -complex
|
351
|
+
(0..5).each do |i|
|
352
|
+
assert_equal(sample.shift, complex.include?(i))
|
353
|
+
end
|
354
|
+
|
355
|
+
complex = When::Parts::GeometricComplex.new(3..5)
|
356
|
+
(3..5).each do |i|
|
357
|
+
union = complex | i
|
358
|
+
assert_equal(complex, union)
|
359
|
+
end
|
360
|
+
|
361
|
+
assert_equal(When::Parts::GeometricComplex.new(3..5),
|
362
|
+
When::Parts::GeometricComplex.new(3...5) | 5)
|
363
|
+
|
364
|
+
null = When::Parts::GeometricComplex.new(false)
|
365
|
+
all = When::Parts::GeometricComplex.new(true)
|
366
|
+
period_1_2 = When::Parts::GeometricComplex.new(1..2)
|
367
|
+
period_2_3 = When::Parts::GeometricComplex.new(2..3)
|
368
|
+
period_3_4 = When::Parts::GeometricComplex.new(3..4)
|
369
|
+
period_4_5 = When::Parts::GeometricComplex.new(4..5)
|
370
|
+
period_5_6 = When::Parts::GeometricComplex.new(5..6)
|
371
|
+
|
372
|
+
period_1_4 = When::Parts::GeometricComplex.new(1..4)
|
373
|
+
period_2_4 = When::Parts::GeometricComplex.new(2..4)
|
374
|
+
period_2_5 = When::Parts::GeometricComplex.new(2..5)
|
375
|
+
period_2_6 = When::Parts::GeometricComplex.new(2..6)
|
376
|
+
period_3_6 = When::Parts::GeometricComplex.new(3..6)
|
377
|
+
period_4_6 = When::Parts::GeometricComplex.new(4..6)
|
378
|
+
period_1_6 = When::Parts::GeometricComplex.new(1..6)
|
379
|
+
|
380
|
+
period_1_2_4_6 = When::Parts::GeometricComplex.new([[1,true],[2,true],[4,true],[6,true]])
|
381
|
+
period_2_4_5_6 = When::Parts::GeometricComplex.new([[2,true],[4,true],[5,true],[6,true]])
|
382
|
+
|
383
|
+
[[period_1_2_4_6, null, period_1_2_4_6],
|
384
|
+
[period_1_2_4_6, period_1_2_4_6, null],
|
385
|
+
[all, all, period_1_2_4_6],
|
386
|
+
[all, period_1_2_4_6, all],
|
387
|
+
[period_1_2_4_6, period_1_2, period_4_6],
|
388
|
+
[period_1_4, period_1_2, period_2_4],
|
389
|
+
[period_2_6, period_2_4, period_3_6],
|
390
|
+
[period_2_4, period_2_3, period_2_4],
|
391
|
+
[period_2_4, period_2_4, period_2_3],
|
392
|
+
|
393
|
+
[period_1_6, period_2_4, period_1_6],
|
394
|
+
[period_1_6, period_1_6, period_2_4],
|
395
|
+
[period_2_4, period_2_4, period_2_4],
|
396
|
+
|
397
|
+
[period_2_6, period_3_6, period_2_4],
|
398
|
+
[period_2_4, period_3_4, period_2_4],
|
399
|
+
[period_2_4, period_2_4, period_3_4],
|
400
|
+
[period_2_5, period_4_5, period_2_4],
|
401
|
+
[period_2_4_5_6, period_5_6, period_2_4]].each do |sample|
|
402
|
+
assert_equal(sample[0], sample[1] | sample[2])
|
403
|
+
end
|
404
|
+
|
405
|
+
period_1_2 = When::Parts::GeometricComplex.new(1...2)
|
406
|
+
period_2_3 = When::Parts::GeometricComplex.new(2...3)
|
407
|
+
period_3_4 = When::Parts::GeometricComplex.new(3...4)
|
408
|
+
period_4_5 = When::Parts::GeometricComplex.new(4...5)
|
409
|
+
period_5_6 = When::Parts::GeometricComplex.new(5...6)
|
410
|
+
|
411
|
+
period_1_4 = When::Parts::GeometricComplex.new(1...4)
|
412
|
+
period_2_4 = When::Parts::GeometricComplex.new(2...4)
|
413
|
+
period_2_5 = When::Parts::GeometricComplex.new(2...5)
|
414
|
+
period_2_6 = When::Parts::GeometricComplex.new(2...6)
|
415
|
+
period_3_6 = When::Parts::GeometricComplex.new(3...6)
|
416
|
+
period_4_6 = When::Parts::GeometricComplex.new(4...6)
|
417
|
+
period_1_6 = When::Parts::GeometricComplex.new(1...6)
|
418
|
+
|
419
|
+
period_1_2_4_6 = When::Parts::GeometricComplex.new([[1,true],[2,false],[4,true],[6,false]])
|
420
|
+
period_2_4_5_6 = When::Parts::GeometricComplex.new([[2,true],[4,false],[5,true],[6,false]])
|
421
|
+
|
422
|
+
[[period_1_2_4_6, null, period_1_2_4_6],
|
423
|
+
[period_1_2_4_6, period_1_2_4_6, null],
|
424
|
+
[all, all, period_1_2_4_6],
|
425
|
+
[all, period_1_2_4_6, all],
|
426
|
+
[period_1_2_4_6, period_1_2, period_4_6],
|
427
|
+
[period_1_4, period_1_2, period_2_4],
|
428
|
+
[period_2_6, period_2_4, period_3_6],
|
429
|
+
[period_2_4, period_2_3, period_2_4],
|
430
|
+
[period_2_4, period_2_4, period_2_3],
|
431
|
+
|
432
|
+
[period_1_6, period_2_4, period_1_6],
|
433
|
+
[period_1_6, period_1_6, period_2_4],
|
434
|
+
[period_2_4, period_2_4, period_2_4],
|
435
|
+
|
436
|
+
[period_2_6, period_3_6, period_2_4],
|
437
|
+
[period_2_4, period_3_4, period_2_4],
|
438
|
+
[period_2_4, period_2_4, period_3_4],
|
439
|
+
[period_2_5, period_4_5, period_2_4],
|
440
|
+
[period_2_4_5_6, period_5_6, period_2_4]].each do |sample|
|
441
|
+
assert_equal(sample[0], sample[1] | sample[2])
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
def test__include_in_sample
|
446
|
+
range_1_4 = When::Parts::GeometricComplex.new(1,4)
|
447
|
+
range_2_2 = When::Parts::GeometricComplex.new(2)
|
448
|
+
range_2_3 = When::Parts::GeometricComplex.new(2,3)
|
449
|
+
range_2_5 = When::Parts::GeometricComplex.new(2,5)
|
450
|
+
range_4_4 = When::Parts::GeometricComplex.new(4)
|
451
|
+
assert_equal(true, range_1_4.include?(range_2_2))
|
452
|
+
assert_equal(true, range_1_4.include?(range_2_3))
|
453
|
+
assert_equal(false, range_1_4.include?(range_2_5))
|
454
|
+
assert_equal(false, range_1_4.include?(range_4_4))
|
455
|
+
end
|
456
|
+
|
457
|
+
def test__union_in_sample
|
458
|
+
#range_null = When::Parts::GeometricComplex.new()
|
459
|
+
#range_1_1 = When::Parts::GeometricComplex.new(1)
|
460
|
+
range_1_4 = When::Parts::GeometricComplex.new(1,4)
|
461
|
+
range_2_2 = When::Parts::GeometricComplex.new(2)
|
462
|
+
range_2_3 = When::Parts::GeometricComplex.new(2,3)
|
463
|
+
range_2_5 = When::Parts::GeometricComplex.new(2,5)
|
464
|
+
range_4_4 = When::Parts::GeometricComplex.new(4)
|
465
|
+
assert_equal("1...4", range_1_4.to_s)
|
466
|
+
assert_equal("2...3", range_2_3.to_s)
|
467
|
+
sample = [1, 2, 3]
|
468
|
+
range_1_4.each {|x| assert_equal(sample.shift, x)}
|
469
|
+
assert_equal("4..4", range_4_4.to_s)
|
470
|
+
assert_equal("1...4", (range_1_4 | range_2_3).to_s)
|
471
|
+
range_1_5 = range_1_4 | range_2_5
|
472
|
+
assert_equal("1...5", range_1_5.to_s)
|
473
|
+
assert_equal("1..4", (range_1_4 | range_4_4).to_s)
|
474
|
+
reverse_all = When::Parts::GeometricComplex.new(true)
|
475
|
+
reverse_1_4 = When::Parts::GeometricComplex.new(1,4, true)
|
476
|
+
reverse_2_3 = When::Parts::GeometricComplex.new(2,3, true)
|
477
|
+
reverse_2_5 = When::Parts::GeometricComplex.new(2,5, true)
|
478
|
+
assert_equal("1..4", reverse_1_4.to_s)
|
479
|
+
assert_equal("2..3", reverse_2_3.to_s)
|
480
|
+
unless Float::INFINITY == Float::MAX
|
481
|
+
assert_equal("-Infinity..Infinity", reverse_all.to_s)
|
482
|
+
assert_equal("-Infinity..Infinity", (reverse_2_3 | range_2_3).to_s)
|
483
|
+
end
|
484
|
+
assert_equal("1..2", (reverse_1_4 | range_2_5).to_s)
|
485
|
+
end
|
486
|
+
end
|
487
|
+
end
|