Esempio n. 1
0
    def setup(self):
        """
        Setup the test case
        """
        self.rng = random.Random()
        self.level = Level((60, 40))
        self.level.set_location_type((10, 10), 'room')

        creature_config = CreatureConfigurations(self.rng)
        creature_config.add_creature(
                        CreatureConfiguration(name = 'rat',
                                              body = 4,
                                              finesse = 12,
                                              mind = 2,
                                              hp = 2,
                                              speed = 2,
                                              icons = 1,
                                              attack = 2,
                                              ai = None))

        creature_config.add_creature(
                        CreatureConfiguration(name = 'dragon',
                                              body = 4,
                                              finesse = 12,
                                              mind = 2,
                                              hp = 2,
                                              speed = 2,
                                              icons = 1,
                                              attack = 2,
                                              ai = None))

        self.mock_action_factory = mock()
        self.model = mock()
        self.creature_generator = CreatureGenerator(creature_config,
                                                    self.model,
                                                    self.mock_action_factory,
                                                    self.rng)

        self.configuration = CreatureAdderConfiguration(['crypt'])
        self.configuration.add_creature(min_amount = 3,
                                        max_amount = 4,
                                        name = 'rat')
        self.configuration.add_creature(min_amount = 1,
                                        max_amount = 1,
                                        name = 'dragon',
                                        location = 'room')
        self.creature_adder = CreatureAdder(self.creature_generator,
                                            self.configuration,
                                            self.rng)

        self.creature_adder.add_creatures(self.level)
Esempio n. 2
0
class TestCreatureAdder():
    """
    Tests for CreatureAdder
    """
    def __init__(self):
        """
        Default constructor
        """
        self.rng = None
        self.level = None
        self.mock_action_factory = None
        self.creature_generator = None
        self.configuration = None
        self.creature_adder = None

    def setup(self):
        """
        Setup the test case
        """
        self.rng = random.Random()
        self.level = Level((60, 40))
        self.level.set_location_type((10, 10), 'room')

        creature_config = CreatureConfigurations(self.rng)
        creature_config.add_creature(
                        CreatureConfiguration(name = 'rat',
                                              body = 4,
                                              finesse = 12,
                                              mind = 2,
                                              hp = 2,
                                              speed = 2,
                                              icons = 1,
                                              attack = 2,
                                              ai = None))

        creature_config.add_creature(
                        CreatureConfiguration(name = 'dragon',
                                              body = 4,
                                              finesse = 12,
                                              mind = 2,
                                              hp = 2,
                                              speed = 2,
                                              icons = 1,
                                              attack = 2,
                                              ai = None))

        self.mock_action_factory = mock()
        self.model = mock()
        self.creature_generator = CreatureGenerator(creature_config,
                                                    self.model,
                                                    self.mock_action_factory,
                                                    self.rng)

        self.configuration = CreatureAdderConfiguration(['crypt'])
        self.configuration.add_creature(min_amount = 3,
                                        max_amount = 4,
                                        name = 'rat')
        self.configuration.add_creature(min_amount = 1,
                                        max_amount = 1,
                                        name = 'dragon',
                                        location = 'room')
        self.creature_adder = CreatureAdder(self.creature_generator,
                                            self.configuration,
                                            self.rng)

        self.creature_adder.add_creatures(self.level)

    def test_adding_creatures(self):
        """
        Test basic case of adding creatures on the level
        """
        assert_that(self.level.creatures, has_length(greater_than(3)))
        assert_that(self.level.creatures, has_length(less_than(6)))

        assert_that(self.level, has_creature('rat',
                                             greater_than_or_equal_to(3)))
        assert_that(self.level, has_creature('dragon', 1))

    def test_adding_to_location(self):
        """
        Test that CreatureAdder will use location types passed to it
        """
        dragon = [x for x in self.level.creatures
                  if x.name == 'dragon'][0]

        location = dragon.location

        assert_that(located_in_room(dragon))