style: black formatting on additional file

This commit is contained in:
Chris Davoren 2023-11-15 12:39:04 +10:00
parent a7e0b692c0
commit 38f23b340c
1 changed files with 27 additions and 18 deletions

View File

@ -3,8 +3,8 @@
import unittest import unittest
import toyrobot import toyrobot
class ToyRobotTests(unittest.TestCase):
class ToyRobotTests(unittest.TestCase):
def test_creation(self): def test_creation(self):
robot = toyrobot.Robot() robot = toyrobot.Robot()
self.assertFalse(robot.is_initialized()) self.assertFalse(robot.is_initialized())
@ -17,25 +17,27 @@ class ToyRobotTests(unittest.TestCase):
def test_invalid_max_x(self): def test_invalid_max_x(self):
exception_thrown = False exception_thrown = False
try: try:
robot = toyrobot.Robot(-1, 5) toyrobot.Robot(-1, 5)
except ValueError as ve: except ValueError:
exception_thrown = True exception_thrown = True
self.assertTrue(exception_thrown) self.assertTrue(exception_thrown)
def test_invalid_max_y(self): def test_invalid_max_y(self):
exception_thrown = False exception_thrown = False
try: try:
robot = toyrobot.Robot(5, -1) toyrobot.Robot(5, -1)
except ValueError as ve: except ValueError:
exception_thrown = True exception_thrown = True
self.assertTrue(exception_thrown) self.assertTrue(exception_thrown)
def test_valid_place(self): def test_valid_place(self):
robot = toyrobot.Robot() robot = toyrobot.Robot()
robot.place(1, 1, "NORTH") robot.place(1, 1, "NORTH")
self.assertTrue(robot.is_initialized() and \ self.assertTrue(
robot.get_position() == (1, 1) and \ robot.is_initialized()
robot.get_direction() == "NORTH") and robot.get_position() == (1, 1)
and robot.get_direction() == "NORTH"
)
def test_invalid_place_position_x(self): def test_invalid_place_position_x(self):
robot = toyrobot.Robot() robot = toyrobot.Robot()
@ -66,17 +68,21 @@ class ToyRobotTests(unittest.TestCase):
robot = toyrobot.Robot() robot = toyrobot.Robot()
robot.place(5, 5, "NORTH") robot.place(5, 5, "NORTH")
robot.place(2, 2) robot.place(2, 2)
self.assertTrue(robot.is_initialized() and \ self.assertTrue(
robot.get_position() == (2, 2) and \ robot.is_initialized()
robot.get_direction() == "NORTH") and robot.get_position() == (2, 2)
and robot.get_direction() == "NORTH"
)
def test_double_place_2(self): def test_double_place_2(self):
robot = toyrobot.Robot() robot = toyrobot.Robot()
robot.place(5, 5, "NORTH") robot.place(5, 5, "NORTH")
robot.place(2, 2, "SOUTH") robot.place(2, 2, "SOUTH")
self.assertTrue(robot.is_initialized() and \ self.assertTrue(
robot.get_position() == (2, 2) and \ robot.is_initialized()
robot.get_direction() == "SOUTH") and robot.get_position() == (2, 2)
and robot.get_direction() == "SOUTH"
)
def test_valid_movement_x(self): def test_valid_movement_x(self):
robot = toyrobot.Robot() robot = toyrobot.Robot()
@ -150,9 +156,11 @@ class ToyRobotTests(unittest.TestCase):
robot.move() robot.move()
robot.place(3, 1) robot.place(3, 1)
robot.move() robot.move()
self.assertTrue(robot.is_initialized() and \ self.assertTrue(
robot.get_position() == (3, 2) and \ robot.is_initialized()
robot.get_direction() == "NORTH") and robot.get_position() == (3, 2)
and robot.get_direction() == "NORTH"
)
def test_example_d_commands(self): def test_example_d_commands(self):
robot = toyrobot.Robot() robot = toyrobot.Robot()
@ -164,5 +172,6 @@ class ToyRobotTests(unittest.TestCase):
robot.interpret_command("MOVE") robot.interpret_command("MOVE")
self.assertTrue(str(robot) == "3,2,NORTH") self.assertTrue(str(robot) == "3,2,NORTH")
if __name__ == '__main__':
if __name__ == "__main__":
unittest.main() unittest.main()