Пример #1
0
    def test_update_pos_and_cleanSimpleRobot(self):
        "Test SimpleRobot.update_pos_and_clean"
        r = ps3.iRoom(3, 5, 1)
        robot = ps3.SimpleRobot(r, 1.0, 1)
        robot.set_robot_position(ps3.Position(1.5, 2.5))
        robot.set_robot_direction(90)
        robot.update_pos_and_clean()
        self.assertEqual(robot.get_robot_direction(), 90,
                          "Robot direction is updated incorrectly by update_pos_and_clean: expected %r, got %r" %
                          (90, robot.get_robot_direction()))
        # check if robot position is valid
        robotPos = robot.get_robot_position()
        correctPos = ps3.Position(2.5, 2.5)
        self.assertTrue(robotPos.get_x() == correctPos.get_x() and robotPos.get_y() == correctPos.get_y(),
                          "Robot position is updated incorrectly by update_pos_and_clean: expected %r, got %r" %
                          (ps3.Position(2.5, 2.5), robot.get_robot_position()))
        self.assertTrue(2>=r.get_num_cleaned_tiles() >= 1,
                        "update_pos_and_clean should have marked one or two tiles as clean")
        self.assertTrue(r.is_tile_cleaned(1, 2) or r.is_tile_cleaned(2, 2),
                        "update_pos_and_clean should have marked either (1, 2) or (2, 2) as clean")

        # Simulate a lot of time passing...
        for i in range(20):
            robot.update_pos_and_clean()
            self.assertTrue(r.is_position_in_room(robot.get_robot_position()),
                            "Robot position %r is not in room!" % (robot.get_robot_position(),))
        self.assertNotEqual(robot.get_robot_direction(), 90,
                          "Robot direction should have been changed in update_pos_and_clean")
        self.assertTrue(r.get_num_cleaned_tiles() >= 1,
                        "update_pos_and_clean should have marked another tile as clean")
Пример #2
0
 def createRoomAndRobots(self, num_robots):
     r = ps3.iRoom(5, 7, 1)
     robots = [ps3.SimpleRobot(r, 1.0, 1) for i in range(num_robots)]
     return r, robots