Beispiel #1
0
    def test_robot_left(self):
        subject = Robot()
        subject.left()

        self.assertEqual(subject.x, 0)
        self.assertEqual(subject.y, 0)
        self.assertEqual(subject.facing, 'WEST')
Beispiel #2
0
    def test_robot_move(self):
        subject = Robot()
        subject.move()

        self.assertEqual(subject.x, 0)
        self.assertEqual(subject.y, 1)
        self.assertEqual(subject.facing, 'NORTH')
Beispiel #3
0
    def test_robot_place(self):
        subject = Robot()
        subject.place('4,2,EAST')

        self.assertEqual(subject.x, 4)
        self.assertEqual(subject.y, 2)
        self.assertEqual(subject.facing, 'EAST')
Beispiel #4
0
    def test_robot_call_move(self):
        subject = Robot()
        subject.call('MOVE')

        self.assertEqual(subject.x, 0)
        self.assertEqual(subject.y, 1)
        self.assertEqual(subject.facing, 'NORTH')
Beispiel #5
0
    def test_robot_call_unknown(self):
        subject = Robot()
        subject.call('UNKNOWN')

        self.assertEqual(subject.x, 0)
        self.assertEqual(subject.y, 0)
        self.assertEqual(subject.facing, 'NORTH')
Beispiel #6
0
    def test_robot_call_left(self):
        subject = Robot()
        subject.call('LEFT')

        self.assertEqual(subject.x, 0)
        self.assertEqual(subject.y, 0)
        self.assertEqual(subject.facing, 'WEST')
Beispiel #7
0
    def test_robot_call_place(self):
        subject = Robot()
        subject.call('PLACE', '4,2,EAST')

        self.assertEqual(subject.x, 4)
        self.assertEqual(subject.y, 2)
        self.assertEqual(subject.facing, 'EAST')
Beispiel #8
0
    def test_robot_right(self):
        subject = Robot()
        subject.right()

        self.assertEqual(subject.x, 0)
        self.assertEqual(subject.y, 0)
        self.assertEqual(subject.facing, 'EAST')
def test_turn_right_on_robot_not_placed():
    with pytest.raises(MissingPlaceCommandException) as e:
        robot = Robot()
        robot.turn_right()
    assert str(e.value) == 'Robot not placed.'
    assert robot.x_coordinate is None
    assert robot.y_coordinate is None
    assert robot.facing is None
def test_move_on_robot_placed(input_params, x, y, direction):
    robot = Robot()
    robot.place(input_params)
    robot.move()
    assert robot.x_coordinate == x
    assert robot.y_coordinate == y
    assert robot.facing == direction
Beispiel #11
0
    def test_robot_move_west_from_place_2_2_west(self):
        subject = Robot()
        subject.place('2,2,WEST')
        subject.move()

        self.assertEqual(subject.x, 1)
        self.assertEqual(subject.y, 2)
        self.assertEqual(subject.facing, 'WEST')
Beispiel #12
0
    def test_robot_move_east_from_origin(self):
        subject = Robot()
        subject.right()
        subject.move()

        self.assertEqual(subject.x, 1)
        self.assertEqual(subject.y, 0)
        self.assertEqual(subject.facing, 'EAST')
Beispiel #13
0
    def test_robot_move_south_from_place_2_2_south(self):
        subject = Robot()
        subject.place('2,2,SOUTH')
        subject.move()

        self.assertEqual(subject.x, 2)
        self.assertEqual(subject.y, 1)
        self.assertEqual(subject.facing, 'SOUTH')
Beispiel #14
0
    def test_robot_move_east_from_place_2_2_east(self):
        subject = Robot()
        subject.place('2,2,EAST')
        subject.move()

        self.assertEqual(subject.x, 3)
        self.assertEqual(subject.y, 2)
        self.assertEqual(subject.facing, 'EAST')
Beispiel #15
0
    def test_robot_move_north_from_place_2_2_north(self):
        subject = Robot()
        subject.place('2,2,NORTH')
        subject.move()

        self.assertEqual(subject.x, 2)
        self.assertEqual(subject.y, 3)
        self.assertEqual(subject.facing, 'NORTH')
Beispiel #16
0
    def test_robot_move_west_from_origin(self):
        subject = Robot()
        subject.left()
        subject.move()

        self.assertEqual(subject.x, 0)
        self.assertEqual(subject.y, 0)
        self.assertEqual(subject.facing, 'WEST')
def test_move_for_robot_out_of_bounds(input_params, x, y, direction):
    with pytest.raises(MoveOutOfBoundsException) as e:
        robot = Robot()
        robot.place(input_params)
        robot.move()
    assert str(e.value) == 'Cannot move robot. Coordinates out of bound.'
    assert robot.x_coordinate == x
    assert robot.y_coordinate == y
    assert robot.facing == direction
def test_report_on_robot_placed(capsys):
    robot = Robot()
    robot.place([0, 0, 'NORTH'])
    robot.report()
    assert robot.x_coordinate == 0
    assert robot.y_coordinate == 0
    assert robot.facing == 'NORTH'
    captured = capsys.readouterr()
    assert captured.out.replace('\n', '') == 'Output: 0, 0, NORTH'
Beispiel #19
0
    def test_robot_move_south_from_origin(self):
        subject = Robot()
        subject.left()
        subject.left()
        subject.move()

        self.assertEqual(subject.x, 0)
        self.assertEqual(subject.y, 0)
        self.assertEqual(subject.facing, 'SOUTH')
def test_turn_left_on_robot_placed(input_params, expected_direction):
    robot = Robot()
    robot.place(input_params)
    robot.turn_left()
    assert robot.facing == expected_direction
Beispiel #21
0
 def test_robot_default_constructor(self):
     subject = Robot()
     self.assertEqual(subject.x, 0)
     self.assertEqual(subject.y, 0)
     self.assertEqual(subject.facing, 'NORTH')
def test_invoke_for_report(mock_report):
    robot = Robot()
    robot.invoke('REPORT', None)
    mock_report.assert_called_once_with(robot)
def test_invoke_for_turn_right(mock_turn_right):
    robot = Robot()
    robot.invoke('RIGHT', None)
    mock_turn_right.assert_called_once_with(robot)
def test_invoke_for_turn_left(mock_turn_left):
    robot = Robot()
    robot.invoke('LEFT', None)
    mock_turn_left.assert_called_once_with(robot)
def test_invoke_for_place(mock_place):
    robot = Robot()
    robot.invoke('PLACE', [0, 0, 'NORTH'])
    mock_place.assert_called_once_with(robot, [0, 0, 'NORTH'])
def test_place_with_valid_params():
    robot = Robot()
    robot.place([0, 0, 'NORTH'])
    assert robot.x_coordinate == 0
    assert robot.y_coordinate == 0
    assert robot.facing == 'NORTH'
def test_invoke_for_move(mock_move):
    robot = Robot()
    robot.invoke('MOVE', None)
    mock_move.assert_called_once_with(robot)
Beispiel #28
0
 def test_robot_constructor(self):
     subject = Robot(1, 2, 'SOUTH')
     self.assertEqual(subject.x, 1)
     self.assertEqual(subject.y, 2)
     self.assertEqual(subject.facing, 'SOUTH')
Beispiel #29
0
 def test_robot_report(self):
     subject = Robot()
     with OutputBuffer() as bf:
         self.assertIsNone(subject.report())
     self.assertEqual(bf.out, '0, 0, NORTH\n')