def test_prev_signal_after_switch(self): # UP <-----> DN # 0 3 5 10 # +----+-----+-------------+ # -o \ 8 # '-+---------+ # 6 -> 10 t1 = Track("Track1", self.n, up_prefix="A", down_prefix="A", up=0, down=10, joints=[3]) t2 = Track("Track2", self.n, up_prefix="B", down_prefix="B", up=6, down=10) i = Interlocking("Test", self.n) l = Lever(1, i) sw = Switch(lever=l, label="A") sw.attach(t1, 5, Direction.DOWN) sw.attach_turnout(t2, Direction.UP) s = Signal() s.attach(t1, 3, Direction.DOWN) self.assertEqual(t2.prev_signal(8, Direction.DOWN), s)
def test_fork_route(self): # UP <-----> DN # # 2 7 10 16 18 # --+----------+-----+------------+---- t1 # -o 2 -o 4 \ 5 -o 6 # '----------+---- t2 # -o 8 n = TrackNetwork("Test") i = Interlocking("Test", n) l2, l4, l5, l6, l8 = [Lever(j, i) for j in [2, 4, 5, 6, 8]] t1 = Track("Track1", n, up_prefix="B", down_prefix="B", up=0, down=18, joints=[2, 7, 16]) t2 = Track("Track2", n, up_prefix="B", down_prefix="B", up=12, down=18) sw = Switch(lever=l5, label="A") sw.attach(t1, 10, Direction.DOWN) sw.attach_turnout(t2, Direction.UP) s2 = Signal(lever=l2, control_length = ControlLength([ (l5.normal, [SWO(t1, 3), SWO(t1, 8)]), (l5.reverse, [SWO(t1, 3), SWO(t1, 8), SWO(t2, 15)]) ])) s4 = Signal(lever=l4, control_length = ControlLength([ (l5.normal, [SWO(t1, 8)]), (l5.reverse, [SWO(t1, 8), SWO(t2, 15)]) ])) s6 = Signal(lever=l6) s8 = Signal(lever=l8) s2.attach(t1, 2, Direction.DOWN) s4.attach(t1, 7, Direction.DOWN) s6.attach(t1, 16, Direction.DOWN) s8.attach(t2, 16, Direction.DOWN) routes = i.routes_from(l2) self.assertIn(([l2], s4), routes) self.assertIn(([l2, l4], s6), routes) self.assertIn(([l2, l4, l5], s8), routes) self.assertEquals(len(routes), 3)