def testGetTimeToPos(self): p = roomba.Position(1, 1) posible_positions = roomba.product(range(3), repeat=2) func_soultions = [] for element in posible_positions: solution = p.getTimeToPos(roomba.Position(element[0], element[1]), 1) func_soultions.append(solution) repetition = [2**.5, 1.0] solutions = repetition * 2 + [0] + list(reversed(repetition)) * 2 self.assertListEqual(func_soultions, solutions)
def testGetBearing(self): p = roomba.Position(1, 1) posible_positions = [ element for element in roomba.product(range(3), repeat=2) if element != (1, 1) ] func_soultions = [] for element in posible_positions: solution = p.getBearing(roomba.Position(element[0], element[1])) func_soultions.append(solution) solutions = [225.0, 180.0, 135.0, 270.0, 90.0, 315.0, 0.0, 45.0] self.assertListEqual(func_soultions, solutions)
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 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 testGetX(self): p = roomba.Position(1, 2) x = p.getX() self.assertEqual(x, 1)
def testCleanTileAtPosition(self): r = roomba.RectangularRoom(10, 10) r.cleanTileAtPosition(roomba.Position(1, 1)) self.assertTrue(r.isTileCleaned(1, 1))
def testGetY(self): p = roomba.Position(1, 2) y = p.getY() self.assertEqual(y, 2)
def testSetPosition(self): self.robot.setRobotPosition(roomba.Position(3, 3)) position = self.robot.getRobotPosition() self.assertEqual((position.getX(), position.getY()), (3, 3))