class TestRandomRobot(unittest.TestCase): r = roomba.RectangularRoom(10, 10) def testHeadingChange(self): robot = roomba.RandomWalkRobot(self.r, 1) direction = robot.getRobotDirection() robot.updatePositionAndClean() self.assertNotEqual(direction, robot.getRobotDirection()) def testMovement(self): robot = roomba.RandomWalkRobot(self.r, 1) position = robot.getRobotPosition() robot.updatePositionAndClean() direction = robot.getRobotDirection() rob_p = robot.getRobotPosition() calc_p = position.getNewPosition(direction, 1) self.assertEqual((rob_p.getX(), rob_p.getY()), (calc_p.getX(), calc_p.getY())) def testPositionIsClean(self): robot = roomba.RandomWalkRobot(self.r, 1) robot.updatePositionAndClean() position = robot.getRobotPosition() self.assertTrue( self.r.isTileCleaned(int(position.getX()), int(position.getY())))
class TestStandardRobot(unittest.TestCase): r = roomba.RectangularRoom(5, 5) def testMovement(self): robot = roomba.StandardRobot(self.r, 1) position = robot.getRobotPosition() robot.updatePositionAndClean() bearing = robot.getRobotDirection() rob_pos = robot.getRobotPosition() calc_pos = position.getNewPosition(bearing, 1) self.assertEqual((rob_pos.getX(), rob_pos.getY()), (calc_pos.getX(), calc_pos.getY())) def testChangeHeading(self): robot = roomba.StandardRobot(self.r, 1) robot.setRobotPosition(roomba.Position(0, 0)) robot.setRobotDirection(180) robot.updatePositionAndClean() self.assertNotEqual( robot.getRobotDirection(), 180) and self.assertTrue( self.r.isPositionInRoom(robot.getRobotPosition())) def testPositionIsClean(self): robot = roomba.StandardRobot(self.r, 1) robot.updatePositionAndClean() position = robot.getRobotPosition() self.assertTrue( self.r.isTileCleaned(int(position.getX()), int(position.getY())))
class TestGraphDrivenRobot(unittest.TestCase): r = roomba.RectangularRoom(10, 8) def testNavigateRaise(self): robot = roomba.GraphDrivenRobot(self.r, 1) robot.setRobotDirection(0) robot.Navigate(100) self.assertRaises(ValueError)
class TestRobot(unittest.TestCase): r = roomba.RectangularRoom(5, 5) robot = roomba.Robot(r, 1) def testCleanedInitTile(self): position = self.robot.getRobotPosition() x, y = position.getX(), position.getY() self.assertTrue(self.r.isTileCleaned(int(x), int(y))) def testSetPosition(self): self.robot.setRobotPosition(roomba.Position(3, 3)) position = self.robot.getRobotPosition() self.assertEqual((position.getX(), position.getY()), (3, 3)) def testSetDirection(self): r = roomba.RectangularRoom(5, 5) self.robot = roomba.Robot(r, 1) self.robot.setRobotDirection(227) self.assertEqual(self.robot.getRobotDirection(), 227)
def testGetRandomPosition(self): r = roomba.RectangularRoom(4, 3) position = r.getRandomPosition() self.assertTrue(r.isPositionInRoom(position))
def testIsPositionInRoomNot(self): r = roomba.RectangularRoom(4, 3) self.assertFalse(r.isPositionInRoom(roomba.Position(3, 2)))
def testIsPositionInRoom(self): r = roomba.RectangularRoom(4, 3) self.assertTrue(r.isPositionInRoom(roomba.Position(2, 3)))
def testGetNumCleanedTilesAll(self): r = roomba.RectangularRoom(3, 4) for tile in roomba.product(range(4), range(3)): x, y = tile r.cleanTileAtPosition(roomba.Position(x, y)) self.assertEqual(r.getNumCleanedTiles(), 12)
def testGetNumClenedTiles1(self): r = roomba.RectangularRoom(3, 4) r.cleanTileAtPosition(roomba.Position(2, 2)) self.assertEqual(r.getNumCleanedTiles(), 1)
def testGetNumCleanedTiles(self): r = roomba.RectangularRoom(3, 4) self.assertEqual(r.getNumCleanedTiles(), 0)
def testGetNumberOfTiles(self): r = roomba.RectangularRoom(3, 4) self.assertEqual(r.getNumTiles(), 12)
def testCleanTileAtPosition(self): r = roomba.RectangularRoom(10, 10) r.cleanTileAtPosition(roomba.Position(1, 1)) self.assertTrue(r.isTileCleaned(1, 1))
def testIsTileClean(self): r = roomba.RectangularRoom(6, 10) self.assertFalse(r.isTileCleaned(1, 1))
def testGetDimensions(self): r = roomba.RectangularRoom(50, 6) self.assertEqual(r.get_dimensions(), (6, 50))
def testSetDirection(self): r = roomba.RectangularRoom(5, 5) self.robot = roomba.Robot(r, 1) self.robot.setRobotDirection(227) self.assertEqual(self.robot.getRobotDirection(), 227)