test/unit/test_line.rb in metra_schedule-0.2.2 vs test/unit/test_line.rb in metra_schedule-0.3.0
- old
+ new
@@ -1,6 +1,11 @@
require File.join(File.dirname(__FILE__), "../", "test_helper.rb")
+begin
+ require 'mocha'
+rescue
+ puts "Not all the tests may function properly without Mocha installed. gem install mocha"
+end
class TestLine < Test::Unit::TestCase
def test_initialize_with_line_name
assert_nothing_raised do
@@ -187,10 +192,25 @@
valid_trains = line.to(:ogilve).from(:arlington_heights).at('12:35').trains
assert_equal([train2], valid_trains)
end
+ def test_trains_filter_by_start_with_delay_threshold
+ line = Metra.new.line(:up_nw).delay_threshold(10)
+
+ stop1 = MetraSchedule::Stop.new :station => :arlington_heights, :time => Time.parse('12:30')
+ stop2 = MetraSchedule::Stop.new :station => :arlington_heights, :time => Time.parse('12:40')
+ stop3 = MetraSchedule::Stop.new :station => :ogilve, :time => Time.parse('13:30')
+ train1 = MetraSchedule::Train.new :stops => [stop1, stop3], :direction => :inbound, :schedule => :weekday
+ train2 = MetraSchedule::Train.new :stops => [stop2, stop3], :direction => :inbound, :schedule => :weekday
+ train1.delay = "Delayed"
+ line.engines = [train1, train2]
+
+ valid_trains = line.to(:ogilve).from(:arlington_heights).at('12:35').trains
+ assert_equal([train1, train2], valid_trains)
+ end
+
def test_trains_just_direction_and_time
line = Metra.new.line(:up_nw)
stop1 = MetraSchedule::Stop.new :station => :barrington, :time => Time.parse('12:30')
stop2 = MetraSchedule::Stop.new :station => :arlington_heights, :time => Time.parse('12:30')
@@ -317,8 +337,14 @@
train1 = MetraSchedule::Train.new :train_num => 642, :direction => :inbound, :stops => [stop1, stop2], :schedule => :weekday
train2 = MetraSchedule::Train.new :train_num => 631, :direction => :outbound, :stops => [stop1, stop2], :schedule => :holiday
line.engines = [train1, train2]
assert_equal(train1, line.find_train_by_train_num(642))
+ end
+
+ def test_delay_threshold
+ line = Metra.new.line(:up_nw)
+ line.delay_threshold(5)
+ assert_equal(5, line.del_threshold)
end
end