runt 0.6.0 → 0.7.0

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.
@@ -1,117 +1,147 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'date'
5
- require 'runt'
6
-
7
- # Unit tests for PDate class
8
- # Author:: Matthew Lipper
9
- class PDateTest < Test::Unit::TestCase
10
-
11
- include Runt
12
-
13
- def setup
14
- # 2010 (August - ignored)
15
- @year_prec = PDate.year(2010,8)
16
- #August, 2004
17
- @month_prec = PDate.month(2004,8)
18
- #January 25th, 2004 (11:39 am - ignored)
19
- @day_prec = PDate.day(2004,1,25,11,39)
20
- #11:59(:04 - ignored), December 31st, 1999
21
- @minute_prec = PDate.min(1999,12,31,23,59,4)
22
- #12:00:10 am, March 1st, 2004
23
- @second_prec = PDate.sec(2004,3,1,0,0,10)
24
- end
25
-
26
- def test_marshal
27
- # Thanks to Jodi Showers for finding/fixing this bug
28
- pdate=PDate.new(2004,2,29,22,13,2)
29
- assert_not_nil pdate.date_precision
30
- data=Marshal.dump pdate
31
- obj=Marshal.load data
32
- assert_not_nil obj.date_precision
33
- end
34
-
35
- def test_include
36
- pdate = PDate.new(2006,3,10)
37
- assert(pdate.include?(Date.new(2006,3,10)))
38
- date = Date.new(2006,3,10)
39
- assert(date.include?(PDate.new(2006,3,10)))
40
- end
41
-
42
- def test_new
43
- date = PDate.new(2004,2,29)
44
- assert(!date.date_precision.nil?)
45
- date_time = PDate.new(2004,2,29,22,13,2)
46
- assert(!date_time.date_precision.nil?)
47
- date2 = PDate.day(2004,2,29)
48
- assert(date==date2)
49
- date_time2 = PDate.sec(2004,2,29,22,13,2)
50
- assert(date_time==date_time2)
51
- end
52
-
53
- def test_plus
54
- assert(PDate.year(2022,12)==(@year_prec+12))
55
- assert(PDate.month(2005,2)==(@month_prec+6))
56
- assert(PDate.day(2004,2,1)==(@day_prec+7))
57
- assert(PDate.min(2000,1,1,0,0)==(@minute_prec+1))
58
- assert(PDate.sec(2004,3,1,0,0,21)==(@second_prec+11))
59
- end
60
-
61
- def test_minus
62
- assert(PDate.year(1998,12)==(@year_prec-12))
63
- assert(PDate.month(2002,6)==(@month_prec-26))
64
- #Hmmm...FIXME? @day_prec-26 == 12/31??
65
- assert(PDate.day(2003,12,30)==(@day_prec-26))
66
- assert(PDate.min(1999,12,31,21,57)==(@minute_prec-122))
67
- assert(PDate.sec(2004,2,29,23,59,59)==(@second_prec-11))
68
- end
69
- def test_spaceship_comparison_operator
70
- sec_prec = PDate.sec(2002,8,28,6,04,02)
71
- assert(PDate.year(1998,12)<sec_prec)
72
- assert(PDate.month(2002,9)>sec_prec)
73
- assert(PDate.day(2002,8,28)==sec_prec)
74
- assert(PDate.min(1999,12,31,21,57)<sec_prec)
75
- assert(DateTime.new(2002,8,28,6,04,02)==sec_prec)
76
- assert(Date.new(2004,8,28)>sec_prec)
77
- end
78
- def test_succ
79
- #~ fail("FIXME! Implement succ")
80
- end
81
- def test_range
82
- #11:50 pm (:22 seconds ignored), February 2nd, 2004
83
- min1 = PDate.min(2004,2,29,23,50,22)
84
- #12:02 am , March 1st, 2004
85
- min2 = PDate.min(2004,3,1,0,2)
86
- #Inclusive Range w/minute precision
87
- r_min = min1..min2
88
- assert( r_min.include?(PDate.min(2004,2,29,23,50,22)) )
89
- assert( r_min.include?(PDate.min(2004,3,1,0,2)) )
90
- assert( r_min.include?(PDate.min(2004,3,1,0,0)) )
91
- assert( ! r_min.include?(PDate.min(2004,3,1,0,3)) )
92
- #Exclusive Range w/minute precision
93
- r_min = min1...min2
94
- assert( r_min.include?(PDate.min(2004,2,29,23,50,22)) )
95
- assert( !r_min.include?(PDate.min(2004,3,1,0,2)) )
96
- end
97
-
98
- def test_create_with_class_methods
99
- #December 12th, 1968
100
- no_prec = PDate.civil(1968,12,12)
101
- #December 12th, 1968 (at 11:15 am - ignored)
102
- day_prec = PDate.day(1968,12,12,11,15)
103
- assert(no_prec==day_prec, "PDate instance does not equal precisioned instance.")
104
- #December 2004 (24th - ignored)
105
- month_prec1 = PDate.month(2004,12,24)
106
- #December 31st, 2004 (31st - ignored)
107
- month_prec2 = PDate.month(2004,12,31)
108
- assert(month_prec1==month_prec2, "PDate.month instances not equal.")
109
- #December 2004
110
- month_prec3 = PDate.month(2004,12)
111
- assert(month_prec1==month_prec3, "PDate.month instances not equal.")
112
- assert(month_prec2==month_prec3, "PDate.month instances not equal.")
113
- #December 2003
114
- month_prec4 = PDate.month(2003,12)
115
- assert(month_prec4!=month_prec1, "PDate.month instances not equal.")
116
- end
117
- end
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'date'
5
+ require 'runt'
6
+
7
+ # Unit tests for PDate class
8
+ # Author:: Matthew Lipper
9
+ class PDateTest < Test::Unit::TestCase
10
+
11
+ include Runt
12
+
13
+ def setup
14
+ # 2010 (August - ignored)
15
+ @year_prec = PDate.year(2010,8)
16
+ #August, 2004
17
+ @month_prec = PDate.month(2004,8)
18
+ #January 25th, 2004 (11:39 am - ignored)
19
+ @week_prec = PDate.week(2004,1,25,11,39)
20
+ #January 25th, 2004 (11:39 am - ignored)
21
+ @day_prec = PDate.day(2004,1,25,11,39)
22
+ #11:59(:04 - ignored), December 31st, 1999
23
+ @minute_prec = PDate.min(1999,12,31,23,59,4)
24
+ #12:00:10 am, March 1st, 2004
25
+ @second_prec = PDate.sec(2004,3,1,0,0,10)
26
+ end
27
+
28
+ def test_marshal
29
+ # Thanks to Jodi Showers for finding/fixing this bug
30
+ pdate=PDate.new(2004,2,29,22,13,2)
31
+ assert_not_nil pdate.date_precision
32
+ data=Marshal.dump pdate
33
+ obj=Marshal.load data
34
+ assert_not_nil obj.date_precision
35
+ end
36
+
37
+ def test_include
38
+ pdate = PDate.new(2006,3,10)
39
+ assert(pdate.include?(Date.new(2006,3,10)))
40
+ date = Date.new(2006,3,10)
41
+ assert(date.include?(PDate.new(2006,3,10)))
42
+ end
43
+
44
+ def test_new
45
+ date = PDate.new(2004,2,29)
46
+ assert(!date.date_precision.nil?)
47
+ date_time = PDate.new(2004,2,29,22,13,2)
48
+ assert(!date_time.date_precision.nil?)
49
+ date2 = PDate.day(2004,2,29)
50
+ assert(date==date2)
51
+ date_time2 = PDate.sec(2004,2,29,22,13,2)
52
+ assert(date_time==date_time2)
53
+ end
54
+
55
+ def test_plus
56
+ assert(PDate.year(2022,12)==(@year_prec+12))
57
+ assert(PDate.month(2005,2)==(@month_prec+6))
58
+ assert(PDate.week(2004,2,1)==(@week_prec+1))
59
+ assert(PDate.day(2004,2,1)==(@day_prec+7))
60
+ assert(PDate.min(2000,1,1,0,0)==(@minute_prec+1))
61
+ assert(PDate.sec(2004,3,1,0,0,21)==(@second_prec+11))
62
+ end
63
+
64
+ def test_minus
65
+ assert(PDate.year(1998,12)==(@year_prec-12))
66
+ assert(PDate.month(2002,6)==(@month_prec-26))
67
+ assert(PDate.week(2004,1,11)==(@week_prec-2))
68
+ #Hmmm...FIXME? @day_prec-26 == 12/31??
69
+ assert(PDate.day(2003,12,30)==(@day_prec-26))
70
+ assert(PDate.min(1999,12,31,21,57)==(@minute_prec-122))
71
+ assert(PDate.sec(2004,2,29,23,59,59)==(@second_prec-11))
72
+ end
73
+ def test_spaceship_comparison_operator
74
+ sec_prec = PDate.sec(2002,8,28,6,04,02)
75
+ assert(PDate.year(1998,12)<sec_prec)
76
+ assert(PDate.month(2002,9)>sec_prec)
77
+ assert(PDate.week(2002,8,28)==sec_prec)
78
+ assert(PDate.day(2002,8,28)==sec_prec)
79
+ assert(PDate.min(1999,12,31,21,57)<sec_prec)
80
+ assert(DateTime.new(2002,8,28,6,04,02)==sec_prec)
81
+ assert(Date.new(2004,8,28)>sec_prec)
82
+ end
83
+ def test_succ
84
+ #~ fail("FIXME! Implement succ")
85
+ end
86
+ def test_range
87
+ #11:50 pm (:22 seconds ignored), February 2nd, 2004
88
+ min1 = PDate.min(2004,2,29,23,50,22)
89
+ #12:02 am , March 1st, 2004
90
+ min2 = PDate.min(2004,3,1,0,2)
91
+ #Inclusive Range w/minute precision
92
+ r_min = min1..min2
93
+ assert( r_min.include?(PDate.min(2004,2,29,23,50,22)) )
94
+ assert( r_min.include?(PDate.min(2004,3,1,0,2)) )
95
+ assert( r_min.include?(PDate.min(2004,3,1,0,0)) )
96
+ assert( ! r_min.include?(PDate.min(2004,3,1,0,3)) )
97
+ #Exclusive Range w/minute precision
98
+ r_min = min1...min2
99
+ assert( r_min.include?(PDate.min(2004,2,29,23,50,22)) )
100
+ assert( !r_min.include?(PDate.min(2004,3,1,0,2)) )
101
+ end
102
+
103
+ def test_create_with_class_methods
104
+ #December 12th, 1968
105
+ no_prec = PDate.civil(1968,12,12)
106
+ #December 12th, 1968 (at 11:15 am - ignored)
107
+ day_prec = PDate.day(1968,12,12,11,15)
108
+ assert(no_prec==day_prec, "PDate instance does not equal precisioned instance.")
109
+ #December 2004 (24th - ignored)
110
+ month_prec1 = PDate.month(2004,12,24)
111
+ #December 31st, 2004 (31st - ignored)
112
+ month_prec2 = PDate.month(2004,12,31)
113
+ assert(month_prec1==month_prec2, "PDate.month instances not equal.")
114
+ #December 2004
115
+ month_prec3 = PDate.month(2004,12)
116
+ assert(month_prec1==month_prec3, "PDate.month instances not equal.")
117
+ assert(month_prec2==month_prec3, "PDate.month instances not equal.")
118
+ #December 2003
119
+ month_prec4 = PDate.month(2003,12)
120
+ assert(month_prec4!=month_prec1, "PDate.month instances not equal.")
121
+
122
+ one_week = [
123
+ PDate.week(2004, 12, 20), # Monday
124
+ PDate.week(2004, 12, 21), # Tuesday
125
+ PDate.week(2004, 12, 22), # Wednesday
126
+ PDate.week(2004, 12, 23), # Thursday
127
+ PDate.week(2004, 12, 24), # Friday
128
+ PDate.week(2004, 12, 25), # Saturday
129
+ PDate.week(2004, 12, 26), # Sunday
130
+ ]
131
+
132
+ one_week.each do |week_prec1|
133
+ one_week.each do |week_prec2|
134
+ assert_equal week_prec1, week_prec2
135
+ end
136
+ end
137
+
138
+ week_before = PDate.week(2004, 12, 19)
139
+ week_after = PDate.week(2004, 12, 27)
140
+
141
+ one_week.each do |week_prec|
142
+ assert week_prec != week_before
143
+ assert week_prec != week_after
144
+ end
145
+ end
146
+
147
+ end
@@ -26,5 +26,15 @@ class REDayTest < BaseExpressionTest
26
26
  def test_range_each_day_te_to_s
