Scheduler Test Code
From DojoWiki
Revision as of 22:08, 25 April 2007; view current revision
←Older revision | Newer revision→
←Older revision | Newer revision→
#
# schedule_test.rb
#
# Tests the function of the scheduler
#
require 'test/unit'
require 'schedule'
class ScheduleTest < Test::Unit::TestCase
def test_daily_gives_next_day
schedule = Schedule.new
assert_equal Time.local(2007, 3, 1),
schedule.next_after(Time.local(2007, 2, 28))
end
def test_daily_sets_time_to_midnight
schedule = Schedule.new
assert_equal Time.local(2007, 3, 1),
schedule.next_after(Time.local(2007, 2, 28, 6, 30, 1, 400))
end
def test_daily_at_3_thirty_when_later
schedule = Schedule.new(:start_time =>
{:hour => 3, :min => 30})
assert_equal Time.local(2007, 3, 6, 3, 30),
schedule.next_after(Time.local(2007, 3, 5, 10))
end
def test_daily_at_10_thirty_when_earlier
schedule = Schedule.new(:start_time =>
{:hour => 10, :min => 30})
assert_equal Time.local(2007, 3, 10, 10, 30),
schedule.next_after(Time.local(2007, 3, 10, 9))
end
def test_daily_at_2_thirty_when_later_min
schedule = Schedule.new(:start_time =>
{:hour => 2, :min => 30})
assert_equal Time.local(2007, 3, 15, 2, 30),
schedule.next_after(Time.local(2007, 3, 14, 2, 31))
end
def test_daily_at_2_thirty_when_later_sec
schedule = Schedule.new(:start_time =>
{:hour => 2, :min => 30, :sec => 15})
assert_equal Time.local(2007, 3, 15, 2, 30, 15),
schedule.next_after(Time.local(2007, 3, 14, 2, 30, 16))
end
end
#
# create_schedule_test.rb
#
# Tests the creation of schedulers
#
require 'test/unit'
require 'schedule'
require 'rubygems'
require 'active_support'
class CreateScheduleTest < Test::Unit::TestCase
def test_every_day
schedule = Schedule.every.day
assert_equal 1.day, schedule.frequency
assert_equal 0, schedule.start_time
end
end
#
# schedule_equality_test.rb
#
# Tests the equality properties of the scheduler
#
class ScheduleEqualityTest < Test::Unit::TestCase
def setup
@eq = Schedule.new
end
def test_eq_is_reflexsive
assert @eq == @eq
end
def test_same_initialization_are_eq
eq2 = Schedule.new
assert @eq == eq2
assert eq2 == @eq
end
def test_eq_differs_from_nil
assert !(@eq == nil)
end
def test_different_start_times_differ
neq = Schedule.new(:start_time =>
{:hour => 10})
assert !(@eq == neq)
assert !(neq == @eq)
end
end
Return to discussion
