/
dimonthtest.rb
59 lines (49 loc) · 1.84 KB
/
dimonthtest.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env ruby
require 'baseexpressiontest'
# Unit tests for DIMonth class
# Author:: Matthew Lipper
class DIMonthTest < BaseExpressionTest
def setup
super
@date_range = @date_20050101..@date_20051231
end
###
# Dates functionality & tests contributed by Emmett Shear
###
def test_dates_mixin_first_tuesday
dates = DIMonth.new(First, Tuesday).dates(@date_range)
assert dates.size == 12
dates.each do |d|
assert @date_range.include?(d)
assert d.wday == 2 # tuesday
assert d.day < 8 # in the first week
end
end
def test_dates_mixin_last_friday
dates = DIMonth.new(Last, Friday).dates(@date_range)
assert dates.size == 12
month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
dates.each do |d|
assert @date_range.include?(d)
assert d.wday == 5 # friday
assert d.day > month_days[d.month-1] - 8 # last week
end
end
def test_third_friday_of_the_month
expr = DIMonth.new(Third,Friday)
assert expr.include?(@date_20040116), "Third Friday of the month should include #{@date_20040116.to_s}"
assert !expr.include?(@date_20040109), "Third Friday of the month should not include #{@date_20040109.to_s}"
end
def test_second_friday_of_the_month
expr = DIMonth.new(Second,Friday)
assert expr.include?(@date_20040109), "Second Friday of the month should include #{@date_20040109.to_s}"
assert !expr.include?(@date_20040116), "Second Friday of the month should not include #{@date_20040116.to_s}"
end
def test_last_sunday_of_the_month
expr = DIMonth.new(Last_of,Sunday)
assert expr.include?(@date_20040125), "Last Sunday of the month should include #{@date_20040125}"
end
def test_to_s
assert_equal 'last Sunday of the month', DIMonth.new(Last_of,Sunday).to_s
end
end