Exemple #1
0
	def test_invalid_attach(self):
		t1 = Track("Track1", self.n, up_prefix="A", down_prefix="A", up=0, down=1)
		t2 = Track("Track2", self.n, up_prefix="A", down_prefix="A", up=0, down=1)
		with self.assertRaises(TrackError):
			t1.attach(0, Direction.UP)
		with self.assertRaises(TrackError):
			t1.attach(t2, 0)
Exemple #2
0
	def test_next_down_signal(self):
		# UP <-----> DN
		#       3   5
		# +---------+---------+
		#       ->  -o
		t = Track("Track1", self.n, up_prefix="A", down_prefix="A", up=0, down=10, joints=[5])
		s = Signal()
		s.attach(t, 5, Direction.DOWN)
		self.assertEqual(t.next_signal(3, Direction.DOWN), s)
Exemple #3
0
	def test_previous_up_signal(self):
		# UP <-----> DN
		#      <-  o-
		# +---------+---------+
		#       3   5
		t = Track("Track1", self.n, up_prefix="A", down_prefix="A", up=0, down=10, joints=[5])
		s = Signal()
		s.attach(t, 5, Direction.UP)
		self.assertEqual(t.prev_signal(3, Direction.UP), s)
Exemple #4
0
	def test_next_up_signal(self):
		# UP <-----> DN
		#          o-    <-
		# +---------+---------+
		#           5     8
		t = Track("Track1", self.n, up_prefix="A", down_prefix="A", up=0, down=10, joints=[5])
		s = Signal()
		s.attach(t, 5, Direction.UP)
		self.assertEqual(t.next_signal(8, Direction.UP), s)
Exemple #5
0
	def test_previous_down_signal(self):
		# UP <-----> DN
		#           5     8
		# +---------+---------+
		#           -o    ->
		t = Track("Track1", self.n, up_prefix="A", down_prefix="A", up=0, down=10, joints=[5])
		s = Signal()
		s.attach(t, 5, Direction.DOWN)
		self.assertEqual(t.prev_signal(8, Direction.DOWN), s)
Exemple #6
0
	def test_adjacent_track_sections(self):
		# UP <-----> DN
		#
		#  <--- t1 --> <-- t2 --->
		# +-----+-----+-----+-----+
		#    1     0     1     0
		t1 = Track("Track1", self.n, up_prefix="A", down_prefix="A", up=0, down=4, joints=[2])
		t2 = Track("Track2", self.n, up_prefix="A", down_prefix="A", up=0, down=4, joints=[2])
		t1.attach(t2, Direction.DOWN)
		self.assertEqual(t1.sections[0].down_next, t2.sections[1])
		self.assertEqual(t2.sections[1].up_next, t1.sections[0])
Exemple #7
0
	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)
Exemple #8
0
	def test_longer_chaining_line(self):
		self.assertFalse(Track.chaining_line_is_valid("AAA"))
Exemple #9
0
	def test_long_track_number(self):
		self.assertFalse(Track.number_is_valid("12"))
Exemple #10
0
	def test_long_chaining_line(self):
		self.assertTrue(Track.chaining_line_is_valid("AA"))
Exemple #11
0
	def test_lowercase_track_number(self):
		self.assertTrue(Track.number_is_valid("m"))
Exemple #12
0
	def test_numeric_track_number(self):
		self.assertFalse(Track.number_is_valid(0))
Exemple #13
0
	def test_next_track_down(self):
		t1 = Track("Track1", self.n, up_prefix="A", down_prefix="A", up=0, down=1)
		t2 = Track("Track2", self.n, up_prefix="A", down_prefix="A", up=0, down=1)
		t1.attach(t2, Direction.DOWN)
		self.assertEqual(t1.down_next, t2)
		self.assertEqual(t2.up_next, t1)
Exemple #14
0
	def test_uppercase_track_number(self):
		self.assertTrue(Track.number_is_valid("M"))
Exemple #15
0
	def test_alphanumeric_chaining_prefix(self):
		self.assertTrue(Track.chaining_prefix_is_valid("A1"))
Exemple #16
0
	def test_alphanumeric_chaining_line(self):
		self.assertFalse(Track.chaining_line_is_valid("A1"))
Exemple #17
0
	def test_digits_chaining_line(self):
		self.assertFalse(Track.chaining_line_is_valid("10"))
Exemple #18
0
	def test_section_with_offset_joint(self):
		t = Track("Track1", self.n, up_prefix="A", down_prefix="A", up=0, down=5, joints=[2.5])
		self.assertEqual(t.section_with_offset(2.5), None)
Exemple #19
0
	def test_section_with_offset_inside_section(self):
		t = Track("Track1", self.n, up_prefix="A", down_prefix="A", up=0, down=5, joints=[2.5])
		sec = t.section_with_offset(3)
		self.assertEqual(sec.track, t)
		self.assertEqual(sec.up, 2.5)
		self.assertEqual(sec.down, 5)
Exemple #20
0
	def test_numeric_chaining_line(self):
		self.assertFalse(Track.chaining_line_is_valid(0))
Exemple #21
0
	def test_prev_signal_none(self):
		t = Track("Track1", self.n, up_prefix="A", down_prefix="A", up=0, down=10, joints=[5])
		self.assertEqual(t.prev_signal(8, Direction.UP), None)
		self.assertEqual(t.prev_signal(3, Direction.DOWN), None)
Exemple #22
0
	def test_letter_chaining_prefix(self):
		self.assertTrue(Track.chaining_prefix_is_valid("N"))
Exemple #23
0
	def test_digit_track_number(self):
		self.assertTrue(Track.number_is_valid("1"))
Exemple #24
0
	def test_lowercase_chaining_prefix(self):
		self.assertTrue(Track.chaining_prefix_is_valid("n"))
Exemple #25
0
	def test_numeric_chaining_prefix(self):
		self.assertFalse(Track.chaining_prefix_is_valid(0))