Files
python/exercises/practice/robot-simulator/robot_simulator_test.py
BethanyG be794198e1 [Resistor Color Expert]: Corrected Small Typos (#3469)
* Corrected small typos around resistor bands.

* Due to failing CI, alterations to the test generator script were needed.
The generated vs submitted diff now skips the first three lines of the file
so that the generation date is not picked up and flagged as needing regeneration.

Sadly, a workaround was also needed to prevent Python difflib from noting the difference
anyways and producing an empty "false positive" diff.

All templates and test files also needed to be altered to ensure that the first three
lines of every test file will always be the autogeneration comment and date.

Hopefully, this will now stop the CI failures without creating any subtle additional bugs.

* Touch up to bowling template.  Added back the error raising utility.
* Touch up to two-bucket template to add back in error raising utility.
[no important files changed]
2023-07-21 16:54:40 -07:00

146 lines
4.1 KiB
Python

# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/robot-simulator/canonical-data.json
# File last updated on 2023-07-19
import unittest
from robot_simulator import (
Robot,
NORTH,
EAST,
SOUTH,
WEST,
)
class RobotSimulatorTest(unittest.TestCase):
# Test create robot
def test_at_origin_facing_north(self):
robot = Robot(NORTH, 0, 0)
self.assertEqual(robot.coordinates, (0, 0))
self.assertEqual(robot.direction, NORTH)
def test_at_negative_position_facing_south(self):
robot = Robot(SOUTH, -1, -1)
self.assertEqual(robot.coordinates, (-1, -1))
self.assertEqual(robot.direction, SOUTH)
# Test rotating clockwise
def test_changes_north_to_east(self):
robot = Robot(NORTH, 0, 0)
robot.move("R")
self.assertEqual(robot.coordinates, (0, 0))
self.assertEqual(robot.direction, EAST)
def test_changes_east_to_south(self):
robot = Robot(EAST, 0, 0)
robot.move("R")
self.assertEqual(robot.coordinates, (0, 0))
self.assertEqual(robot.direction, SOUTH)
def test_changes_south_to_west(self):
robot = Robot(SOUTH, 0, 0)
robot.move("R")
self.assertEqual(robot.coordinates, (0, 0))
self.assertEqual(robot.direction, WEST)
def test_changes_west_to_north(self):
robot = Robot(WEST, 0, 0)
robot.move("R")
self.assertEqual(robot.coordinates, (0, 0))
self.assertEqual(robot.direction, NORTH)
# Test rotating counter-clockwise
def test_changes_north_to_west(self):
robot = Robot(NORTH, 0, 0)
robot.move("L")
self.assertEqual(robot.coordinates, (0, 0))
self.assertEqual(robot.direction, WEST)
def test_changes_west_to_south(self):
robot = Robot(WEST, 0, 0)
robot.move("L")
self.assertEqual(robot.coordinates, (0, 0))
self.assertEqual(robot.direction, SOUTH)
def test_changes_south_to_east(self):
robot = Robot(SOUTH, 0, 0)
robot.move("L")
self.assertEqual(robot.coordinates, (0, 0))
self.assertEqual(robot.direction, EAST)
def test_changes_east_to_north(self):
robot = Robot(EAST, 0, 0)
robot.move("L")
self.assertEqual(robot.coordinates, (0, 0))
self.assertEqual(robot.direction, NORTH)
# Test moving forward one
def test_facing_north_increments_y(self):
robot = Robot(NORTH, 0, 0)
robot.move("A")
self.assertEqual(robot.coordinates, (0, 1))
self.assertEqual(robot.direction, NORTH)
def test_facing_south_decrements_y(self):
robot = Robot(SOUTH, 0, 0)
robot.move("A")
self.assertEqual(robot.coordinates, (0, -1))
self.assertEqual(robot.direction, SOUTH)
def test_facing_east_increments_x(self):
robot = Robot(EAST, 0, 0)
robot.move("A")
self.assertEqual(robot.coordinates, (1, 0))
self.assertEqual(robot.direction, EAST)
def test_facing_west_decrements_x(self):
robot = Robot(WEST, 0, 0)
robot.move("A")
self.assertEqual(robot.coordinates, (-1, 0))
self.assertEqual(robot.direction, WEST)
# Test follow series of instructions
def test_moving_east_and_north_from_readme(self):
robot = Robot(NORTH, 7, 3)
robot.move("RAALAL")
self.assertEqual(robot.coordinates, (9, 4))
self.assertEqual(robot.direction, WEST)
def test_moving_west_and_north(self):
robot = Robot(NORTH, 0, 0)
robot.move("LAAARALA")
self.assertEqual(robot.coordinates, (-4, 1))
self.assertEqual(robot.direction, WEST)
def test_moving_west_and_south(self):
robot = Robot(EAST, 2, -7)
robot.move("RRAAAAALA")
self.assertEqual(robot.coordinates, (-3, -8))
self.assertEqual(robot.direction, SOUTH)
def test_moving_east_and_north(self):
robot = Robot(SOUTH, 8, 4)
robot.move("LAAARRRALLLL")
self.assertEqual(robot.coordinates, (11, 5))
self.assertEqual(robot.direction, NORTH)