コード例 #1
0
def test_move_world():
    rovers = [
        Rover(Position(x=1, y=2, heading='N'), Plateau(max_x=5, max_y=5)),
        Rover(Position(x=3, y=3, heading='E'), Plateau(max_x=5, max_y=5))
    ]
    world = World(Plateau(5, 5))
    world.rovers = rovers
    world.instructions = ["LMLMLMLMM", "MMRMMRMRRM"]
    world.follow_instructions()
    assert world.rovers[0].position == Position(1, 3, 'N')
    assert world.rovers[1].position == Position(5, 1, 'E')
コード例 #2
0
class TestPosition(unittest.TestCase):
    def setUp(self):
        self.pos = Position()

    def tearDown(self):
        del self.pos

    def test_1(self):
        self.assertEqual(Position().get(), (0, 0, 'North'))

    @parameterized.expand([[True, None, (0, 1, 'North')],
                           [False, "L", (0, 0, 'West')],
                           [False, "R", (0, 0, "East")],
                           [True, "L", (0, 1, "North")]])
    def test_2(self, movement, face, output):
        self.pos.set(face, movement)
        self.assertEqual(output, self.pos.get())
コード例 #3
0
def test_plateau_contains():
    assert Plateau(1, 0).contains(Position(0, 0, 'W'))
    assert Plateau(1, 0).contains(Position(1, 0, 'W'))
    assert Plateau(1, 0).contains(Position(-1, 0, 'W')) is False
    assert Plateau(1, 0).contains(Position(0, -1, 'W')) is False
    assert Plateau(1, 0).contains(Position(1, 1, 'W')) is False
    assert Plateau(1, 0).contains(Position(0, 1, 'W')) is False
コード例 #4
0
def test_report_position():
    plateau = Plateau(0, 1)
    rover = Rover(Position(0, 1, 'N'), plateau)
    assert "0 1 N\n" == rover.report_position()
コード例 #5
0
def test_move_rover_over_edge():
    plateau = Plateau(0, 1)
    rover = Rover(Position(0, 1, 'N'), plateau)
    with pytest.raises(ValueError):
        rover.move()
コード例 #6
0
def test_move_rover_on_plateau():
    plateau = Plateau(5, 5)
    rover = Rover(Position(1, 2, 'N'), plateau)
    rover.move()
    assert rover.position == Position(1, 3, 'N')
コード例 #7
0
def test_move():
    assert move(Position(1, 2, 'N')) == Position(1, 3, 'N')
    assert move(Position(1, 2, 'W')) == Position(0, 2, 'W')
    assert move(Position(1, 2, 'S')) == Position(1, 1, 'S')
    assert move(Position(1, 2, 'E')) == Position(2, 2, 'E')
コード例 #8
0
 def setUp(self):
     self.pos = Position()
コード例 #9
0
 def test_1(self):
     self.assertEqual(Position().get(), (0, 0, 'North'))