runt19 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/History.txt +153 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +44 -0
- data/Manifest.txt +112 -0
- data/README.md +29 -0
- data/README.txt +106 -0
- data/Rakefile +2 -0
- data/TODO +13 -0
- data/examples/payment_report.rb +59 -0
- data/examples/payment_reporttest.rb +49 -0
- data/examples/reminder.rb +63 -0
- data/examples/schedule_tutorial.rb +59 -0
- data/examples/schedule_tutorialtest.rb +52 -0
- data/lib/runt.rb +249 -0
- data/lib/runt/daterange.rb +74 -0
- data/lib/runt/dprecision.rb +150 -0
- data/lib/runt/expressionbuilder.rb +65 -0
- data/lib/runt/pdate.rb +165 -0
- data/lib/runt/schedule.rb +88 -0
- data/lib/runt/sugar.rb +171 -0
- data/lib/runt/temporalexpression.rb +795 -0
- data/lib/runt/version.rb +3 -0
- data/lib/runt19.rb +1 -0
- data/runt19.gemspec +17 -0
- data/setup.rb +1331 -0
- data/site/blue-robot3.css +132 -0
- data/site/dcl-small.gif +0 -0
- data/site/index.html +72 -0
- data/site/logohover.png +0 -0
- data/site/runt-logo.gif +0 -0
- data/site/runt-logo.psd +0 -0
- data/test/aftertetest.rb +31 -0
- data/test/baseexpressiontest.rb +110 -0
- data/test/beforetetest.rb +31 -0
- data/test/collectiontest.rb +63 -0
- data/test/combinedexpressionstest.rb +158 -0
- data/test/daterangetest.rb +89 -0
- data/test/dayintervaltetest.rb +37 -0
- data/test/difftest.rb +37 -0
- data/test/dimonthtest.rb +59 -0
- data/test/diweektest.rb +32 -0
- data/test/dprecisiontest.rb +58 -0
- data/test/everytetest.rb +36 -0
- data/test/expressionbuildertest.rb +64 -0
- data/test/icalendartest.rb +1104 -0
- data/test/intersecttest.rb +34 -0
- data/test/pdatetest.rb +147 -0
- data/test/redaytest.rb +40 -0
- data/test/remonthtest.rb +37 -0
- data/test/reweektest.rb +51 -0
- data/test/reyeartest.rb +99 -0
- data/test/rspectest.rb +25 -0
- data/test/runttest.rb +98 -0
- data/test/scheduletest.rb +148 -0
- data/test/spectest.rb +36 -0
- data/test/sugartest.rb +104 -0
- data/test/temporalexpressiontest.rb +76 -0
- data/test/uniontest.rb +36 -0
- data/test/wimonthtest.rb +54 -0
- data/test/yeartetest.rb +22 -0
- metadata +137 -0
@@ -0,0 +1,158 @@
|
|
1
|
+
|
2
|
+
#!/usr/bin/env ruby
|
3
|
+
|
4
|
+
require 'baseexpressiontest'
|
5
|
+
|
6
|
+
# Unit tests for composite temporal expressions
|
7
|
+
# Author:: Matthew Lipper
|
8
|
+
|
9
|
+
class CombinedExpressionTest < BaseExpressionTest
|
10
|
+
|
11
|
+
def test_dates_on_last_fri_or_first_tues
|
12
|
+
date_range = @date_20050101..@date_20051231
|
13
|
+
expr = DIMonth.new(Last, Friday) | DIMonth.new(First, Tuesday)
|
14
|
+
dates = expr.dates(date_range)
|
15
|
+
assert_equal 24, dates.size, "Expected 24 dates in 2005 which were either on the last Friday or first Tuesday of the month"
|
16
|
+
month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
17
|
+
dates.each do |d|
|
18
|
+
unless (d.wday == 2 and d.day < 8) or \
|
19
|
+
(d.wday == 5 and d.day > month_days[d.month-1] - 8)
|
20
|
+
# Fail
|
21
|
+
assert false, d.to_s
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_january_except_from_7th_to_15th
|
27
|
+
date_range = @date_20050101..@date_20050131
|
28
|
+
dates = (REYear.new(1, 1, 1, 31) - REMonth.new(7, 15)).dates(date_range)
|
29
|
+
assert_equal 22, dates.size, "Expected 22 dates: 1/1-1/6, 1/16-1/31"
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_work_day
|
33
|
+
# Should match for 9am to 5pm except for 12pm to 1pm
|
34
|
+
expr = REDay.new(9,0,17,0) - REDay.new(12,0,13,0)
|
35
|
+
assert expr.include?(@pdate_200405030906), "Expression #{expr.to_s} should include #{@pdate_200405030906.to_s}"
|
36
|
+
assert !expr.include?(@pdate_1975060512), "Expression #{expr.to_s} should not include #{@pdate_1975060512.to_s}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_monday_tuesday_8am_to_9am
|
40
|
+
expr = REWeek.new(Mon,Fri) & REDay.new(8,0,9,0)
|
41
|
+
assert expr.include?(@pdate_200405040806), "Expression #{expr.to_s} should include #{@pdate_200405040806.to_s}"
|
42
|
+
assert !expr.include?(@pdate_200405010806), "Expression #{expr.to_s} should not include #{@pdate_200405010806.to_s}"
|
43
|
+
assert !expr.include?(@pdate_200405030906), "Expression #{expr.to_s} should not include #{@pdate_200405030906.to_s}"
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def test_midnight_to_9am_or_tuesday
|
48
|
+
expr = REDay.new(0,0,9,0) | DIWeek.new(Tuesday)
|
49
|
+
assert expr.include?(@pdate_20071030), "Expression #{expr.to_s} should include #{@pdate_20071030.to_s}"
|
50
|
+
assert expr.include?(@pdate_2012050803), "Expression #{expr.to_s} should include #{@pdate_2012050803.to_s}"
|
51
|
+
assert !expr.include?(@pdate_20071116100030), "Expression #{expr.to_s} should not include #{@pdate_20071116100030.to_s}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_wednesday_thru_saturday_6_to_12am
|
55
|
+
expr = REWeek.new(Wed, Sat) & REDay.new(6,0,12,00)
|
56
|
+
assert !expr.include?(@time_20070926000000), "Expression #{expr.to_s} should include #{@time_20070926000000.to_s}"
|
57
|
+
assert expr.include?(@time_20070927065959), "Expression #{expr.to_s} should include #{@time_20070927065959.to_s}"
|
58
|
+
assert !expr.include?(@time_20070928000000), "Expression #{expr.to_s} should include #{@time_20070928000000.to_s}"
|
59
|
+
assert expr.include?(@time_20070929110000), "Expression #{expr.to_s} should include #{@time_20070929110000.to_s}"
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_memorial_day
|
63
|
+
# Monday through Friday, from 9am to 5pm
|
64
|
+
job = REWeek.new(Mon,Fri) & REDay.new(9,00,17,00)
|
65
|
+
# Memorial Day (U.S.)
|
66
|
+
memorial_day = REYear.new(5) & DIMonth.new(Last,Monday)
|
67
|
+
# May 29th, 2006
|
68
|
+
last_monday_in_may = @pdate_200605291012
|
69
|
+
# Before
|
70
|
+
assert job.include?(last_monday_in_may), "Expression #{job.to_s} should include #{last_monday_in_may.to_s}"
|
71
|
+
assert job.include?(@pdate_200605301400), "Expression #{job.to_s} should include #{@pdate_200605301400.to_s}"
|
72
|
+
# Add Diff expression
|
73
|
+
job_with_holiday = job - last_monday_in_may
|
74
|
+
assert !job_with_holiday.include?(last_monday_in_may), "Expression #{job_with_holiday.to_s} should not include #{last_monday_in_may.to_s}"
|
75
|
+
# Still have to work on Tuesday
|
76
|
+
assert job.include?(@pdate_200605301400), "Expression #{job.to_s} should include #{@pdate_200605301400.to_s}"
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_summertime
|
80
|
+
#This is a hack.....
|
81
|
+
#In the U.S., Memorial Day begins the last Monday of May
|
82
|
+
#
|
83
|
+
#The month of May
|
84
|
+
may=REYear.new(5)
|
85
|
+
#Monday through Saturday
|
86
|
+
monday_to_saturday = REWeek.new(1,6)
|
87
|
+
#Last week of (any) month
|
88
|
+
last_week_in = WIMonth.new(Last_of)
|
89
|
+
#So, to say 'starting from the last Monday in May',
|
90
|
+
#we need to select just that last week of May begining with
|
91
|
+
#the Monday of that week
|
92
|
+
last_week_of_may = may & monday_to_saturday & last_week_in
|
93
|
+
|
94
|
+
#This is another hack similar to the above, except instead of selecting a range
|
95
|
+
#starting at the begining of the month, we need to select only the time period in
|
96
|
+
#September up until Labor Day.
|
97
|
+
#
|
98
|
+
#In the U.S., Labor Day is the first Monday in September
|
99
|
+
#
|
100
|
+
#The month of September
|
101
|
+
september=REYear.new(9)
|
102
|
+
#First week of (any) month
|
103
|
+
first_week_in = WIMonth.new(First)
|
104
|
+
entire_first_week_of_september = september & first_week_in
|
105
|
+
#To exclude everything in the first week which occurs on or after Monday.
|
106
|
+
first_week_of_september=entire_first_week_of_september - monday_to_saturday
|
107
|
+
#June through August
|
108
|
+
june_through_august=REYear.new(6, 1, 8)
|
109
|
+
assert june_through_august.include?(@pdate_20040704), "Expression #{june_through_august.to_s} should include #{@pdate_20040704.to_s}"
|
110
|
+
#Finally!
|
111
|
+
summer_time = last_week_of_may | first_week_of_september | june_through_august
|
112
|
+
|
113
|
+
#Will work, but will be incredibly slow:
|
114
|
+
# assert(summer_time.include?(PDate.min(2004,5,31,0,0)))
|
115
|
+
assert summer_time.include?(@pdate_20040531), "Expression #{summer_time.to_s} should include #{@pdate_20040704.to_s}"
|
116
|
+
assert summer_time.include?(@pdate_20040704), "Expression #{summer_time.to_s} should include #{@pdate_20040704.to_s}"
|
117
|
+
#also works...also slow:
|
118
|
+
# assert(!summer_time.include?(PDate.min(2004,9,6,0,0)))
|
119
|
+
assert !summer_time.include?(@pdate_2004090600), "Expression #{summer_time.to_s} should not include #{@pdate_2004090600.to_s}"
|
120
|
+
|
121
|
+
end
|
122
|
+
def test_nyc_parking_te
|
123
|
+
|
124
|
+
#Monday, Wednesday, Friday
|
125
|
+
mon_wed_fri = DIWeek.new(Mon) | \
|
126
|
+
DIWeek.new(Wed) | \
|
127
|
+
DIWeek.new(Fri)
|
128
|
+
|
129
|
+
assert mon_wed_fri.include?(@datetime_200403101915), "Expression #{mon_wed_fri.to_s} should include #{@datetime_200403101915.to_s}"
|
130
|
+
assert !mon_wed_fri.include?(@datetime_200403140900), "Expression #{mon_wed_fri.to_s} should not include #{@datetime_200403140900.to_s}"
|
131
|
+
# 8am to 11am
|
132
|
+
eight_to_eleven = REDay.new(8,00,11,00)
|
133
|
+
# => Mon,Wed,Fri - 8am to 11am
|
134
|
+
expr1 = mon_wed_fri & eight_to_eleven
|
135
|
+
# Tuesdays, Thursdays
|
136
|
+
tues_thurs = DIWeek.new(Tue) | DIWeek.new(Thu)
|
137
|
+
# 11:30am to 2pm
|
138
|
+
eleven_thirty_to_two = REDay.new(11,30,14,00)
|
139
|
+
assert eleven_thirty_to_two.include?(@datetime_200403081200), "Expression #{eleven_thirty_to_two.to_s} should include #{@datetime_200403081200.to_s}"
|
140
|
+
assert !eleven_thirty_to_two.include?(@datetime_200403110000), "Expression #{eleven_thirty_to_two.to_s} should not include #{@datetime_200403110000.to_s}"
|
141
|
+
# => Tues,Thurs - 11:30am to 2pm
|
142
|
+
expr2 = tues_thurs & eleven_thirty_to_two
|
143
|
+
#
|
144
|
+
# No parking: Mon Wed Fri, 8am - 11am
|
145
|
+
# Tu Thu, 11:30am - 2pm
|
146
|
+
parking_ticket = expr1 | expr2
|
147
|
+
assert parking_ticket.include?(@datetime_200403111215), "Expression #{parking_ticket.to_s} should include #{@datetime_200403111215.to_s}"
|
148
|
+
assert parking_ticket.include?(@datetime_200403100915), "Expression #{parking_ticket.to_s} should include #{@datetime_200403100915.to_s}"
|
149
|
+
assert parking_ticket.include?(@datetime_200403100800), "Expression #{parking_ticket.to_s} should include #{@datetime_200403100800.to_s}"
|
150
|
+
assert !parking_ticket.include?(@datetime_200403110115), "Expression #{parking_ticket.to_s} should not include #{@datetime_200403110115.to_s}"
|
151
|
+
|
152
|
+
# The preceeding example can be condensed to:
|
153
|
+
# e1 = (DIWeek.new(Mon) | DIWeek.new(Wed) | DIWeek.new(Fri)) & REDay.new(8,00,11,00)
|
154
|
+
# e2 = (DIWeek.new(Tue) | DIWeek.new(Thu)) & REDay.new(11,30,14,00)
|
155
|
+
# ticket = e1 | e2
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'runt'
|
5
|
+
require 'date'
|
6
|
+
|
7
|
+
# Unit tests for DateRange class
|
8
|
+
#
|
9
|
+
# Author:: Matthew Lipper
|
10
|
+
class DateRangeTest < Test::Unit::TestCase
|
11
|
+
|
12
|
+
include Runt
|
13
|
+
|
14
|
+
def test_sub_range
|
15
|
+
r_start = PDate.sec(2004,2,29,16,24,12)
|
16
|
+
r_end = PDate.sec(2004,3,2,4,22,58)
|
17
|
+
range = DateRange.new(r_start,r_end)
|
18
|
+
assert(range.min==r_start)
|
19
|
+
assert(range.max==r_end)
|
20
|
+
assert(range.include?(r_start+1))
|
21
|
+
assert(range.include?(r_end-1))
|
22
|
+
sub_range = DateRange.new((r_start+1),(r_end-1))
|
23
|
+
assert(range.include?(sub_range))
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_date
|
27
|
+
r_start = PDate.min(1979,12,31,23,57)
|
28
|
+
r_end = PDate.min(1980,1,1,0,2)
|
29
|
+
range = DateRange.new(r_start,r_end)
|
30
|
+
assert(range.min==r_start)
|
31
|
+
assert(range.max==r_end)
|
32
|
+
assert(range.include?(r_start+1))
|
33
|
+
assert(range.include?(r_end-1))
|
34
|
+
sub_range = DateRange.new((r_start+1),(r_end-1))
|
35
|
+
assert(range.include?(sub_range))
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_spaceship_operator
|
39
|
+
r_start = PDate.min(1984,8,31,22,00)
|
40
|
+
r_end = PDate.min(1984,9,15,0,2)
|
41
|
+
range = DateRange.new(r_start,r_end)
|
42
|
+
assert(-1==(range<=>(DateRange.new(r_start+2,r_end+5))))
|
43
|
+
assert(1==(range<=>(DateRange.new(r_start-24,r_end+5))))
|
44
|
+
assert(0==(range<=>(DateRange.new(r_start,r_end))))
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_overlap
|
48
|
+
r_start = PDate.month(2010,12)
|
49
|
+
r_end = PDate.month(2011,12)
|
50
|
+
range = DateRange.new(r_start,r_end)
|
51
|
+
o_start = PDate.month(2010,11)
|
52
|
+
o_end = PDate.month(2012,2)
|
53
|
+
o_range = DateRange.new(o_start,o_end)
|
54
|
+
assert(range.overlap?(o_range))
|
55
|
+
assert(o_range.overlap?(range))
|
56
|
+
assert(o_range.overlap?(DateRange.new(r_start,o_end)))
|
57
|
+
assert(o_range.overlap?(DateRange.new(o_start,r_end)))
|
58
|
+
|
59
|
+
# September 18th - 19th, 2005, 8am - 10am
|
60
|
+
expr1=DateRange.new(PDate.day(2005,9,18),PDate.day(2005,9,19))
|
61
|
+
# September 19th - 20th, 2005, 9am - 11am
|
62
|
+
expr2=DateRange.new(PDate.day(2005,9,19),PDate.day(2005,9,20))
|
63
|
+
|
64
|
+
assert(expr1.overlap?(expr2))
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_empty
|
68
|
+
r_start = PDate.hour(2004,2,10,0)
|
69
|
+
r_end = PDate.hour(2004,2,9,23)
|
70
|
+
empty_range = DateRange.new(r_start,r_end)
|
71
|
+
assert(empty_range.empty?)
|
72
|
+
assert(DateRange::EMPTY.empty?)
|
73
|
+
# start == end should be empty
|
74
|
+
assert DateRange.new(r_start,r_start).empty?, "Range should be empty when start == end"
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_gap
|
78
|
+
r_start = PDate.day(2000,6,12)
|
79
|
+
r_end = PDate.day(2000,6,14)
|
80
|
+
range = DateRange.new(r_start,r_end)
|
81
|
+
g_start = PDate.day(2000,6,18)
|
82
|
+
g_end = PDate.day(2000,6,20)
|
83
|
+
g_range = DateRange.new(g_start,g_end)
|
84
|
+
the_gap=range.gap(g_range)
|
85
|
+
assert(the_gap.start_expr==(r_end+1))
|
86
|
+
assert(the_gap.end_expr==(g_start-1))
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'baseexpressiontest'
|
4
|
+
|
5
|
+
# Unit tests for DayIntervalTE class
|
6
|
+
# Author:: Matthew Lipper
|
7
|
+
|
8
|
+
class DayIntervalTETest < BaseExpressionTest
|
9
|
+
|
10
|
+
|
11
|
+
def test_every_8_days
|
12
|
+
date = @date_20040116
|
13
|
+
# Match every 8 days
|
14
|
+
expr = DayIntervalTE.new(date, 8)
|
15
|
+
assert expr.include?(date + 8), "Expression #{expr.to_s} should include #{(date + 8).to_s}"
|
16
|
+
assert expr.include?(date + 16), "Expression #{expr.to_s} should include #{(date + 16).to_s}"
|
17
|
+
assert expr.include?(date + 64), "Expression #{expr.to_s} should include #{(date + 64).to_s}"
|
18
|
+
assert !expr.include?(date + 4), "Expression #{expr.to_s} should not include #{(date + 4).to_s}"
|
19
|
+
# FIXME This test fails
|
20
|
+
#assert !expr.include?(date - 8), "Expression #{expr.to_s} should not include #{(date - 8).to_s}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_every_2_days
|
24
|
+
date = @datetime_200709161007
|
25
|
+
expr = DayIntervalTE.new(date, 2)
|
26
|
+
assert expr.include?(date + 2), "Expression #{expr.to_s} should include #{(date + 2).to_s}"
|
27
|
+
assert expr.include?(date + 4), "Expression #{expr.to_s} should include #{(date + 4).to_s}"
|
28
|
+
assert !expr.include?(date + 3), "Expression #{expr.to_s} should not include #{(date + 3).to_s}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_to_s
|
32
|
+
every_four_days = DayIntervalTE.new(Date.new(2006,2,26), 4)
|
33
|
+
assert_equal "every 4th day after #{Runt.format_date(Date.new(2006,2,26))}", every_four_days.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
end
|
data/test/difftest.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'baseexpressiontest'
|
4
|
+
|
5
|
+
# Unit tests for Diff class
|
6
|
+
# Author:: Matthew Lipper
|
7
|
+
|
8
|
+
class DiffTest < BaseExpressionTest
|
9
|
+
|
10
|
+
def setup
|
11
|
+
super
|
12
|
+
@diff = Diff.new(@stub1, @stub2)
|
13
|
+
@date = @pdate_20071008
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_initialize
|
17
|
+
assert_same @stub1, @diff.expr1, "Expected #{@stub1} instance used to create expression. Instead got #{@diff.expr1}"
|
18
|
+
assert_same @stub2, @diff.expr2, "Expected #{@stub2} instance used to create expression. Instead got #{@diff.expr2}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_to_s
|
22
|
+
assert_equal @stub1.to_s + ' except for ' + @stub2.to_s, @diff.to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_include
|
26
|
+
# Diff will match only if expr1 && !expr2
|
27
|
+
@stub1.match = false
|
28
|
+
@stub2.match = false
|
29
|
+
assert !@diff.include?(@date), "Diff instance should not include any dates"
|
30
|
+
@stub2.match = true
|
31
|
+
assert !@diff.include?(@date), "Diff instance should not include any dates"
|
32
|
+
@stub1.match = true
|
33
|
+
assert !@diff.include?(@date), "Diff instance should not include any dates"
|
34
|
+
@stub2.match = false
|
35
|
+
assert @diff.include?(@date), "Diff instance should include any dates"
|
36
|
+
end
|
37
|
+
end
|
data/test/dimonthtest.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'baseexpressiontest'
|
4
|
+
|
5
|
+
# Unit tests for DIMonth class
|
6
|
+
# Author:: Matthew Lipper
|
7
|
+
|
8
|
+
class DIMonthTest < BaseExpressionTest
|
9
|
+
def setup
|
10
|
+
super
|
11
|
+
@date_range = @date_20050101..@date_20051231
|
12
|
+
end
|
13
|
+
|
14
|
+
###
|
15
|
+
# Dates functionality & tests contributed by Emmett Shear
|
16
|
+
###
|
17
|
+
def test_dates_mixin_first_tuesday
|
18
|
+
dates = DIMonth.new(First, Tuesday).dates(@date_range)
|
19
|
+
assert dates.size == 12
|
20
|
+
dates.each do |d|
|
21
|
+
assert @date_range.include?(d)
|
22
|
+
assert d.wday == 2 # tuesday
|
23
|
+
assert d.day < 8 # in the first week
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_dates_mixin_last_friday
|
28
|
+
dates = DIMonth.new(Last, Friday).dates(@date_range)
|
29
|
+
assert dates.size == 12
|
30
|
+
month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
31
|
+
dates.each do |d|
|
32
|
+
assert @date_range.include?(d)
|
33
|
+
assert d.wday == 5 # friday
|
34
|
+
assert d.day > month_days[d.month-1] - 8 # last week
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_third_friday_of_the_month
|
39
|
+
expr = DIMonth.new(Third,Friday)
|
40
|
+
assert expr.include?(@date_20040116), "Third Friday of the month should include #{@date_20040116.to_s}"
|
41
|
+
assert !expr.include?(@date_20040109), "Third Friday of the month should not include #{@date_20040109.to_s}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_second_friday_of_the_month
|
45
|
+
expr = DIMonth.new(Second,Friday)
|
46
|
+
assert expr.include?(@date_20040109), "Second Friday of the month should include #{@date_20040109.to_s}"
|
47
|
+
assert !expr.include?(@date_20040116), "Second Friday of the month should not include #{@date_20040116.to_s}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_last_sunday_of_the_month
|
51
|
+
expr = DIMonth.new(Last_of,Sunday)
|
52
|
+
assert expr.include?(@date_20040125), "Last Sunday of the month should include #{@date_20040125}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_to_s
|
56
|
+
assert_equal 'last Sunday of the month', DIMonth.new(Last_of,Sunday).to_s
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
data/test/diweektest.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'baseexpressiontest'
|
4
|
+
|
5
|
+
# Unit tests for DIWeek class
|
6
|
+
# Author:: Matthew Lipper
|
7
|
+
|
8
|
+
class DIWeekTest < BaseExpressionTest
|
9
|
+
|
10
|
+
def test_day_in_week_te
|
11
|
+
expr = DIWeek.new(Friday)
|
12
|
+
assert expr.include?(@date_20040109), "'Friday' should include #{@date_20040109} which is a Friday"
|
13
|
+
assert expr.include?(@date_20040116), "'Friday' should include #{@date_20040116} which is a Friday"
|
14
|
+
assert !expr.include?(@date_20040125), "'Friday' should not include #{@date_20040125} which is a Sunday"
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_day_in_week_te_to_s
|
18
|
+
assert_equal 'Friday', DIWeek.new(Friday).to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_day_in_week_dates
|
22
|
+
expr = DIWeek.new(Sunday)
|
23
|
+
dates = expr.dates(@date_20050101..@date_20050131)
|
24
|
+
assert dates.size == 5, "There are five Sundays in January, 2005: found #{dates.size}"
|
25
|
+
assert dates.include?(@date_20050102), "Should include #{@date_20050102}"
|
26
|
+
assert dates.include?(@date_20050109), "Should include #{@date_20050109}"
|
27
|
+
assert dates.include?(@date_20050116), "Should include #{@date_20050116}"
|
28
|
+
assert dates.include?(@date_20050123), "Should include #{@date_20050123}"
|
29
|
+
assert dates.include?(@date_20050130), "Should include #{@date_20050130}"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'runt'
|
5
|
+
require 'date'
|
6
|
+
|
7
|
+
# Unit tests for DPrecision class
|
8
|
+
#
|
9
|
+
# Author:: Matthew Lipper
|
10
|
+
|
11
|
+
class DPrecisionTest < Test::Unit::TestCase
|
12
|
+
|
13
|
+
include Runt
|
14
|
+
|
15
|
+
def test_comparable
|
16
|
+
assert(DPrecision::YEAR<DPrecision::MONTH, "DPrecision.year was not less than DPrecision.month")
|
17
|
+
assert(DPrecision::MONTH<DPrecision::WEEK, "DPrecision.month was not less than DPrecision.week")
|
18
|
+
assert(DPrecision::WEEK<DPrecision::DAY, "DPrecision.week was not less than DPrecision.day")
|
19
|
+
assert(DPrecision::DAY<DPrecision::HOUR, "DPrecision.day was not less than DPrecision.hour")
|
20
|
+
assert(DPrecision::HOUR<DPrecision::MIN, "DPrecision.hour was not less than DPrecision.min")
|
21
|
+
assert(DPrecision::MIN<DPrecision::SEC, "DPrecision.min was not less than DPrecision.sec")
|
22
|
+
assert(DPrecision::SEC<DPrecision::MILLI, "DPrecision.sec was not less than DPrecision.millisec")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_pseudo_singleton_instance
|
26
|
+
assert(DPrecision::YEAR.object_id==DPrecision::YEAR.object_id, "Object Id's not equal.")
|
27
|
+
assert(DPrecision::MONTH.object_id==DPrecision::MONTH.object_id, "Object Id's not equal.")
|
28
|
+
assert(DPrecision::WEEK.object_id==DPrecision::WEEK.object_id, "Object Id's not equal.")
|
29
|
+
assert(DPrecision::DAY.object_id==DPrecision::DAY.object_id, "Object Id's not equal.")
|
30
|
+
assert(DPrecision::HOUR.object_id==DPrecision::HOUR.object_id, "Object Id's not equal.")
|
31
|
+
assert(DPrecision::MIN.object_id==DPrecision::MIN.object_id, "Object Id's not equal.")
|
32
|
+
assert(DPrecision::SEC.object_id==DPrecision::SEC.object_id, "Object Id's not equal.")
|
33
|
+
assert(DPrecision::MILLI.object_id==DPrecision::MILLI.object_id, "Object Id's not equal.")
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_to_precision
|
37
|
+
#February 29th, 2004
|
38
|
+
no_prec_date = PDate.civil(2004,2,29)
|
39
|
+
month_prec = PDate.month(2004,2,29)
|
40
|
+
assert(month_prec==DPrecision.to_p(no_prec_date,DPrecision::MONTH))
|
41
|
+
#11:59:59 am, February 29th, 2004
|
42
|
+
no_prec_datetime = PDate.civil(2004,2,29,23,59,59)
|
43
|
+
#puts "-->#{no_prec_datetime.date_precision}<--"
|
44
|
+
assert(month_prec==DPrecision.to_p(no_prec_datetime,DPrecision::MONTH))
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_label
|
48
|
+
assert_equal(DPrecision::YEAR.label,"YEAR")
|
49
|
+
assert_equal(DPrecision::MONTH.label,"MONTH")
|
50
|
+
assert_equal(DPrecision::WEEK.label,"WEEK")
|
51
|
+
assert_equal(DPrecision::DAY.label,"DAY")
|
52
|
+
assert_equal(DPrecision::HOUR.label,"HOUR")
|
53
|
+
assert_equal(DPrecision::MIN.label,"MINUTE")
|
54
|
+
assert_equal(DPrecision::SEC.label,"SECOND")
|
55
|
+
assert_equal(DPrecision::MILLI.label,"MILLISECOND")
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|