Exemplo n.º 1
0
 def test_map_controller_heading(self):
     """Test mapping Controller Heading to User Heading."""
     d = roverdispatcher.RoverDispatcher()
     self.assertEquals(d.map_controller_heading(math.pi/2), 'N')
     self.assertEquals(d.map_controller_heading(3*math.pi/2), 'S')
     self.assertEquals(d.map_controller_heading(0), 'E')
     self.assertEquals(d.map_controller_heading(math.pi), 'W')
     self.assertRaises(Exception, d.map_controller_heading, math.pi/4)
Exemplo n.º 2
0
 def test_end_to_end(self):
     """Tests the Mars Rover Solution End to End for given test data."""
     input = '5 5\n1 2 N\nLMLMLMLMM\n3 3 E\nMMRMMRMRRM'
     output = '1 3 N\n5 1 E\n'
     dispatcher = roverdispatcher.RoverDispatcher()
     dispatcher.parse_input(input)
     dispatcher.dispatch()
     self.assertEquals(dispatcher.render_view(), output)
Exemplo n.º 3
0
 def test_map_user_heading(self):
     """Test mapping of User Heading to Controller Heading."""
     d = roverdispatcher.RoverDispatcher()
     self.assertEquals(d.map_user_heading('N'), math.pi/2)
     self.assertEquals(d.map_user_heading('S'), 3*math.pi/2)
     self.assertEquals(d.map_user_heading('E'), 0)
     self.assertEquals(d.map_user_heading('W'), math.pi)
     self.assertRaises(Exception, d.map_user_heading, 'NW')
Exemplo n.º 4
0
 def test_dispatch(self):
     """Test unknown instruction."""
     d = roverdispatcher.RoverDispatcher()
     vertices = ((0, 0, 0), (5, 5, 0))
     d.controller = marsrovercontroller.MarsRoverController(vertices)
     d.parse_rover('1 2 N')
     d.parse_instruction(' L L')
     self.assertRaises(Exception, d.dispatch)
Exemplo n.º 5
0
 def test_convert_instruction(self):
     """Test converting User Instruction to Controller Instruction."""
     d = roverdispatcher.RoverDispatcher()
     vertices = ((0, 0, 0), (5, 5, 0))
     d.parse_instruction('LLMMRR')
     self.assertEquals(d.instructions[0], ['L', 'L', 'M', 'M', 'R', 'R'])
     d.parse_instruction(' LL ')
     self.assertEquals(d.instructions[1], ['L', 'L'])
Exemplo n.º 6
0
 def test_convert_vertices(self):
     """Test converting User Vertices to Controller Vertices."""
     dispatcher = roverdispatcher.RoverDispatcher()
     self.assertEquals(dispatcher.parse_vertex('3 3'), (3, 3, 0))
     self.assertEquals(dispatcher.parse_vertex(' 3 3 '), (3, 3, 0))
     self.assertRaises(ValueError, dispatcher.parse_vertex, 'a b')
     self.assertRaises(ValueError, dispatcher.parse_vertex, ' ')
     self.assertRaises(ValueError, dispatcher.parse_vertex, '5.5 5.5')
Exemplo n.º 7
0
 def test_convert_rover(self):
     """Test converting User Rover to Controller Rover."""
     d = roverdispatcher.RoverDispatcher()
     vertices = ((0, 0, 0), (5, 5, 0))
     d.controller = marsrovercontroller.MarsRoverController(vertices)
     d.parse_rover('1 2 N')
     self.assertEquals(d.controller.get_rover('1 2 N').position, (1, 2, 0))
     d.parse_rover(' 2 2 N ')
     self.assertEquals(d.controller.get_rover('2 2 N').position, (2, 2, 0))
     self.assertRaises(Exception, d.parse_rover, '2 2')
     self.assertRaises(ValueError, d.parse_rover, 's 2 N')
     self.assertRaises(ValueError, d.parse_rover, '2.2 2 N')