From 8621a1b4914f70975f83ad59d31da25d5c01aa1a Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Wed, 10 Aug 2011 13:54:53 +0100 Subject: Updated during_runner to work better. --HG-- rename : test/time_test.rb => test/tc_mauve_time.rb --- test/tc_mauve_notification.rb | 111 ++++++++++++++++++++++++++++++++++++++++++ test/tc_mauve_time.rb | 43 ++++++++++++++++ test/test_mauve.rb | 2 + test/time_test.rb | 43 ---------------- 4 files changed, 156 insertions(+), 43 deletions(-) create mode 100644 test/tc_mauve_notification.rb create mode 100644 test/tc_mauve_time.rb delete mode 100644 test/time_test.rb (limited to 'test') diff --git a/test/tc_mauve_notification.rb b/test/tc_mauve_notification.rb new file mode 100644 index 0000000..3414292 --- /dev/null +++ b/test/tc_mauve_notification.rb @@ -0,0 +1,111 @@ +$:.unshift "../lib" + +require 'test/unit' +require 'mauve/alert' +require 'mauve/notification' +require 'mauve/configuration' +require 'mauve/configuration_builder' +require 'mauve/mauve_time' +require 'th_mauve_resolv' +require 'pp' + + + +class TcMauveDuringRunner < Test::Unit::TestCase + + def test_initialize + + alert = Mauve::Alert.new + time = Time.now + during = Proc.new { false } + + dr = Mauve::DuringRunner.new(time, alert, &during) + + assert_equal(dr.alert, alert) + assert_equal(dr.time, time) + assert_equal(dr.during, during) + + end + + def test_now? + alert = Mauve::Alert.new + time = Time.now + during = Proc.new { @test_time } + + dr = Mauve::DuringRunner.new(time, alert, &during) + assert_equal(time, dr.now?) + assert_equal(time+3600, dr.now?(time+3600)) + assert_equal(time, dr.time) + end + + def test_find_next + # + # An alert is supposed to remind someone every six hours during working + # hours, and it is raised outside working hours. Assuming it is still + # raised when working hours start, when should the first reminder get sent? + # + # (a) As soon as working hours commence. + # (b) At some point in the first six hours of working hours. + # (c) After six working hours. + # + # (12:38:19) Nick: a) + + # + # This should give us midnight last sunday night. + # + now = Mauve::MauveTime.now + midnight_sunday = now - (now.hour.hours + now.min.minutes + now.sec.seconds + now.wday.days) + + # + # first working hour on Monday + monday_morning = midnight_sunday.in_x_hours(0,"working") + + # + # This should alert at exactly first thing on Monday morning. + # + dr = Mauve::DuringRunner.new(midnight_sunday, nil){ working_hours? } + assert_equal(dr.find_next(6.hours), monday_morning) + + # + # This should alert six hours later than the last one. + # + dr = Mauve::DuringRunner.new(monday_morning, nil){ working_hours? } + assert_equal(dr.find_next(6.hours), monday_morning + 6.hours) + + # + # Now assuming the working day is not 12 hours long, if we progress to 6 + # hours in the future then the next alert should be first thing on Tuesday. + # + dr = Mauve::DuringRunner.new(monday_morning + 6.hours, nil){ working_hours? } + tuesday_morning = monday_morning+24.hours + assert_equal(dr.find_next(6.hours), tuesday_morning) + + # + # If an alert is too far in the future (a week) return nil. + # + dr = Mauve::DuringRunner.new(monday_morning, nil){ @test_time > (@time + 12.days) } + assert_nil(dr.find_next) + end + + def test_hours_in_day + end + + def test_days_in_week + end + + def test_unacknowledged + end + +end + +class TcMauveNotification < Test::Unit::TestCase + + def test_notify + end + + def remind_at_next + end + +end + + diff --git a/test/tc_mauve_time.rb b/test/tc_mauve_time.rb new file mode 100644 index 0000000..0749fef --- /dev/null +++ b/test/tc_mauve_time.rb @@ -0,0 +1,43 @@ +$: << "../lib/" + +require 'test/unit' +require 'mauve/mauve_time' +require 'pp' + +class TestMauveTime < Test::Unit::TestCase + + def test_in_x_hours + + # + # 5pm on a Friday + # + t = Time.local(2011,6,3,17,14,32) + + # + # Working hours.. + # + hour_0 = Time.local(2011,6,6,8,30,0) + hour_1 = Time.local(2011,6,6,9,30,0) + + assert_equal(hour_1, t.in_x_hours(1,"working")) + assert_equal(hour_0, t.in_x_hours(0,"working")) + + # + # 4.45pm on a Friday + # + t = Time.local(2011,6,3,16,45,32) + + # + # Working hours.. + # + hour_0 = Time.local(2011,6,3,16,45,32) + hour_1 = Time.local(2011,6,6,9,15,32) + + assert_equal(hour_1, t.in_x_hours(1,"working")) + assert_equal(hour_0, t.in_x_hours(0,"working")) + + + end + + +end diff --git a/test/test_mauve.rb b/test/test_mauve.rb index e3df469..a8dba9b 100644 --- a/test/test_mauve.rb +++ b/test/test_mauve.rb @@ -17,6 +17,8 @@ tc_mauve_source_list.rb tc_mauve_people_list.rb tc_mauve_alert.rb tc_mauve_alert_group.rb +tc_mauve_notification.rb +tc_mauve_time.rb ).each do |s| require s end diff --git a/test/time_test.rb b/test/time_test.rb deleted file mode 100644 index 0749fef..0000000 --- a/test/time_test.rb +++ /dev/null @@ -1,43 +0,0 @@ -$: << "../lib/" - -require 'test/unit' -require 'mauve/mauve_time' -require 'pp' - -class TestMauveTime < Test::Unit::TestCase - - def test_in_x_hours - - # - # 5pm on a Friday - # - t = Time.local(2011,6,3,17,14,32) - - # - # Working hours.. - # - hour_0 = Time.local(2011,6,6,8,30,0) - hour_1 = Time.local(2011,6,6,9,30,0) - - assert_equal(hour_1, t.in_x_hours(1,"working")) - assert_equal(hour_0, t.in_x_hours(0,"working")) - - # - # 4.45pm on a Friday - # - t = Time.local(2011,6,3,16,45,32) - - # - # Working hours.. - # - hour_0 = Time.local(2011,6,3,16,45,32) - hour_1 = Time.local(2011,6,6,9,15,32) - - assert_equal(hour_1, t.in_x_hours(1,"working")) - assert_equal(hour_0, t.in_x_hours(0,"working")) - - - end - - -end -- cgit v1.2.1