Exemple #1
0
    def test_water_level(self):
        '''Tests if water level increases after watering.'''
        database = MemcachedDatabase()
        world = World()

        robot = Robot("198.1287.fkdfjei", "123")
        robot.set_location((5, 0))
        robot.set_has_water(True)

        plant = Plant()
        plant.set_water_level(30)

        world.plant(plant, (5, 0))

        database.commit()

        action = WaterAction()
        action.do_action(robot, ["198.1287.fkdfjei"])

        database.commit()

        updated_square = world.get_square((5, 0))
        plant = updated_square.get_plant()

        # Checking if honor increased.
        self.assertEqual(robot.get_honor(), 1)

        self.assertEqual(plant.get_water_level(), 100)
        self.assertFalse(robot.get_has_water())
    def test_water_level(self):
        '''Tests if water level increases after watering.'''
        database = MemcachedDatabase()
        world = World()

        robot = Robot("198.1287.fkdfjei", "123")
        robot.set_location((5, 0))
        robot.set_has_water(True)

        plant = Plant()
        plant.set_water_level(30)

        world.plant(plant, (5, 0))

        database.commit()

        action = WaterAction()
        action.do_action(robot, ["198.1287.fkdfjei"])

        database.commit()

        updated_square = world.get_square((5, 0))
        plant = updated_square.get_plant()

        # Checking if honor increased.
        self.assertEqual(robot.get_honor(), 1)

        self.assertEqual(plant.get_water_level(), 100)
        self.assertFalse(robot.get_has_water())
Exemple #3
0
    def test_have_no_water(self):
        '''Tests if a robot has water.'''
        robot = Robot("1223.9887.099", "123")
        robot.set_location((6, 0))
        robot.set_has_water(False)

        action = WaterAction()

        with self.assertRaises(RobotHaveNoWaterError):
            action.do_action(robot, ["1223.9887.099"])
    def test_have_no_water(self):
        '''Tests if a robot has water.'''
        robot = Robot("1223.9887.099", "123")
        robot.set_location((6, 0))
        robot.set_has_water(False)

        action = WaterAction()

        with self.assertRaises(RobotHaveNoWaterError):
            action.do_action(robot, ["1223.9887.099"])
Exemple #5
0
    def test_getting_data(self):
        robot = Robot("13329.12900.12213", "123", name="HappyBot")
        robot.set_energy(124)
        robot.set_honor(7)
        robot.set_life(3)
        robot.set_has_water(True)

        plant = Plant()
        plant.set_age(64)
        plant.set_water_level(98)

        database = MemcachedDatabase()
        database.add_robot(robot, (6, 11))
        square = database.get_square((5, 11), for_update=True)
        square.set_plant(plant)
        database.commit()

        expected_result = {
            "5,11": {
                "surface_type": MapSquareTypes.SOIL,
                "plant": {
                    "water_level": 98,
                    "matured": True,
                    "age": 64
                },
                "robot": None
            },
            "6,11": {
                "surface_type": MapSquareTypes.SOIL,
                "plant": None,
                "robot": {
                    "name": "HappyBot",
                    "has_water": True,
                    "energy": 124,
                    "life": 3,
                    "honor": 7
                }
            },
            "6,2": {
                "surface_type": MapSquareTypes.ROCK,
                "robot": None,
                "plant": None
            }
        }

        communicator = Communicator()
        result = communicator.execute_command("NhdEr32Qcmp0Iue3", "map_data",
                                              expected_result.keys())

        self.assertCountEqual(result, expected_result)
        for expected_key, expected_value in expected_result.items():
            self.assertDictEqual(result[expected_key], expected_value)
Exemple #6
0
    def test_locked_square(self):
        '''Tests with a already-locked square.'''
        database = MemcachedDatabase()
        robot = Robot("oi981872yuweu.9887", "123")
        robot.set_location((5, 0))
        robot.set_has_water(True)

        database.get_square((5, 0), for_update=True)

        action = WaterAction()

        with self.assertRaises(LockAlreadyAquiredError):
            action.do_action(robot, ["oi981872yuweu.9887"])

        # Freeing lock.
        database.rollback()
    def test_locked_square(self):
        '''Tests with a already-locked square.'''
        database = MemcachedDatabase()
        robot = Robot("oi981872yuweu.9887", "123")
        robot.set_location((5, 0))
        robot.set_has_water(True)

        database.get_square((5, 0), for_update=True)

        action = WaterAction()

        with self.assertRaises(LockAlreadyAquiredError):
            action.do_action(robot, ["oi981872yuweu.9887"])

        # Freeing lock.
        database.rollback()
Exemple #8
0
    def test_no_plant_square(self):
        '''Tests watering a square without any plant.'''
        database = MemcachedDatabase()

        robot = Robot("098kk.ski87.99", "123")
        robot.set_location((6, 0))
        robot.set_has_water(True)

        action = WaterAction()

        action.do_action(robot, ["098kk.ski87.99"])

        self.assertFalse(robot.get_has_water())
        # Honor shouldn't increase because this robot didn't really watered a plant.
        self.assertEqual(robot.get_honor(), 0)

        database.rollback()
    def test_no_plant_square(self):
        '''Tests watering a square without any plant.'''
        database = MemcachedDatabase()

        robot = Robot("098kk.ski87.99", "123")
        robot.set_location((6, 0))
        robot.set_has_water(True)

        action = WaterAction()

        action.do_action(robot, ["098kk.ski87.99"])

        self.assertFalse(robot.get_has_water())
        # Honor shouldn't increase because this robot didn't really watered a plant.
        self.assertEqual(robot.get_honor(), 0)

        database.rollback()