Пример #1
0
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())))
Пример #2
0
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())))
Пример #3
0
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)
Пример #4
0
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)
Пример #5
0
 def testGetRandomPosition(self):
     r = roomba.RectangularRoom(4, 3)
     position = r.getRandomPosition()
     self.assertTrue(r.isPositionInRoom(position))
Пример #6
0
 def testIsPositionInRoomNot(self):
     r = roomba.RectangularRoom(4, 3)
     self.assertFalse(r.isPositionInRoom(roomba.Position(3, 2)))
Пример #7
0
 def testIsPositionInRoom(self):
     r = roomba.RectangularRoom(4, 3)
     self.assertTrue(r.isPositionInRoom(roomba.Position(2, 3)))
Пример #8
0
 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)
Пример #9
0
 def testGetNumClenedTiles1(self):
     r = roomba.RectangularRoom(3, 4)
     r.cleanTileAtPosition(roomba.Position(2, 2))
     self.assertEqual(r.getNumCleanedTiles(), 1)
Пример #10
0
 def testGetNumCleanedTiles(self):
     r = roomba.RectangularRoom(3, 4)
     self.assertEqual(r.getNumCleanedTiles(), 0)
Пример #11
0
 def testGetNumberOfTiles(self):
     r = roomba.RectangularRoom(3, 4)
     self.assertEqual(r.getNumTiles(), 12)
Пример #12
0
 def testCleanTileAtPosition(self):
     r = roomba.RectangularRoom(10, 10)
     r.cleanTileAtPosition(roomba.Position(1, 1))
     self.assertTrue(r.isTileCleaned(1, 1))
Пример #13
0
 def testIsTileClean(self):
     r = roomba.RectangularRoom(6, 10)
     self.assertFalse(r.isTileCleaned(1, 1))
Пример #14
0
 def testGetDimensions(self):
     r = roomba.RectangularRoom(50, 6)
     self.assertEqual(r.get_dimensions(), (6, 50))
Пример #15
0
 def testSetDirection(self):
     r = roomba.RectangularRoom(5, 5)
     self.robot = roomba.Robot(r, 1)
     self.robot.setRobotDirection(227)
     self.assertEqual(self.robot.getRobotDirection(), 227)