Beispiel #1
0
def test_incorect_placement(capsys):
    instructions = """
        PLACE 6,6,EAST
        REPORT
    """
    robot = Robot()
    with pytest.raises(InvalidInstruction):
        robot.simulate(instructions)
Beispiel #2
0
def test_invalid_instruction(capsys):
    instructions = """
        PLACE
        REPORT
    """
    robot = Robot()
    with pytest.raises(InvalidInstruction):
        robot.simulate(instructions)
Beispiel #3
0
def test1(capsys):
    instructions = """
        PLACE 0,0,NORTH
        MOVE
        REPORT
    """
    robot = Robot()
    robot.simulate(instructions)
    captured = capsys.readouterr()
    assert captured.out.strip() == "0,1,NORTH", "Example 1 failed"
Beispiel #4
0
def test2(capsys):
    instructions = """
        PLACE 0,0,NORTH
        LEFT
        REPORT
    """
    robot = Robot()
    robot.simulate(instructions)
    captured = capsys.readouterr()
    assert captured.out.strip() == "0,0,WEST", "Example 2 failed"
Beispiel #5
0
def test_proper_start(capsys):
    instructions = """
        MOVE
        RIGHT
        PLACE 5,5,EAST
        REPORT
    """
    robot = Robot()
    robot.simulate(instructions)
    captured = capsys.readouterr()
    assert captured.out.strip(
    ) == "5,5,EAST", "Failed finding the starting instruction"
Beispiel #6
0
def test3(capsys):
    instructions = """
        PLACE 1,2,EAST
        MOVE
        MOVE
        LEFT
        MOVE
        REPORT
    """
    robot = Robot()
    robot.simulate(instructions)
    captured = capsys.readouterr()
    assert captured.out.strip() == "3,3,NORTH", "Example 3 failed"
Beispiel #7
0
def test_overboundary2(capsys):
    instructions = """
        PLACE 5,5,EAST
        MOVE
        LEFT
        MOVE
        LEFT
        MOVE
        REPORT
    """
    robot = Robot()
    robot.simulate(instructions)
    captured = capsys.readouterr()
    assert captured.out.strip() == "4,5,WEST", "Failed boundary test 2"
Beispiel #8
0
 def test_left(self):
     steve = Robot()
     steve.place(0,0,'S')
     steve.left()
     
     self.assertEqual(steve.facing, 'E', 'robot should face east from south')
Beispiel #9
0
 def test_position(self):
     steve = Robot()
     steve.place(0,0)
     self.assertEqual(steve.position, (0,0), 'robot is in the wrong position')
 def testTurnPriorToPlacement(self):
   unplacedBot = Robot('unplacedBot', 5, 5)
   self.assertFalse(unplacedBot.turn('RIGHT'))
 def testMovePriorToPlacement(self):
   unplacedBot = Robot('unplacedBot', 5, 5)
   self.assertFalse(unplacedBot.move())
 def testReportPriorToPlacement(self):
   unplacedBot = Robot('unplacedBot', 5, 5)
   self.assertEqual(unplacedBot.report(), 'Ready to be placed on table.')
 def setUp(self):
   self.robot = Robot('Testy', 5, 5)
class RobotTestCase(unittest.TestCase):
  def setUp(self):
    self.robot = Robot('Testy', 5, 5)
  
  def testSetUp(self):
    self.assertEqual(self.robot.name, 'Testy')
    self.assertEqual(self.robot.table_height, 5)
    self.assertEqual(self.robot.table_width, 5)

  def testValidPlacement(self):
    # if the placement is allowed, place returns True
    self.assertTrue(self.robot.place(0,4,'S'))
    self.assertTrue(self.robot.place(4,4,'S'))
    # go ahead and test the properties match our parameters
    self.assertEqual(self.robot.facing, 'S')
    self.assertEqual(self.robot.x, 4)
    self.assertEqual(self.robot.y, 4)
  
  def testInvalidPlacementFacing(self):
    self.robot.place(4,4,'X') # should succeed, facing 'N' since 'X' is invalid
    self.assertEqual(self.robot.facing, 'N')

  def testInvalidPlacementCoords(self):
    # our board is 5x5 and 0-indexed
    # if the placement is refused, place returns False
    # a position of 6 is off by two.
    self.assertFalse(self.robot.place(6,6,'N'))
    # a position of 5 is off by one:
    self.assertFalse(self.robot.place(5,5,'N'))
  
  def testValidMove(self):
    self.robot.place(0,0,'N')
    # shall move forward, where forward is one position in the direction
    # it's facing, and shall refuse to move if doing so would result in
    # the robot falling 'off' the table.
    self.assertTrue(self.robot.move())
    self.assertEqual(self.robot.x, 0)
    self.assertEqual(self.robot.y, 1)
    
  def testInvalidMove(self):
    self.robot.place(0,0,'S')
    self.assertFalse(self.robot.move())
    self.assertEqual(self.robot.x, 0)
    self.assertEqual(self.robot.y, 0)

  def testValidTurn(self):
    self.robot.place(0,0,'N')
    self.assertEqual(self.robot.facing, 'N')
    self.assertTrue(self.robot.turn('LEFT'))
    self.assertEqual(self.robot.facing, 'W')
    self.assertTrue(self.robot.turn('RIGHT'))
    self.assertEqual(self.robot.facing, 'N')

  def testInvalidTurn(self):
    self.robot.place(0,0,'N')
    self.assertEqual(self.robot.facing,'N')
    self.assertFalse(self.robot.turn('STRAIGHT'))
    self.assertEqual(self.robot.facing,'N')

  def testReport(self):
    self.robot.place(0,0,'N')
    self.assertEqual(self.robot.report(), '0, 0, N')
    self.robot.move() # 0, 1, 'N'
    self.robot.move() # 0, 2, 'N'
    self.robot.turn('RIGHT') # 0, 2, 'E'
    self.robot.move() # 1, 2, 'E'
    self.robot.move() # 2, 2, 'E'
    self.robot.turn('RIGHT') # 2, 2, 'S'
    self.assertEqual(self.robot.report(), '2, 2, S')

  def testReportPriorToPlacement(self):
    unplacedBot = Robot('unplacedBot', 5, 5)
    self.assertEqual(unplacedBot.report(), 'Ready to be placed on table.')

  def testMovePriorToPlacement(self):
    unplacedBot = Robot('unplacedBot', 5, 5)
    self.assertFalse(unplacedBot.move())

  def testTurnPriorToPlacement(self):
    unplacedBot = Robot('unplacedBot', 5, 5)
    self.assertFalse(unplacedBot.turn('RIGHT'))