Added more complex unit tests.
This commit is contained in:
parent
ff704ec625
commit
a59cf70e9d
32
trtests.py
32
trtests.py
|
@ -115,6 +115,14 @@ class ToyRobotTests(unittest.TestCase):
|
|||
self.assertTrue(robot.get_position() == (0, 1))
|
||||
|
||||
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.place(0, 0, "NORTH")
|
||||
robot.rotate_left()
|
||||
|
@ -128,11 +136,33 @@ class ToyRobotTests(unittest.TestCase):
|
|||
|
||||
def test_rotate_right_2(self):
|
||||
# Blackbox test - ensures internal numerical direction using modulus
|
||||
# correctly.
|
||||
# correctly on increment.
|
||||
robot = toyrobot.Robot()
|
||||
robot.place(0, 0, "WEST")
|
||||
robot.rotate_right()
|
||||
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__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue