From 3868fb1e0622e5d3cda0c093ce3114c485fd0096 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 9 Nov 2013 15:45:03 -0600 Subject: simplify the vba-related tests The imports for the emulator-related tests are now simplified in the tests/ folder. The bootstrapping.py file contains some shared functions that multiple test files might choose to use. Those functions probably belong in the actual module instead of in tests/. The battle-related tests have been separated from the other emulator tests. --- tests/test_vba_battle.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/test_vba_battle.py (limited to 'tests/test_vba_battle.py') diff --git a/tests/test_vba_battle.py b/tests/test_vba_battle.py new file mode 100644 index 0000000..6d3b504 --- /dev/null +++ b/tests/test_vba_battle.py @@ -0,0 +1,51 @@ +""" +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 + + def test_battle_is_player_turn(self): + self.cry.vba.state = self.bootstrap_state + + battle = Battle(emulator=self.cry) + + self.assertTrue(battle.is_player_turn()) + +if __name__ == "__main__": + unittest.main() -- cgit v1.2.3 From eb31936aa758a9a8534a3fd53a4987c0d5d9ca0b Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 9 Nov 2013 15:53:17 -0600 Subject: simplify the battle tests --- tests/test_vba_battle.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'tests/test_vba_battle.py') diff --git a/tests/test_vba_battle.py b/tests/test_vba_battle.py index 6d3b504..acf9d7d 100644 --- a/tests/test_vba_battle.py +++ b/tests/test_vba_battle.py @@ -39,13 +39,16 @@ class BattleTests(unittest.TestCase): def setUp(self): # reset to whatever the bootstrapper created self.vba.state = self.bootstrap_state + self.battle = Battle(emulator=self.cry) - def test_battle_is_player_turn(self): - self.cry.vba.state = self.bootstrap_state + def test_is_in_battle(self): + self.assertTrue(self.battle.is_in_battle()) - battle = Battle(emulator=self.cry) + def test_is_player_turn(self): + self.battle.skip_start_text() - self.assertTrue(battle.is_player_turn()) + # the initial state should be the player's turn + self.assertTrue(self.battle.is_player_turn()) if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From d5989b755aeedb3d553d225e29c3b8c7c4d8640f Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 9 Nov 2013 15:59:16 -0600 Subject: write another quick battle test --- tests/test_vba_battle.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/test_vba_battle.py') diff --git a/tests/test_vba_battle.py b/tests/test_vba_battle.py index acf9d7d..12b991c 100644 --- a/tests/test_vba_battle.py +++ b/tests/test_vba_battle.py @@ -46,9 +46,14 @@ class BattleTests(unittest.TestCase): 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()) + if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From 5495504228d9ebb46c9d94a79692b4a2522d2042 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 9 Nov 2013 17:57:23 -0600 Subject: make sure an attack works (new test) --- tests/test_vba_battle.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests/test_vba_battle.py') diff --git a/tests/test_vba_battle.py b/tests/test_vba_battle.py index 12b991c..be62fb5 100644 --- a/tests/test_vba_battle.py +++ b/tests/test_vba_battle.py @@ -55,5 +55,19 @@ class BattleTests(unittest.TestCase): # should not be asking for a switch so soon in the battle self.assertFalse(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() -- cgit v1.2.3 From 1d9ecfa00f91d602073b56a64f9aa129b95a8c2e Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Mon, 11 Nov 2013 00:04:32 -0600 Subject: switch tests to use new battle starter --- tests/test_vba_battle.py | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/test_vba_battle.py') diff --git a/tests/test_vba_battle.py b/tests/test_vba_battle.py index be62fb5..e86b53c 100644 --- a/tests/test_vba_battle.py +++ b/tests/test_vba_battle.py @@ -40,6 +40,7 @@ class BattleTests(unittest.TestCase): # 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()) -- cgit v1.2.3 From 966985411f01b799fa71f4823da7a8cd6d9cc47b Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Mon, 11 Nov 2013 00:55:54 -0600 Subject: detect the "mandatory switch" menu This requires a slightly slower text_wait function. There is probably a way to refactor that function in a way that doesn't cause cancer. --- tests/test_vba_battle.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/test_vba_battle.py') diff --git a/tests/test_vba_battle.py b/tests/test_vba_battle.py index e86b53c..61c0297 100644 --- a/tests/test_vba_battle.py +++ b/tests/test_vba_battle.py @@ -56,6 +56,25 @@ class BattleTests(unittest.TestCase): # 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() -- cgit v1.2.3 From e61643e6814d49c4244c49fa561745dc3fc3e80a Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Mon, 11 Nov 2013 21:33:14 -0600 Subject: use set_battle_mon_hp in a test --- tests/test_vba_battle.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests/test_vba_battle.py') diff --git a/tests/test_vba_battle.py b/tests/test_vba_battle.py index 61c0297..8b02cef 100644 --- a/tests/test_vba_battle.py +++ b/tests/test_vba_battle.py @@ -67,8 +67,7 @@ class BattleTests(unittest.TestCase): 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) + self.cry.set_battle_mon_hp(1) # let the enemy attack and kill the pokemon self.battle.skip_until_input_required() -- cgit v1.2.3 From ba6eb203b4afef6179d30a13f6f4037349d79272 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Mon, 11 Nov 2013 21:48:29 -0600 Subject: a test for detecting the yes/no prompt --- tests/test_vba_battle.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests/test_vba_battle.py') diff --git a/tests/test_vba_battle.py b/tests/test_vba_battle.py index 8b02cef..8299bea 100644 --- a/tests/test_vba_battle.py +++ b/tests/test_vba_battle.py @@ -88,5 +88,30 @@ class BattleTests(unittest.TestCase): self.assertTrue(self.battle.is_player_turn()) + def test_is_battle_switch_prompt(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 enemy hp to very low + self.cry.lower_enemy_hp() + + # attack the enemy and kill it + self.battle.skip_until_input_required() + + import time + time.sleep(1) + + # yes/no menu is present, should be detected + self.assertTrue(self.battle.is_switch_prompt()) + + # but it's not mandatory + self.assertFalse(self.battle.is_mandatory_switch()) + if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From 993eaa34517c271f3e076744f96aa479008fdf16 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Mon, 11 Nov 2013 21:52:33 -0600 Subject: fix the is_switch_prompt test --- tests/test_vba_battle.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/test_vba_battle.py') diff --git a/tests/test_vba_battle.py b/tests/test_vba_battle.py index 8299bea..a0338e5 100644 --- a/tests/test_vba_battle.py +++ b/tests/test_vba_battle.py @@ -104,12 +104,12 @@ class BattleTests(unittest.TestCase): # attack the enemy and kill it self.battle.skip_until_input_required() - import time - time.sleep(1) - # yes/no menu is present, should be detected self.assertTrue(self.battle.is_switch_prompt()) + # and input should be required + self.assertTrue(self.is_input_required()) + # but it's not mandatory self.assertFalse(self.battle.is_mandatory_switch()) -- cgit v1.2.3 From d9bb01f2c0aef6d270bc4e2da93af94ea210e8db Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Mon, 11 Nov 2013 21:56:34 -0600 Subject: rename the switch prompt detector --- tests/test_vba_battle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_vba_battle.py') diff --git a/tests/test_vba_battle.py b/tests/test_vba_battle.py index a0338e5..0faa26e 100644 --- a/tests/test_vba_battle.py +++ b/tests/test_vba_battle.py @@ -105,7 +105,7 @@ class BattleTests(unittest.TestCase): self.battle.skip_until_input_required() # yes/no menu is present, should be detected - self.assertTrue(self.battle.is_switch_prompt()) + self.assertTrue(self.battle.is_trainer_switch_prompt()) # and input should be required self.assertTrue(self.is_input_required()) -- cgit v1.2.3 From 2ff3478bfda330fbc379f5278a6d37d7065dd9df Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Mon, 11 Nov 2013 21:57:08 -0600 Subject: fix a typo in the switch prompt test --- tests/test_vba_battle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_vba_battle.py') diff --git a/tests/test_vba_battle.py b/tests/test_vba_battle.py index 0faa26e..c6debc3 100644 --- a/tests/test_vba_battle.py +++ b/tests/test_vba_battle.py @@ -108,7 +108,7 @@ class BattleTests(unittest.TestCase): self.assertTrue(self.battle.is_trainer_switch_prompt()) # and input should be required - self.assertTrue(self.is_input_required()) + self.assertTrue(self.battle.is_input_required()) # but it's not mandatory self.assertFalse(self.battle.is_mandatory_switch()) -- cgit v1.2.3