Beispiel #1
0
    def test_player(self):
        ###########################################################################
        # Change to raising handler for unit-testing
        set_prequire_handler(raising_prequire_handler)

        Configuration._create()
        player = Player()
        spell = "hot"

        exp_needed = player.next_level_cost() - player.exp()

        self.assertRaises(ProgramError, player.gain_exp, exp_needed)

        grant_access(self, Player.ALLOW_GAIN_EXP)
        player.gain_exp(exp_needed)
        self.assertEqual(player.level(), 2)

        from spell_factory import SpellFactory

        hot_spell_1 = SpellFactory.create_spell(spell, 1)

        # TODO - Uncomment once Talents are implemented
        #self.assertRaises(UserError, player.verify_cast, hot_spell_1)

        self.assertRaises(ProgramError, player.learn, spell)
        grant_access(self, Player.ALLOW_LEARN)
        player.learn(spell)

        player.verify_cast(hot_spell_1)

        self.assertRaises(ProgramError, player.cast, hot_spell_1)
        grant_access(self, Player.ALLOW_CAST)
        player.cast(hot_spell_1)

        self.assertEqual(player.mana(), player.max_mana() - hot_spell_1.cost())
Beispiel #2
0
    def test_talents(self):
    ###########################################################################
        from player import Player
        from configuration import Configuration

        Configuration._create()
        player = Player()
        talents = Talents(player)
        tier1_spell_name = "hot"
        another_tier1_spell_name = "cold"
        tier2_spell_name = "fire"
        high_tier_spell_name = "quake"
        not_a_spell = "lol"

        # Give ourselves ability to add exp to player
        grant_access(self, Player.ALLOW_GAIN_EXP)

        # Get player up to level 10
        for i in xrange(9):
            exp_needed = player.next_level_cost() - player.exp()
            player.gain_exp(exp_needed)

        self.assertEqual(player.level(), 10)

        # Should not be able to learn fire 1 (don't know hot 1)
        self.assertRaises(UserError, talents.add, tier2_spell_name)

        # Should not be able to learn quake 1 (not high enough level)
        self.assertRaises(UserError, talents.add, high_tier_spell_name)

        # Should not be able to learn an invalid spell
        self.assertRaises(UserError, talents.add, not_a_spell)

        # Learn hot up to max
        for i in xrange(talents._MAX_SPELL_LEVEL):
            talents.add(tier1_spell_name)

        # Should not be able to learn tier1 spell again, maxed out
        self.assertRaises(UserError, talents.add, tier1_spell_name)

        # Should be able to learn fire now
        for i in xrange(talents._MAX_SPELL_LEVEL):
            talents.add(tier2_spell_name)

        # Should not be able to learn a different tier1 spell, out of points
        self.assertRaises(UserError, talents.add, another_tier1_spell_name)

        # Check iteration
        known_spells = []
        for spell_spec in talents:
            known_spells.append(spell_spec)

        # Check that we know the spells we've learned
        for spell_name in [tier1_spell_name, tier2_spell_name]:
            for spell_level in xrange(1, talents._MAX_SPELL_LEVEL):
                self.assertIn( (spell_name, spell_level), talents )
                #self.assertIn( (spell_name, spell_level), known_spells )

        self.assertEqual(len(known_spells), 2)
Beispiel #3
0
    def test_world(self):
    ###########################################################################
        from configuration import Configuration
        from world_factory import create_world

        Configuration._create()

        world = create_world()

        grant_access(self, World.ALLOW_CYCLE_TURN)

        # Test cycle turn
        time1_val = int(world.time().season())
        world.cycle_turn()
        time2 = world.time()
        self.assertEqual(time1_val + 1, int(time2.season()))
Beispiel #4
0
    def test_engine(self):
        ###########################################################################
        # Change to raising handler for unit-testing
        set_prequire_handler(raising_prequire_handler)

        # Test that we cannot create instances of Engine
        self.assertRaises(ProgramError, Engine)

        # Create configuration
        from interface import Interfaces
        config = Configuration._create(interface_config=str(Interfaces.TEXT),
                                       world_config="1")

        # Grab global instance
        eng = engine()

        # Integration test
        self.assertEqual(eng.ai_player().population(), 1000)
Beispiel #5
0
 def test_interface(self):
     ###########################################################################
     # Test create_interface
     Configuration._create(interface_config=str(Interfaces.TEXT))
     interface = create_interface()
     self.assertEqual(type(interface), TextInterface)
Beispiel #6
0
    def test_world_factory(self):
        ###########################################################################
        Configuration._create()

        create_world()