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,101 +1,98 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'runt'
5
- require 'date'
6
- require 'pp'
7
-
8
- class RuntModuleTest < Test::Unit::TestCase
9
-
10
- def test_last
11
- assert Runt::Last == -1
12
- end
13
-
14
- def test_last_of
15
- assert Runt::Last_of == -1
16
- end
17
-
18
- def test_second_to_last
19
- assert Runt::Second_to_last == -2
20
- end
21
-
22
- def test_ordinals
23
- #1.upto(31){ |n| puts Runt.ordinalize(n); }
24
- assert_equal '1st', Runt.ordinalize(1)
25
- assert_equal '33rd', Runt.ordinalize(33)
26
- assert_equal '50th', Runt.ordinalize(50)
27
- assert_equal '2nd', Runt.ordinalize(2)
28
- assert_equal 'second to last', Runt.ordinalize(-2)
29
- assert_equal 'last', Runt.ordinalize(-1)
30
- end
31
-
32
- def test_day_name
33
- i=0
34
- Date::DAYNAMES.each do |n|
35
- assert_equal Date::DAYNAMES[i], Runt.day_name(i)
36
- i=i+1
37
- end
38
- end
39
-
40
- def test_month_name
41
- i=0
42
- Date::MONTHNAMES.each do |n|
43
- assert_equal Date::MONTHNAMES[i], Runt.month_name(i)
44
- i=i+1
45
- end
46
- end
47
-
48
- def test_strftime
49
- d=DateTime.new(2006,2,26,14,45)
50
- assert_equal '02:45PM', Runt.format_time(d)
51
- end
52
-
53
- def test_numeric_class_additions
54
- assert_equal 0.000001, 1.microsecond
55
- assert_equal 0.000001, 1.microseconds
56
- assert_equal 0.001, 1.millisecond
57
- assert_equal 0.001, 1.milliseconds
58
- assert_equal 7, 7.second
59
- assert_equal 7, 7.seconds
60
- assert_equal 60, 1.minute
61
- assert_equal 60, 1.minutes
62
- assert_equal 3600, 1.hour
63
- assert_equal 3600, 1.hours
64
- assert_equal 86400, 1.day
65
- assert_equal 86400, 1.days
66
- assert_equal 604800, 1.week
67
- assert_equal 604800, 1.weeks
68
- assert_equal 2592000, 1.month
69
- assert_equal 2592000, 1.months
70
- assert_equal 31536000, 1.year
71
- assert_equal 31536000, 1.years
72
- assert_equal 315360000, 1.decade
73
- assert_equal 315360000, 1.decades
74
- end
75
-
76
- def test_time_class_dprecision
77
- time=Time.parse('Monday 06 November 2006 07:38')
78
- assert_equal(Runt::DPrecision::DEFAULT,time.date_precision)
79
- end
80
-
81
- def test_date_class_dprecision
82
- date=Date.today
83
- assert_equal(Runt::DPrecision::DEFAULT,date.date_precision)
84
- end
85
-
86
- def test_datetime_class_dprecision
87
- date=DateTime.civil
88
- assert_equal(Runt::DPrecision::DEFAULT,date.date_precision)
89
- end
90
-
91
- def test_time_plus
92
- time=Time.parse("Sat Dec 09 05:56:12 -0500 2006")
93
- # Default precision is minute
94
- assert_equal(Runt::PDate.min(2006,12,9,5,56),Runt::DPrecision.to_p(time))
95
- assert_not_equal(Time.parse("Sat Dec 09 05:56:00 -0500 2006"),time)
96
-
97
-
98
-
99
- end
100
-
101
- end
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'runt'
5
+ require 'date'
6
+ require 'pp'
7
+
8
+ class RuntModuleTest < Test::Unit::TestCase
9
+
10
+ def test_last
11
+ assert Runt::Last == -1
12
+ end
13
+
14
+ def test_last_of
15
+ assert Runt::Last_of == -1
16
+ end
17
+
18
+ def test_second_to_last
19
+ assert Runt::Second_to_last == -2
20
+ end
21
+
22
+ def test_ordinals
23
+ #1.upto(31){ |n| puts Runt.ordinalize(n); }
24
+ assert_equal '1st', Runt.ordinalize(1)
25
+ assert_equal '33rd', Runt.ordinalize(33)
26
+ assert_equal '50th', Runt.ordinalize(50)
27
+ assert_equal '2nd', Runt.ordinalize(2)
28
+ assert_equal 'second to last', Runt.ordinalize(-2)
29
+ assert_equal 'last', Runt.ordinalize(-1)
30
+ end
31
+
32
+ def test_day_name
33
+ i=0
34
+ Date::DAYNAMES.each do |n|
35
+ assert_equal Date::DAYNAMES[i], Runt.day_name(i)
36
+ i=i+1
37
+ end
38
+ end
39
+
40
+ def test_month_name
41
+ i=0
42
+ Date::MONTHNAMES.each do |n|
43
+ assert_equal Date::MONTHNAMES[i], Runt.month_name(i)
44
+ i=i+1
45
+ end
46
+ end
47
+
48
+ def test_strftime
49
+ d=DateTime.new(2006,2,26,14,45)
50
+ assert_equal '02:45PM', Runt.format_time(d)
51
+ end
52
+
53
+ def test_numeric_class_additions
54
+ assert_equal 0.000001, 1.microsecond
55
+ assert_equal 0.000001, 1.microseconds
56
+ assert_equal 0.001, 1.millisecond
57
+ assert_equal 0.001, 1.milliseconds
58
+ assert_equal 7, 7.second
59
+ assert_equal 7, 7.seconds
60
+ assert_equal 60, 1.minute
61
+ assert_equal 60, 1.minutes
62
+ assert_equal 3600, 1.hour
63
+ assert_equal 3600, 1.hours
64
+ assert_equal 86400, 1.day
65
+ assert_equal 86400, 1.days
66
+ assert_equal 604800, 1.week
67
+ assert_equal 604800, 1.weeks
68
+ assert_equal 2592000, 1.month
69
+ assert_equal 2592000, 1.months
70
+ assert_equal 31536000, 1.year
71
+ assert_equal 31536000, 1.years
72
+ assert_equal 315360000, 1.decade
73
+ assert_equal 315360000, 1.decades
74
+ end
75
+
76
+ def test_time_class_dprecision
77
+ time=Time.parse('Monday 06 November 2006 07:38')
78
+ assert_equal(Runt::DPrecision::DEFAULT,time.date_precision)
79
+ end
80
+
81
+ def test_date_class_dprecision
82
+ date=Date.today
83
+ assert_equal(Runt::DPrecision::DEFAULT,date.date_precision)
84
+ end
85
+
86
+ def test_datetime_class_dprecision
87
+ date=DateTime.civil
88
+ assert_equal(Runt::DPrecision::DEFAULT,date.date_precision)
89
+ end
90
+
91
+ def test_time_plus
92
+ time=Time.local(2006, 12, 9, 5, 56, 12)
93
+ # Default precision is minute
94
+ assert_equal(Runt::PDate.min(2006,12,9,5,56),Runt::DPrecision.to_p(time))
95
+ assert_not_equal(Time.parse("Sat Dec 09 05:56:00 -0500 2006"),time)
96
+ end
97
+
98
+ end
@@ -1,148 +1,148 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'runt'
5
- require 'date'
6
-
7
- # Unit tests for Schedule classes
8
- # Author:: Matthew Lipper
9
- class ScheduleTest < Test::Unit::TestCase
10
-
11
- include Runt
12
-
13
- def setup
14
- # Jane is very busy these days.
15
- @sched=Schedule.new
16
- # Elmo's World is on TV: Mon-Fri 8am-8:30am
17
- @elmo=Event.new("Elmo's World")
18
- @elmo_broadcast=(REWeek.new(Mon,Fri) & REDay.new(8,00,8,30))
19
- @sched.add(@elmo,@elmo_broadcast)
20
- #Oobi's on TV: Thu-Sat 8:30am-9am
21
- @oobi=Event.new("Oobi")
22
- @oobi_broadcast=(REWeek.new(Thu,Sat) & REDay.new(8,30,9,00))
23
- @sched.add(@oobi,@oobi_broadcast)
24
- @during_elmo=PDate.new(2004,5,4,8,06)
25
- @not_during_elmo=PDate.new(2004,5,1,8,06)
26
- @during_oobi=PDate.new(2004,4,30,8,56)
27
- @not_during_oobi=PDate.new(2004,5,1,8,12)
28
- end
29
-
30
- def test_include
31
- # Check Elmo
32
- assert(@sched.include?(@elmo, @during_elmo))
33
- assert(!@sched.include?(@elmo,@not_during_elmo))
34
- assert(!@sched.include?(@elmo,@during_oobi))
35
- # Check Oobi
36
- assert(@sched.include?(@oobi, @during_oobi))
37
- assert(!@sched.include?(@oobi,@not_during_oobi))
38
- assert(!@sched.include?(@oobi,@not_during_elmo))
39
- end
40
-
41
- def test_select_all
42
- # select all
43
- all=@sched.select {|ev,xpr| true; }
44
- assert all.size==2
45
- assert all.include?(@elmo)
46
- assert all.include?(@oobi)
47
- end
48
-
49
- def test_select_none
50
- # select none
51
- assert((@sched.select {|ev,xpr| false; }).size==0)
52
- end
53
-
54
- def test_select_some
55
- # select oobi only
56
- some=@sched.select {|ev,xpr| @oobi.eql?(ev); }
57
- assert some.size==1
58
- assert !some.include?(@elmo)
59
- assert some.include?(@oobi)
60
- some.clear
61
- # select elmo only
62
- some=@sched.select {|ev,xpr| @elmo.eql?(ev); }
63
- assert some.size==1
64
- assert some.include?(@elmo)
65
- assert !some.include?(@oobi)
66
- end
67
-
68
- def test_events
69
- events=@sched.events(PDate.new(2006,12,4,11,15))
70
- assert_equal 0,events.size
71
- # The Barney power hour which overlaps with Elmo
72
- barney=Event.new("Barney")
73
- @sched.add(barney,REDay.new(7,30,8,30))
74
- events=@sched.events(PDate.new(2006,12,4,8,15))
75
- assert_equal 2,events.size
76
- assert events.include?(barney)
77
- assert events.include?(@elmo)
78
- end
79
-
80
- def test_update
81
- @sched.update(Event.new("aaa")){|ev|assert_nil(ev)}
82
- @sched.update(@elmo){|ev|assert_equal(@elmo_broadcast,ev)}
83
- @sched.update(@oobi){|ev|assert_equal(@oobi_broadcast,ev)}
84
- end
85
-
86
- def test_select_old
87
- @sched=Schedule.new
88
- e1=Event.new("e1")
89
- assert(!@sched.include?(e1,nil))
90
- range=RSpec.new(DateRange.new(PDate.new(2006,12,3),PDate.new(2007,1,24)))
91
- in_range=PDate.new(2007,1,4)
92
- assert(range.include?(in_range))
93
- out_of_range=PDate.new(2006,1,4)
94
- assert(!range.include?(out_of_range))
95
- @sched.add(e1,range)
96
- assert(@sched.include?(e1,in_range))
97
- assert(!@sched.include?(e1,out_of_range))
98
- end
99
-
100
- def test_dates
101
- # range: May 1st, 2004 to May 31st, 2004
102
- d_range = DateRange.new(PDate.day(2004,5,1), PDate.day(2004,5,31))
103
- @sched = Schedule.new
104
- event = Event.new("Visit Ernie")
105
- # First and last Friday of the month
106
- expr1 = DIMonth.new(1,Fri) | DIMonth.new(-1,Fri)
107
- @sched.add(event,expr1)
108
- dates = @sched.dates(event,d_range)
109
- expected = [PDate.day(2004,5,7), PDate.day(2004,5,28)]
110
- assert_equal(expected,dates)
111
- end
112
-
113
- def test_using_a_schedule
114
-
115
- # September 18th - 19th, 2005, 8am - 10am
116
- expr1=RSpec.new(DateRange.new(PDate.day(2005,9,18),PDate.day(2005,9,19))) & REDay.new(8,0,10,0)
117
- assert(expr1.include?(PDate.min(2005,9,18,8,15)))
118
- # September 19th - 20th, 2005, 9am - 11am
119
- expr2=RSpec.new(DateRange.new(PDate.day(2005,9,19),PDate.day(2005,9,20))) & REDay.new(9,0,11,0)
120
- # Quick sanuty check
121
- assert(expr1.overlap?(expr2))
122
- # Setup a @schedule w/first expression
123
- @sched = Schedule.new
124
- @sched.add(Event.new("Snafubar Opening"),expr1)
125
- resource = Resource.new(@sched)
126
- # Add a another overlapping event
127
- resource.add_event(Event.new("Yodeling Lesson"),expr2)
128
- # Create a new resource using the same schedule
129
- resource2 = Resource.new(@sched)
130
- # Add a another overlapping event and pass a block which should complain
131
- #resource.add_event(Event.new("Yodeling Lesson"),expr2) \
132
- #{|e,s| raise "Resource not available at requested time(s)." \
133
- # if (@schedule.overlap?(s))}
134
- end
135
- end
136
-
137
- class Resource
138
- def initialize(schedule)
139
- @schedule=schedule
140
- end
141
- def add_event(event,expr)
142
- if(block_given?)
143
- yield(event,expr)
144
- else
145
- @schedule.add(event,expr)
146
- end
147
- end
148
- end
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'runt'
5
+ require 'date'
6
+
7
+ # Unit tests for Schedule classes
8
+ # Author:: Matthew Lipper
9
+ class ScheduleTest < Test::Unit::TestCase
10
+
11
+ include Runt
12
+
13
+ def setup
14
+ # Jane is very busy these days.
15
+ @sched=Schedule.new
16
+ # Elmo's World is on TV: Mon-Fri 8am-8:30am
17
+ @elmo=Event.new("Elmo's World")
18
+ @elmo_broadcast=(REWeek.new(Mon,Fri) & REDay.new(8,00,8,30))
19
+ @sched.add(@elmo,@elmo_broadcast)
20
+ #Oobi's on TV: Thu-Sat 8:30am-9am
21
+ @oobi=Event.new("Oobi")
22
+ @oobi_broadcast=(REWeek.new(Thu,Sat) & REDay.new(8,30,9,00))
23
+ @sched.add(@oobi,@oobi_broadcast)
24
+ @during_elmo=PDate.new(2004,5,4,8,06)
25
+ @not_during_elmo=PDate.new(2004,5,1,8,06)
26
+ @during_oobi=PDate.new(2004,4,30,8,56)
27
+ @not_during_oobi=PDate.new(2004,5,1,8,12)
28
+ end
29
+
30
+ def test_include
31
+ # Check Elmo
32
+ assert(@sched.include?(@elmo, @during_elmo))
33
+ assert(!@sched.include?(@elmo,@not_during_elmo))
34
+ assert(!@sched.include?(@elmo,@during_oobi))
35
+ # Check Oobi
36
+ assert(@sched.include?(@oobi, @during_oobi))
37
+ assert(!@sched.include?(@oobi,@not_during_oobi))
38
+ assert(!@sched.include?(@oobi,@not_during_elmo))
39
+ end
40
+
41
+ def test_select_all
42
+ # select all
43
+ all=@sched.select {|ev,xpr| true; }
44
+ assert all.size==2
45
+ assert all.include?(@elmo)
46
+ assert all.include?(@oobi)
47
+ end
48
+
49
+ def test_select_none
50
+ # select none
51
+ assert((@sched.select {|ev,xpr| false; }).size==0)
52
+ end
53
+
54
+ def test_select_some
55
+ # select oobi only
56
+ some=@sched.select {|ev,xpr| @oobi.eql?(ev); }
57
+ assert some.size==1
58
+ assert !some.include?(@elmo)
59
+ assert some.include?(@oobi)
60
+ some.clear
61
+ # select elmo only
62
+ some=@sched.select {|ev,xpr| @elmo.eql?(ev); }
63
+ assert some.size==1
64
+ assert some.include?(@elmo)
65
+ assert !some.include?(@oobi)
66
+ end
67
+
68
+ def test_events
69
+ events=@sched.events(PDate.new(2006,12,4,11,15))
70
+ assert_equal 0,events.size
71
+ # The Barney power hour which overlaps with Elmo
72
+ barney=Event.new("Barney")
73
+ @sched.add(barney,REDay.new(7,30,8,30))
74
+ events=@sched.events(PDate.new(2006,12,4,8,15))
75
+ assert_equal 2,events.size
76
+ assert events.include?(barney)
77
+ assert events.include?(@elmo)
78
+ end
79
+
80
+ def test_update
81
+ @sched.update(Event.new("aaa")){|ev|assert_nil(ev)}
82
+ @sched.update(@elmo){|ev|assert_equal(@elmo_broadcast,ev)}
83
+ @sched.update(@oobi){|ev|assert_equal(@oobi_broadcast,ev)}
84
+ end
85
+
86
+ def test_select_old
87
+ @sched=Schedule.new
88
+ e1=Event.new("e1")
89
+ assert(!@sched.include?(e1,nil))
90
+ range=RSpec.new(DateRange.new(PDate.new(2006,12,3),PDate.new(2007,1,24)))
91
+ in_range=PDate.new(2007,1,4)
92
+ assert(range.include?(in_range))
93
+ out_of_range=PDate.new(2006,1,4)
94
+ assert(!range.include?(out_of_range))
95
+ @sched.add(e1,range)
96
+ assert(@sched.include?(e1,in_range))
97
+ assert(!@sched.include?(e1,out_of_range))
98
+ end
99
+
100
+ def test_dates
101
+ # range: May 1st, 2004 to May 31st, 2004
102
+ d_range = DateRange.new(PDate.day(2004,5,1), PDate.day(2004,5,31))
103
+ @sched = Schedule.new
104
+ event = Event.new("Visit Ernie")
105
+ # First and last Friday of the month
106
+ expr1 = DIMonth.new(1,Fri) | DIMonth.new(-1,Fri)
107
+ @sched.add(event,expr1)
108
+ dates = @sched.dates(event,d_range)
109
+ expected = [PDate.day(2004,5,7), PDate.day(2004,5,28)]
110
+ assert_equal(expected,dates)
111
+ end
112
+
113
+ def test_using_a_schedule
114
+
115
+ # September 18th - 19th, 2005, 8am - 10am
116
+ expr1=RSpec.new(DateRange.new(PDate.day(2005,9,18),PDate.day(2005,9,19))) & REDay.new(8,0,10,0)
117
+ assert(expr1.include?(PDate.min(2005,9,18,8,15)))
118
+ # September 19th - 20th, 2005, 9am - 11am
119
+ expr2=RSpec.new(DateRange.new(PDate.day(2005,9,19),PDate.day(2005,9,20))) & REDay.new(9,0,11,0)
120
+ # Quick sanuty check
121
+ assert(expr1.overlap?(expr2))
122
+ # Setup a @schedule w/first expression
123
+ @sched = Schedule.new
124
+ @sched.add(Event.new("Snafubar Opening"),expr1)
125
+ resource = Resource.new(@sched)
126
+ # Add a another overlapping event
127
+ resource.add_event(Event.new("Yodeling Lesson"),expr2)
128
+ # Create a new resource using the same schedule
129
+ resource2 = Resource.new(@sched)
130
+ # Add a another overlapping event and pass a block which should complain
131
+ #resource.add_event(Event.new("Yodeling Lesson"),expr2) \
132
+ #{|e,s| raise "Resource not available at requested time(s)." \
133
+ # if (@schedule.overlap?(s))}
134
+ end
135
+ end
136
+
137
+ class Resource
138
+ def initialize(schedule)
139
+ @schedule=schedule
140
+ end
141
+ def add_event(event,expr)
142
+ if(block_given?)
143
+ yield(event,expr)
144
+ else
145
+ @schedule.add(event,expr)
146
+ end
147
+ end
148
+ end