diff options
author | Bryan Bishop <kanzure@gmail.com> | 2013-11-11 12:38:52 -0600 |
---|---|---|
committer | Bryan Bishop <kanzure@gmail.com> | 2013-11-11 12:38:52 -0600 |
commit | e0991710ef720ee73bc8042671ba92159002f236 (patch) | |
tree | f8cdf8595411ad8b16eca1f293a1c3e724eef45c /tests/test_vba_battle.py | |
parent | fcfde94ba84a6a29bb22dd97b62af2e3c72276bd (diff) | |
parent | a11b084a2824dbe9c1df84d9ea205b8495f3da13 (diff) |
Merge branch 'github/master' into master
Diffstat (limited to 'tests/test_vba_battle.py')
-rw-r--r-- | tests/test_vba_battle.py | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/test_vba_battle.py b/tests/test_vba_battle.py new file mode 100644 index 0000000..61c0297 --- /dev/null +++ b/tests/test_vba_battle.py @@ -0,0 +1,93 @@ +""" +Tests for the battle controller +""" + +import unittest + +from setup_vba import ( + vba, + autoplayer, +) + +from pokemontools.vba.battle import ( + Battle, + BattleException, +) + +from bootstrapping import ( + bootstrap, + bootstrap_trainer_battle, +) + +class BattleTests(unittest.TestCase): + cry = None + vba = None + bootstrap_state = None + + @classmethod + def setUpClass(cls): + cls.cry = vba.crystal() + cls.vba = cls.cry.vba + + cls.bootstrap_state = bootstrap_trainer_battle() + cls.vba.state = cls.bootstrap_state + + @classmethod + def tearDownClass(cls): + cls.vba.shutdown() + + def setUp(self): + # reset to whatever the bootstrapper created + self.vba.state = self.bootstrap_state + self.battle = Battle(emulator=self.cry) + self.battle.skip_start_text() + + def test_is_in_battle(self): + self.assertTrue(self.battle.is_in_battle()) + + def test_is_player_turn(self): + self.battle.skip_start_text() + self.battle.skip_until_input_required() + + # the initial state should be the player's turn + self.assertTrue(self.battle.is_player_turn()) + + def test_is_mandatory_switch_initial(self): + # should not be asking for a switch so soon in the battle + self.assertFalse(self.battle.is_mandatory_switch()) + + def test_is_mandatory_switch(self): + self.battle.skip_start_text() + self.battle.skip_until_input_required() + + # press "FIGHT" + self.vba.press(["a"], after=20) + + # press the first move ("SCRATCH") + self.vba.press(["a"], after=20) + + # set partymon1 hp to very low + self.vba.write_memory_at(0xc63c, 0) + self.vba.write_memory_at(0xc63d, 1) + + # let the enemy attack and kill the pokemon + self.battle.skip_until_input_required() + + self.assertTrue(self.battle.is_mandatory_switch()) + + def test_attack_loop(self): + self.battle.skip_start_text() + self.battle.skip_until_input_required() + + # press "FIGHT" + self.vba.press(["a"], after=20) + + # press the first move ("SCRATCH") + self.vba.press(["a"], after=20) + + self.battle.skip_until_input_required() + + self.assertTrue(self.battle.is_player_turn()) + +if __name__ == "__main__": + unittest.main() |