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_specific_point(self):
        '''Gets information of a specific point, and check its result.'''
        database = MemcachedDatabase()
        new_robot = Robot("oie982736hhjf", "lo098173635")
        new_robot.set_location((9, 4))

        database.add_robot(new_robot, (9, 4))
        database.commit()

        action_manager = ActionManager()
        info = action_manager.do_action(new_robot.get_password(), "sense", [new_robot.get_id()])

        self.assertEqual(len(info), 9)
        self.assertEqual(info["9,4"], {"surface_type": MapSquareTypes.SOIL,
                                       "robot": True,
                                       "plant": None})
        self.assertEqual(info["9,3"], {"surface_type": MapSquareTypes.WATER,
                                       "robot": False,
                                       "plant": None})
        self.assertEqual(info["10,5"], {"surface_type": MapSquareTypes.SOIL,
                                        "robot": False,
                                        "plant": None})
        self.assertEqual(info["8,4"], {"surface_type": MapSquareTypes.SOIL,
                                       "robot": False,
                                       "plant": None})
Exemple #3
0
    def test_specific_point(self):
        '''Gets information of a specific point, and check its result.'''
        database = MemcachedDatabase()
        new_robot = Robot("oie982736hhjf", "lo098173635")
        new_robot.set_location((9, 4))

        database.add_robot(new_robot, (9, 4))
        database.commit()

        action_manager = ActionManager()
        info = action_manager.do_action(new_robot.get_password(), "sense",
                                        [new_robot.get_id()])

        self.assertEqual(len(info), 9)
        self.assertEqual(info["9,4"], {
            "surface_type": MapSquareTypes.SOIL,
            "robot": True,
            "plant": None
        })
        self.assertEqual(info["9,3"], {
            "surface_type": MapSquareTypes.WATER,
            "robot": False,
            "plant": None
        })
        self.assertEqual(info["10,5"], {
            "surface_type": MapSquareTypes.SOIL,
            "robot": False,
            "plant": None
        })
        self.assertEqual(info["8,4"], {
            "surface_type": MapSquareTypes.SOIL,
            "robot": False,
            "plant": None
        })
Exemple #4
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_ok(self):
        '''Tests a good scenario.'''
        action = PickWaterAction()
        robot = Robot("19882ukfdjfhuoIE", "123")
        robot.set_location((0, 18))

        action.do_action(robot, ["19882ukfdjfhuoIE"])

        self.assertTrue(robot.get_has_water())
    def test_ok(self):
        '''Tests a good scenario.'''
        action = PickWaterAction()
        robot = Robot("19882ukfdjfhuoIE", "123")
        robot.set_location((0, 18))

        action.do_action(robot, ["19882ukfdjfhuoIE"])

        self.assertTrue(robot.get_has_water())
Exemple #7
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"])
    def test_bad_arguments(self):
        '''Tests invalid arguments.'''
        action = PickWaterAction()
        robot = Robot("19882ukfdjfhuoIE", "123")
        robot.set_location((0, 18))

        with self.assertRaises(InvalidArgumentsError):
            action.do_action(robot, [])

        with self.assertRaises(InvalidArgumentsError):
            action.do_action(robot, ["19882ukfdjfhuoIE", ""])
    def test_bad_arguments(self):
        '''Tests invalid arguments.'''
        action = PickWaterAction()
        robot = Robot("19882ukfdjfhuoIE", "123")
        robot.set_location((0, 18))

        with self.assertRaises(InvalidArgumentsError):
            action.do_action(robot, [])

        with self.assertRaises(InvalidArgumentsError):
            action.do_action(robot, ["19882ukfdjfhuoIE", ""])
    def test_ok(self):
        '''Tests a good scenario.'''
        row = [MapSquare(MapSquareTypes.SOIL, (0, 17))]
        database = MemcachedDatabase()
        database.add_square_row(row)

        plant_action = PlantAction()

        robot = Robot("18873.182873.1123", "123")
        robot.set_location((0, 17))

        plant_action.do_action(robot, ["18873.182873.1123"])
    def test_non_water_square(self):
        '''Tests trying to pick water from a dry location.'''
        action = PickWaterAction()
        robot = Robot("19882ukfdjfhuoIE", "123")

        robot.set_location((1, 18))
        with self.assertRaises(NoWaterError):
            action.do_action(robot, ["19882ukfdjfhuoIE"])

        robot.set_location((2, 18))
        with self.assertRaises(NoWaterError):
            action.do_action(robot, ["19882ukfdjfhuoIE"])
    def test_non_water_square(self):
        '''Tests trying to pick water from a dry location.'''
        action = PickWaterAction()
        robot = Robot("19882ukfdjfhuoIE", "123")

        robot.set_location((1, 18))
        with self.assertRaises(NoWaterError):
            action.do_action(robot, ["19882ukfdjfhuoIE"])

        robot.set_location((2, 18))
        with self.assertRaises(NoWaterError):
            action.do_action(robot, ["19882ukfdjfhuoIE"])
    def test_ok(self):
        '''Tests a good scenario.'''
        row = [MapSquare(MapSquareTypes.SOIL, (0, 17))]
        database = MemcachedDatabase()
        database.add_square_row(row)

        plant_action = PlantAction()

        robot = Robot("18873.182873.1123", "123")
        robot.set_location((0, 17))

        plant_action.do_action(robot, ["18873.182873.1123"])
    def test_corner(self):
        '''Tests getting a corner of the map.'''
        database = MemcachedDatabase()
        new_robot = Robot("0981kdjieu871", "oie987163")
        new_robot.set_location((0, 1))

        database.add_robot(new_robot, (0, 1))
        database.commit()

        action_manager = ActionManager()
        info = action_manager.do_action(new_robot.get_password(), "sense", [new_robot.get_id()])

        self.assertEqual(len(info), 6)
    def test_blind_point(self):
        '''Gets information of a point, but don't care about the result.'''
        database = MemcachedDatabase()
        new_robot = Robot("1873yudhNCbueio", "ueijdnchiop")
        new_robot.set_location((9, 7))

        database.add_robot(new_robot, (9, 7))
        database.commit()

        action_manager = ActionManager()
        info = action_manager.do_action(new_robot.get_password(), "sense", [new_robot.get_id()])

        self.assertEqual(len(info), 9)
Exemple #17
0
    def test_blind_point(self):
        '''Gets information of a point, but don't care about the result.'''
        database = MemcachedDatabase()
        new_robot = Robot("1873yudhNCbueio", "ueijdnchiop")
        new_robot.set_location((9, 7))

        database.add_robot(new_robot, (9, 7))
        database.commit()

        action_manager = ActionManager()
        info = action_manager.do_action(new_robot.get_password(), "sense",
                                        [new_robot.get_id()])

        self.assertEqual(len(info), 9)
Exemple #18
0
    def test_corner(self):
        '''Tests getting a corner of the map.'''
        database = MemcachedDatabase()
        new_robot = Robot("0981kdjieu871", "oie987163")
        new_robot.set_location((0, 1))

        database.add_robot(new_robot, (0, 1))
        database.commit()

        action_manager = ActionManager()
        info = action_manager.do_action(new_robot.get_password(), "sense",
                                        [new_robot.get_id()])

        self.assertEqual(len(info), 6)
    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 #20
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()
Exemple #21
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()