diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-08-18 18:19:40 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-08-18 18:19:40 +0100 |
commit | e75e185bd348fd21fb62ba77f54d4f27755ba747 (patch) | |
tree | a53d73607739d0bf66030f64d1f77b687668645c | |
parent | 6aba0c3d8e2d30797755dc8b968fe338e13b8df4 (diff) |
Fixed up test_time bits in mauve_notification and merged tests.
-rw-r--r-- | lib/mauve/notification.rb | 4 | ||||
-rw-r--r-- | test/tc_mauve_notification.rb | 44 |
2 files changed, 48 insertions, 0 deletions
diff --git a/lib/mauve/notification.rb b/lib/mauve/notification.rb index 8e125be..c57d2a9 100644 --- a/lib/mauve/notification.rb +++ b/lib/mauve/notification.rb @@ -87,10 +87,12 @@ module Mauve protected def hours_in_day(*hours) + @test_time = @time if @test_time.nil? x_in_list_of_y(@test_time.hour, hours.flatten) end def days_in_week(*days) + @test_time = @time if @test_time.nil? x_in_list_of_y(@test_time.wday, days.flatten) end @@ -114,6 +116,7 @@ module Mauve end def working_hours? + @test_time = @time if @test_time.nil? @test_time.working_hours? end @@ -123,6 +126,7 @@ module Mauve # # @return [Boolean] Whether now is a in the dead zone or not. def dead_zone? + @test_time = @time if @test_time.nil? @test_time.dead_zone? end diff --git a/test/tc_mauve_notification.rb b/test/tc_mauve_notification.rb index 6b4c3d1..167d069 100644 --- a/test/tc_mauve_notification.rb +++ b/test/tc_mauve_notification.rb @@ -98,10 +98,54 @@ class TcMauveDuringRunner < Mauve::UnitTest assert_nil(dr.find_next) end + + def test_x_in_list_of_y + mdr = Mauve::DuringRunner.new(Time.now) + [ + [[0,1,3,4], 2, false], + [[0,2,4,6], 2, true], + [[0..1,3..6],2, false], + [[0..2, 4,5],2, true], + [[0,1..3], 2, true], + ].each do |y,x,result| + assert_equal(result, mdr.send(:x_in_list_of_y, x,y)) + end + end + def test_hours_in_day + t = Time.gm(2010,1,2,3,4,5) + # => Sat Jan 02 03:04:05 UTC 2010 + mdr = Mauve::DuringRunner.new(t) + [ + [[0,1,3,4], true], + [[0,2,4,6], false], + [[[0,1,3],4], true], + [[[0,2,4],6], false], + [[0..1,3..6], true], + [[0..2, 4,5], false], + [[0,1..3], true], + [[4..12], false] + ].each do |hours, result| + assert_equal(result, mdr.send(:hours_in_day, hours)) + end end def test_days_in_week + t = Time.gm(2010,1,2,3,4,5) + # => Sat Jan 02 03:04:05 UTC 2010 + mdr = Mauve::DuringRunner.new(t) + [ + [[0,1,3,4], false], + [[0,2,4,6], true], + [[[0,1,3],4], false], + [[[0,2,4],6], true], + [[0..1,3..6], true], + [[0..2, 4,5], false], + [[0,1..3], false], + [[4..6], true] + ].each do |days, result| + assert_equal(result, mdr.send(:days_in_week, days), "#{t.wday} in #{days.join(", ")}") + end end def test_unacknowledged |