Added more complex unit tests.

This commit is contained in:
Chris Davoren 2023-10-07 18:12:26 +10:00
parent ff704ec625
commit a59cf70e9d
1 changed files with 31 additions and 1 deletions

View File

@ -115,6 +115,14 @@ class ToyRobotTests(unittest.TestCase):
self.assertTrue(robot.get_position() == (0, 1)) self.assertTrue(robot.get_position() == (0, 1))
def test_rotate_left(self): def test_rotate_left(self):
robot = toyrobot.Robot()
robot.place(0, 0, "SOUTH")
robot.rotate_left()
self.assertTrue(robot.get_direction() == "EAST")
def test_rotate_left_2(self):
# Blackbox test - ensures internal numerical direction using modulus
# correctly on decrement.
robot = toyrobot.Robot() robot = toyrobot.Robot()
robot.place(0, 0, "NORTH") robot.place(0, 0, "NORTH")
robot.rotate_left() robot.rotate_left()
@ -128,11 +136,33 @@ class ToyRobotTests(unittest.TestCase):
def test_rotate_right_2(self): def test_rotate_right_2(self):
# Blackbox test - ensures internal numerical direction using modulus # Blackbox test - ensures internal numerical direction using modulus
# correctly. # correctly on increment.
robot = toyrobot.Robot() robot = toyrobot.Robot()
robot.place(0, 0, "WEST") robot.place(0, 0, "WEST")
robot.rotate_right() robot.rotate_right()
self.assertTrue(robot.get_direction() == "NORTH") self.assertTrue(robot.get_direction() == "NORTH")
def test_example_d_calls(self):
robot = toyrobot.Robot()
robot.place(1, 2, "EAST")
robot.move()
robot.rotate_left()
robot.move()
robot.place(3, 1)
robot.move()
self.assertTrue(robot.is_initialized() and \
robot.get_position() == (3, 2) and \
robot.get_direction() == "NORTH")
def test_example_d_commands(self):
robot = toyrobot.Robot()
robot.interpret_command("PLACE 1,2,EAST")
robot.interpret_command("MOVE")
robot.interpret_command("LEFT")
robot.interpret_command("MOVE")
robot.interpret_command("PLACE 3,1")
robot.interpret_command("MOVE")
self.assertTrue(str(robot) == "3,2,NORTH")
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()