Skip to content

Commit

Permalink
Added proper tests to the battle_creature object to get 100% coverage…
Browse files Browse the repository at this point in the history
… of branches in that class
  • Loading branch information
DaveTCode committed Jul 14, 2017
1 parent 8dacf96 commit 74ce2bf
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CreatureRogue/models/battle_creature.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ def modified_catch_rate(self, pokeball: Pokeball) -> float:
return (triple_max_hp - 2 * self.stat_value(hp_stat)) * self.creature.species.capture_rate * pokeball.catch_rate / triple_max_hp

def __str__(self):
return str(self.creature)
return str(self.creature)
51 changes: 49 additions & 2 deletions tests/models/battle_creature_test.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,63 @@
import CreatureRogue.creature_creator as creature_creator
import CreatureRogue.settings as settings
from CreatureRogue.data_layer.data import ATTACK_STAT
from CreatureRogue.data_layer.db_layer import Loader
from CreatureRogue.models.creature import Creature
from CreatureRogue.models.battle_creature import BattleCreature


loader = Loader(settings.DB_FILE)
static_game_data = loader.load_static_data()


def test_string_blank_name():
loader = Loader(settings.DB_FILE)
static_game_data = loader.load_static_data()
creature = Creature(species=static_game_data.species[1], level=1, nickname=None, trainer=None,
individual_values=creature_creator.random_stat_values(static_game_data.stats, 1, 15),
effort_values=creature_creator.zero_stat_values(static_game_data.stats),
current_xp=1, was_traded=False, moves=[])
battle_creature = BattleCreature(creature=creature, static_game_data=static_game_data)
assert "Wild Bulbasaur" == str(battle_creature)


def test_stat_value_function():
creature = Creature(species=static_game_data.species[1], level=1, nickname=None, trainer=None,
individual_values=creature_creator.random_stat_values(static_game_data.stats, 1, 15),
effort_values=creature_creator.zero_stat_values(static_game_data.stats),
current_xp=1, was_traded=False, moves=[])
battle_creature = BattleCreature(creature=creature, static_game_data=static_game_data)
assert 6.0 == battle_creature.stat_value(static_game_data.stats[ATTACK_STAT])
battle_creature.adjust_stat_adjusts(static_game_data.stats[ATTACK_STAT], 1)
assert 6.0 * 1.5 == battle_creature.stat_value(static_game_data.stats[ATTACK_STAT]) # Multiply default by 1.5


def test_stat_value_positive_capping():
creature = Creature(species=static_game_data.species[1], level=1, nickname=None, trainer=None,
individual_values=creature_creator.random_stat_values(static_game_data.stats, 1, 15),
effort_values=creature_creator.zero_stat_values(static_game_data.stats),
current_xp=1, was_traded=False, moves=[])
battle_creature = BattleCreature(creature=creature, static_game_data=static_game_data)
battle_creature.adjust_stat_adjusts(static_game_data.stats[ATTACK_STAT], 6)
assert 6.0 * 4.0 == battle_creature.stat_value(static_game_data.stats[ATTACK_STAT])
assert 0 == battle_creature.adjust_stat_adjusts(static_game_data.stats[ATTACK_STAT], 1)
assert 6.0 * 4.0 == battle_creature.stat_value(static_game_data.stats[ATTACK_STAT]) # Should still be the same


def test_stat_value_negative_capping():
creature = Creature(species=static_game_data.species[1], level=1, nickname=None, trainer=None,
individual_values=creature_creator.random_stat_values(static_game_data.stats, 1, 15),
effort_values=creature_creator.zero_stat_values(static_game_data.stats),
current_xp=1, was_traded=False, moves=[])
battle_creature = BattleCreature(creature=creature, static_game_data=static_game_data)
battle_creature.adjust_stat_adjusts(static_game_data.stats[ATTACK_STAT], -6)
assert 6.0 / 4.0 == battle_creature.stat_value(static_game_data.stats[ATTACK_STAT])
assert 0 == battle_creature.adjust_stat_adjusts(static_game_data.stats[ATTACK_STAT], -1)
assert 6.0 / 4.0 == battle_creature.stat_value(static_game_data.stats[ATTACK_STAT]) # Should still be the same


def test_modified_catch_rate():
creature = Creature(species=static_game_data.species[1], level=1, nickname=None, trainer=None,
individual_values=creature_creator.random_stat_values(static_game_data.stats, 1, 15),
effort_values=creature_creator.zero_stat_values(static_game_data.stats),
current_xp=1, was_traded=False, moves=[])
battle_creature = BattleCreature(creature=creature, static_game_data=static_game_data)
assert 15.0 == battle_creature.modified_catch_rate(static_game_data.pokeballs[1])

0 comments on commit 74ce2bf

Please sign in to comment.