27
27
  assert_equal 'from 11:10PM to 01:20AM daily', REDay.new(23,10,1,20).to_s
28
28
  end
29
+
30
+ def test_less_precise_argument_and_precision_policy
31
+ expr = REDay.new(8,00,10,00)
32
+ assert expr.include?(@pdate_20040531), \
33
+ "Expression #{expr.to_s} should include any lower precision argument by default"
34
+
35
+ expr = REDay.new(8,00,10,00, false)
36
+ assert !expr.include?(@pdate_20040531), \
37
+ "Expression #{expr.to_s} created with less_precise_match=false should not include any lower precision argument automatically"
38
+ end
29
39
 
30
40
  end
@@ -1,98 +1,99 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'baseexpressiontest'
4
-
5
- # Unit tests for REYear class
6
- # Author:: Matthew Lipper
7
-
8
- class REYearTest < BaseExpressionTest
9
-
10
- def test_ctor_one_arg
11
- expr = REYear.new(11)
12
- assert expr.start_month == 11, "Start month should equal 11"
13
- assert expr.end_month == 11, "End month should equal 11"
14
- assert expr.start_day == REYear::NO_DAY, "Start day should equal constant NO_DAY"
15
- assert expr.end_day == REYear::NO_DAY, "End day should equal constant NO_DAY"
16
- end
17
-
18
- def test_ctor_two_args
19
- expr = REYear.new(11,12)
20
- assert expr.start_month == 11, "Start month should equal 11"
21
- assert expr.end_month == 12, "End month should equal 12"
22
- assert expr.start_day == REYear::NO_DAY, "Start day should equal constant NO_DAY"
23
- assert expr.end_day == REYear::NO_DAY, "End day should equal constant NO_DAY"
24
- end
25
-
26
- def test_ctor_three_args
27
- expr = REYear.new(10,21,12)
28
- assert expr.start_month == 10, "Start month should equal 10"
29
- assert expr.end_month == 12, "End month should equal 12"
30
- assert expr.start_day == 21, "Start day should equal 21"
31
- assert expr.end_day == REYear::NO_DAY, "End day should equal constant NO_DAY"
32
- end
33
-
34
- def test_ctor_three_args
35
- expr = REYear.new(10,21,12,3)
36
- assert expr.start_month == 10, "Start month should equal 10"
37
- assert expr.end_month == 12, "End month should equal 12"
38
- assert expr.start_day == 21, "Start day should equal 21"
39
- assert expr.end_day == 3, "End day should equal 3"
40
- end
41
-
42
- def test_specific_days_same_month
43
- expr = REYear.new(10,20,10,29)
44
- assert expr.include?(@pdate_20071028), "#{expr.to_s} should include #{@pdate_20071028}"
45
- assert !expr.include?(@pdate_20071114), "#{expr.to_s} should not include #{@pdate_20071114}"
46
- assert !expr.include?(@pdate_20071030), "#{expr.to_s} should not include #{@pdate_20071030}"
47
- assert !expr.include?(@pdate_20071008), "#{expr.to_s} should not include #{@pdate_20071008}"
48
- end
49
-
50
- def test_specific_days_different_months
51
- expr = REYear.new(5,31,9,6)
52
- assert expr.include?(@pdate_198606), "#{expr.to_s} should include #{@pdate_198606}"
53
- assert expr.include?(@date_20040806), "#{expr.to_s} should include #{@date_20040806}"
54
- assert !expr.include?(@pdate_20071008), "#{expr.to_s} should not include #{@pdate_20071008}"
55
- end
56
-
57
- def test_default_days_different_months
58
- expr = REYear.new(11,12)
59
- assert expr.include?(@date_19611101), "#{expr.to_s} should include #{@date_19611101}"
60
- assert !expr.include?(@pdate_198606), "#{expr.to_s} should not include #{@pdate_198606}"
61
- end
62
-
63
- def test_all_defaults
64
- expr = REYear.new(8)
65
- assert expr.include?(@date_20040806), "#{expr.to_s} should include #{@date_20040806}"
66
- assert !expr.include?(@pdate_198606), "#{expr.to_s} should not include #{@pdate_198606}"
67
- assert !expr.include?(@date_19611101), "#{expr.to_s} should not include #{@date_19611101}"
68
- end
69
-
70
- def test_same_days_same_month
71
- # Bug #5741
72
- expr = REYear.new(9,21,9,21)
73
- assert expr.include?(@pdate_20060921), "#{expr.to_s} should include #{@pdate_20060921.to_s}"
74
- assert !expr.include?(@pdate_20060914), "#{expr.to_s} should not include #{@pdate_20060914.to_s}"
75
- end
76
-
77
- def test_to_s
78
- assert_equal 'June 1st through July 2nd', REYear.new(6, 1, 7, 2).to_s
79
- end
80
-
81
- def test_dates_mixin
82
- expr = REYear.new(4, 28, 5, 6)
83
- assert (expr.dates(@date_20040501..@date_20060504)).size == 22, "Should be 22 occurences in dates Array"
84
- end
85
-
86
- # From bug #5749
87
- def test_mixed_precision_combo
88
- # 10:00 am to 10:01 am
89
- ten_ish = REDay.new(10,0,10,1)
90
- # September 21st every year
91
- every_21_sept = REYear.new(9,21,9,21)
92
- # Between 10:00 am and 10:01 am every September 21st
93
- combo = ten_ish & every_21_sept
94
- assert !combo.include?(@pdate_20060921), "Should not include lower precision argument"
95
- assert combo.include?(@pdate_200609211001), "Should include matching precision argument which is in range"
96
- assert !combo.include?(@pdate_200609211002), "Should not include matching precision argument which is out of range"
97
- end
98
- end
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'baseexpressiontest'
4
+
5
+ # Unit tests for REYear class
6
+ # Author:: Matthew Lipper
7
+
8
+ class REYearTest < BaseExpressionTest
9
+
10
+ def test_ctor_one_arg
11
+ expr = REYear.new(11)
12
+ assert expr.start_month == 11, "Start month should equal 11"
13
+ assert expr.end_month == 11, "End month should equal 11"
14
+ assert expr.start_day == REYear::NO_DAY, "Start day should equal constant NO_DAY"
15
+ assert expr.end_day == REYear::NO_DAY, "End day should equal constant NO_DAY"
16
+ end
17
+
18
+ def test_ctor_two_args
19
+ expr = REYear.new(11,12)
20
+ assert expr.start_month == 11, "Start month should equal 11"
21
+ assert expr.end_month == 12, "End month should equal 12"
22
+ assert expr.start_day == REYear::NO_DAY, "Start day should equal constant NO_DAY"
23
+ assert expr.end_day == REYear::NO_DAY, "End day should equal constant NO_DAY"
24
+ end
25
+
26
+ def test_ctor_three_args
27
+ expr = REYear.new(10,21,12)
28
+ assert expr.start_month == 10, "Start month should equal 10"
29
+ assert expr.end_month == 12, "End month should equal 12"
30
+ assert expr.start_day == 21, "Start day should equal 21"
31
+ assert expr.end_day == REYear::NO_DAY, "End day should equal constant NO_DAY"
32
+ end
33
+
34
+ def test_ctor_three_args
35
+ expr = REYear.new(10,21,12,3)
36
+ assert expr.start_month == 10, "Start month should equal 10"
37
+ assert expr.end_month == 12, "End month should equal 12"
38
+ assert expr.start_day == 21, "Start day should equal 21"
39
+ assert expr.end_day == 3, "End day should equal 3"
40
+ end
41
+
42
+ def test_specific_days_same_month
43
+ expr = REYear.new(10,20,10,29)
44
+ assert expr.include?(@pdate_20071028), "#{expr.to_s} should include #{@pdate_20071028}"
45
+ assert !expr.include?(@pdate_20071114), "#{expr.to_s} should not include #{@pdate_20071114}"
46
+ assert !expr.include?(@pdate_20071030), "#{expr.to_s} should not include #{@pdate_20071030}"
47
+ assert !expr.include?(@pdate_20071008), "#{expr.to_s} should not include #{@pdate_20071008}"
48
+ assert !expr.include?(@pdate_20060921), "#{expr.to_s} should not include #{@pdate_20060921}"
49
+ end
50
+
51
+ def test_specific_days_different_months
52
+ expr = REYear.new(5,31,9,6)
53
+ assert expr.include?(@pdate_198606), "#{expr.to_s} should include #{@pdate_198606}"
54
+ assert expr.include?(@date_20040806), "#{expr.to_s} should include #{@date_20040806}"
55
+ assert !expr.include?(@pdate_20071008), "#{expr.to_s} should not include #{@pdate_20071008}"
56
+ end
57
+
58
+ def test_default_days_different_months
59
+ expr = REYear.new(11,12)
60
+ assert expr.include?(@date_19611101), "#{expr.to_s} should include #{@date_19611101}"
61
+ assert !expr.include?(@pdate_198606), "#{expr.to_s} should not include #{@pdate_198606}"
62
+ end
63
+
64
+ def test_all_defaults
65
+ expr = REYear.new(8)
66
+ assert expr.include?(@date_20040806), "#{expr.to_s} should include #{@date_20040806}"
67
+ assert !expr.include?(@pdate_198606), "#{expr.to_s} should not include #{@pdate_198606}"
68
+ assert !expr.include?(@date_19611101), "#{expr.to_s} should not include #{@date_19611101}"
69
+ end
70
+
71
+ def test_same_days_same_month
72
+ # Bug #5741
73
+ expr = REYear.new(9,21,9,21)
74
+ assert expr.include?(@pdate_20060921), "#{expr.to_s} should include #{@pdate_20060921.to_s}"
75
+ assert !expr.include?(@pdate_20060914), "#{expr.to_s} should not include #{@pdate_20060914.to_s}"
76
+ end
77
+
78
+ def test_to_s
79
+ assert_equal 'June 1st through July 2nd', REYear.new(6, 1, 7, 2).to_s
80
+ end
81
+
82
+ def test_dates_mixin
83
+ expr = REYear.new(4, 28, 5, 6)
84
+ assert((expr.dates(@date_20040501..@date_20060504)).size == 22, "Should be 22 occurences in dates Array")
85
+ end
86
+
87
+ # From bug #5749
88
+ def test_mixed_precision_combo
89
+ # 10:00 am to 10:01 am
90
+ ten_ish = REDay.new(10,0,10,1)
91
+ # September 21st every year
92
+ every_21_sept = REYear.new(9,21,9,21)
93
+ # Between 10:00 am and 10:01 am every September 21st
94
+ combo = ten_ish & every_21_sept
95
+ assert combo.include?(@pdate_20060921), "Should include lower precision argument"
96
+ assert combo.include?(@pdate_200609211001), "Should include matching precision argument which is in range"
97
+ assert !combo.include?(@pdate_200609211002), "Should not include matching precision argument which is out of range"
98
+ end
99
+ end