From f0e75972a119812ec37ec27fcdcd00afc45edf98 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 21 Sep 2013 23:14:58 -0500 Subject: move tests into test_vba.py They didn't belong in pokemontools/vba/vba.py in the first place. --- tests/test_vba.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index 56a71e3..12dd51b 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -102,5 +102,35 @@ class VbaTests(unittest.TestCase): player_action = self.get_wram_value("PlayerAction") self.assertEqual(player_action, 1) # 1 = standing +class TestEmulator(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.cry = crystal() + + # advance it forward past the intro sequences + cls.cry.vba.step(count=3500) + + def test_PlaceString(self): + self.cry.call(0, 0x1078) + + # where to draw the text + self.cry.registers["hl"] = 0xc4a0 + + # what text to read from + self.cry.registers["de"] = 0x1276 + + self.cry.vba.step(count=10) + + text = self.cry.get_text() + + self.assertTrue("TRAINER" in text) + + def test_keyboard_planner(self): + button_sequence = keyboard.plan_typing("an") + expected_result = ["select", "a", "d", "r", "r", "r", "r", "a"] + + self.assertEqual(len(expected_result), len(button_sequence)) + self.assertEqual(expected_result, button_sequence) + if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From 713c4ceb7736c620cb1626745d0c5bbfec3e22b1 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 22 Sep 2013 00:10:07 -0500 Subject: fix the autoplayer bootstrapper for test_vba.py --- tests/test_vba.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index 12dd51b..d11108d 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -7,11 +7,11 @@ import unittest import pokemontools.vba.vba as vba try: - import pokemontools.vba.vba_autoplayer + import pokemontools.vba.vba_autoplayer as autoplayer except ImportError: - import pokemontools.vba.autoplayer as vba_autoplayer + import pokemontools.vba.autoplayer as autoplayer -vba_autoplayer.vba = vba +autoplayer.vba = vba def setup_wram(): """ @@ -31,18 +31,17 @@ def bootstrap(): is constructed by this function. """ - # reset the rom - vba.shutdown() - vba.load_rom() + cry = vba.crystal() + runner = autoplayer.SpeedRunner(cry=cry) # skip=False means run the skip_intro function instead of just skipping to # a saved state. - vba_autoplayer.skip_intro() + runner.skip_intro() - state = vba.get_state() + state = cry.get_state() # clean everything up again - vba.shutdown() + cry.vba.shutdown() return state -- cgit v1.2.3 From 2614df2587f3ccd9ea3cdf9604c0025f5113507b Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 22 Sep 2013 01:02:56 -0500 Subject: use the state property during test bootstrapping --- tests/test_vba.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index d11108d..1d185fa 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -31,14 +31,14 @@ def bootstrap(): is constructed by this function. """ - cry = vba.crystal() + cry = vba.crystal(config=None) runner = autoplayer.SpeedRunner(cry=cry) # skip=False means run the skip_intro function instead of just skipping to # a saved state. runner.skip_intro() - state = cry.get_state() + state = cry.vba.state # clean everything up again cry.vba.shutdown() -- cgit v1.2.3 From 5aa423ee6294cfba1f4b98d1a8720da909346436 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 22 Sep 2013 01:55:26 -0500 Subject: make the vba tests pass --- tests/test_vba.py | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index 1d185fa..fcd5c61 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -11,6 +11,8 @@ try: except ImportError: import pokemontools.vba.autoplayer as autoplayer +import pokemontools.vba.keyboard as keyboard + autoplayer.vba = vba def setup_wram(): @@ -36,7 +38,7 @@ def bootstrap(): # skip=False means run the skip_intro function instead of just skipping to # a saved state. - runner.skip_intro() + runner.skip_intro(skip=True) state = cry.vba.state @@ -56,28 +58,40 @@ class VbaTests(unittest.TestCase): # # figure out addresses # cls.wram = setup_wram() - # FIXME: work around jython2.5 unittest - state = bootstrap() - wram = setup_wram() + cry = None + wram = None + + @classmethod + def setUpClass(cls): + cls.bootstrap_state = bootstrap() + + cls.wram = setup_wram() + + cls.cry = vba.crystal() + cls.vba = cls.cry.vba + + cls.vba.state = cls.bootstrap_state def get_wram_value(self, name): - return vba.get_memory_at(self.wram[name]) + return self.vba.memory[self.wram[name]] def setUp(self): - # clean the state - vba.shutdown() - vba.load_rom() + #if self.cry: + # # clean up the emulator's state + # self.cry.shutdown() + #self.cry = vba.crystal() + #self.vba = self.cry.vba # reset to whatever the bootstrapper created - vba.set_state(self.state) + self.vba.state = self.bootstrap_state - def tearDown(self): - vba.shutdown() + #def tearDown(self): + # self.vba.shutdown() def test_movement_changes_player_direction(self): player_direction = self.get_wram_value("PlayerDirection") - vba.crystal.move("u") + self.cry.move("u") # direction should have changed self.assertNotEqual(player_direction, self.get_wram_value("PlayerDirection")) @@ -85,7 +99,7 @@ class VbaTests(unittest.TestCase): def test_movement_changes_y_coord(self): first_map_y = self.get_wram_value("MapY") - vba.crystal.move("u") + self.cry.move("u") # y location should be different second_map_y = self.get_wram_value("MapY") @@ -95,7 +109,7 @@ class VbaTests(unittest.TestCase): # should start with standing self.assertEqual(self.get_wram_value("PlayerAction"), 1) - vba.crystal.move("l") + self.cry.move("l") # should be standing player_action = self.get_wram_value("PlayerAction") @@ -104,7 +118,7 @@ class VbaTests(unittest.TestCase): class TestEmulator(unittest.TestCase): @classmethod def setUpClass(cls): - cls.cry = crystal() + cls.cry = vba.crystal() # advance it forward past the intro sequences cls.cry.vba.step(count=3500) -- cgit v1.2.3 From f52f6148d775e51a9cb68201effef905c0880c75 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 22 Sep 2013 02:06:38 -0500 Subject: combine some tests together --- tests/test_vba.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index fcd5c61..3a2de72 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -47,6 +47,14 @@ def bootstrap(): return state +class OtherVbaTests(unittest.TestCase): + def test_keyboard_planner(self): + button_sequence = keyboard.plan_typing("an") + expected_result = ["select", "a", "d", "r", "r", "r", "r", "a"] + + self.assertEqual(len(expected_result), len(button_sequence)) + self.assertEqual(expected_result, button_sequence) + class VbaTests(unittest.TestCase): # unittest in jython2.5 doesn't seem to have setUpClass ?? Man, why am I on # jython2.5? This is ancient. @@ -115,14 +123,6 @@ class VbaTests(unittest.TestCase): player_action = self.get_wram_value("PlayerAction") self.assertEqual(player_action, 1) # 1 = standing -class TestEmulator(unittest.TestCase): - @classmethod - def setUpClass(cls): - cls.cry = vba.crystal() - - # advance it forward past the intro sequences - cls.cry.vba.step(count=3500) - def test_PlaceString(self): self.cry.call(0, 0x1078) @@ -138,12 +138,5 @@ class TestEmulator(unittest.TestCase): self.assertTrue("TRAINER" in text) - def test_keyboard_planner(self): - button_sequence = keyboard.plan_typing("an") - expected_result = ["select", "a", "d", "r", "r", "r", "r", "a"] - - self.assertEqual(len(expected_result), len(button_sequence)) - self.assertEqual(expected_result, button_sequence) - if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From ffad17245b4b2ffa33a97fde0bd51bd643fc1faa Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 22 Sep 2013 02:07:43 -0500 Subject: remove old jython comments from the vba tests --- tests/test_vba.py | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index 3a2de72..1b151b7 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -56,16 +56,6 @@ class OtherVbaTests(unittest.TestCase): self.assertEqual(expected_result, button_sequence) class VbaTests(unittest.TestCase): - # unittest in jython2.5 doesn't seem to have setUpClass ?? Man, why am I on - # jython2.5? This is ancient. - #@classmethod - #def setUpClass(cls): - # # get a good game state - # cls.state = bootstrap() - # - # # figure out addresses - # cls.wram = setup_wram() - cry = None wram = None @@ -80,21 +70,16 @@ class VbaTests(unittest.TestCase): cls.vba.state = cls.bootstrap_state - def get_wram_value(self, name): - return self.vba.memory[self.wram[name]] + @classmethod + def tearDownClass(cls): + cls.vba.shutdown() def setUp(self): - #if self.cry: - # # clean up the emulator's state - # self.cry.shutdown() - #self.cry = vba.crystal() - #self.vba = self.cry.vba - # reset to whatever the bootstrapper created self.vba.state = self.bootstrap_state - #def tearDown(self): - # self.vba.shutdown() + def get_wram_value(self, name): + return self.vba.memory[self.wram[name]] def test_movement_changes_player_direction(self): player_direction = self.get_wram_value("PlayerDirection") -- cgit v1.2.3 From 80cda61ec4478db3253741bc32beae0f6edd5b78 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 22 Sep 2013 02:17:02 -0500 Subject: test autoplayer handle_mom --- tests/test_vba.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index 1b151b7..ec74a55 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -123,5 +123,24 @@ class VbaTests(unittest.TestCase): self.assertTrue("TRAINER" in text) + def test_speedrunner_constructor(self): + runner = autoplayer.SpeedRunner(cry=self.cry) + + def test_speedrunner_handle_mom(self): + self.vba.shutdown() + + # TODO: why can't i pass in the current state of the emulator? + runner = autoplayer.SpeedRunner(cry=None) + runner.setup() + runner.skip_intro(skip=True) + runner.handle_mom(skip=False) + + # confirm that handle_mom is done by attempting to move on the map + first_map_y = self.get_wram_value("MapY") + runner.cry.move("d") + second_map_y = self.get_wram_value("MapY") + + self.assertNotEqual(first_map_y, second_map_y) + if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From 3e0a674817cd4345c9b20d910ee81db406717234 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 22 Sep 2013 02:21:08 -0500 Subject: test the walk_into_new_bark_town vba method --- tests/test_vba.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index ec74a55..e9ff73c 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -142,5 +142,21 @@ class VbaTests(unittest.TestCase): self.assertNotEqual(first_map_y, second_map_y) + def test_speedrunner_walk_into_new_bark_town(self): + runner = autoplayer.SpeedRunner(cry=None) + runner.setup() + runner.skip_intro(skip=True) + runner.handle_mom(skip=True) + runner.walk_into_new_bark_town(skip=False) + + # test again if the game is in a state where the player can walk + first_map_y = self.get_wram_value("MapY") + runner.cry.move("d") + second_map_y = self.get_wram_value("MapY") + + self.assertNotEqual(first_map_y, second_map_y) + + # TODO: test the current map id against what it should be + if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From 57dc8c4fd0b14e4cca190061c47993e1231a931d Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 22 Sep 2013 02:27:57 -0500 Subject: add more defaults to setup_wram for testing This is sorta absurd, it should just load these values by parsing wram.asm on its own. --- tests/test_vba.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index e9ff73c..5098a7d 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -20,11 +20,19 @@ def setup_wram(): Loads up some default addresses. Should eventually be replaced with the actual wram parser. """ + # TODO: this should just be parsed straight out of wram.asm wram = {} wram["PlayerDirection"] = 0xd4de wram["PlayerAction"] = 0xd4e1 wram["MapX"] = 0xd4e6 wram["MapY"] = 0xd4e7 + + wram["WarpNumber"] = 0xdcb4 + wram["MapGroup"] = 0xdcb5 + wram["MapNumber"] = 0xdcb6 + wram["YCoord"] = 0xdcb7 + wram["XCoord"] = 0xdcb8 + return wram def bootstrap(): -- cgit v1.2.3 From 7d3994ae753d3fa208401afbab6678328d6ecc8e Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 22 Sep 2013 02:33:02 -0500 Subject: test that the current map is correct --- tests/test_vba.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index 5098a7d..9f7b8f1 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -162,9 +162,12 @@ class VbaTests(unittest.TestCase): runner.cry.move("d") second_map_y = self.get_wram_value("MapY") + # check that the player has moved self.assertNotEqual(first_map_y, second_map_y) - # TODO: test the current map id against what it should be + # check that the map is correct + self.assertEqual(self.get_wram_value("MapGroup"), 24) + self.assertEqual(self.get_wram_value("MapNumber"), 4) if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From 742bdf8c2fffccf1c216f08192693dab7241a597 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 22 Sep 2013 02:48:41 -0500 Subject: test that the Elm's Lab sequence works --- tests/test_vba.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index 9f7b8f1..55489fb 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -169,5 +169,29 @@ class VbaTests(unittest.TestCase): self.assertEqual(self.get_wram_value("MapGroup"), 24) self.assertEqual(self.get_wram_value("MapNumber"), 4) + def test_speedrunner_handle_elm(self): + self.vba.shutdown() + + runner = autoplayer.SpeedRunner(cry=None) + runner.setup() + runner.skip_intro(skip=True) + runner.handle_mom(skip=True) + runner.walk_into_new_bark_town(skip=False) + + # go through the Elm's Lab sequence + runner.handle_elm("cyndaquil", skip=False) + + # test again if the game is in a state where the player can walk + first_map_y = self.get_wram_value("MapY") + runner.cry.move("d") + second_map_y = self.get_wram_value("MapY") + + # check that the player has moved + self.assertNotEqual(first_map_y, second_map_y) + + # check that the map is correct + self.assertEqual(self.get_wram_value("MapGroup"), 24) + self.assertEqual(self.get_wram_value("MapNumber"), 5) + if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From 840e447557548b67d0c6436949d86c789f0e8fe9 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 22 Sep 2013 02:55:08 -0500 Subject: change the walk test after Elm's Lab The walk test is useful to see if the player is able to move, but it shouldn't walk down and out of the building because the test is comparing against the MapNumber for Elm's Lab and not New Bark Town. --- tests/test_vba.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index 55489fb..0232b1d 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -183,7 +183,7 @@ class VbaTests(unittest.TestCase): # test again if the game is in a state where the player can walk first_map_y = self.get_wram_value("MapY") - runner.cry.move("d") + runner.cry.move("u") second_map_y = self.get_wram_value("MapY") # check that the player has moved -- cgit v1.2.3 From 3151acd42c6f7f448499b6cdf20a603ff7c150e8 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 22 Sep 2013 02:58:25 -0500 Subject: remove unnecessary emulator shutdown --- tests/test_vba.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index 0232b1d..9a772cd 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -170,8 +170,6 @@ class VbaTests(unittest.TestCase): self.assertEqual(self.get_wram_value("MapNumber"), 4) def test_speedrunner_handle_elm(self): - self.vba.shutdown() - runner = autoplayer.SpeedRunner(cry=None) runner.setup() runner.skip_intro(skip=True) -- cgit v1.2.3 From 1d92396ca92d25cf19bdf47ce467e467e8638d08 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 22 Sep 2013 10:10:46 -0500 Subject: reduce some duplicated code inside some tests Those movement checks are now collapsed into a single function that each test can individually call. --- tests/test_vba.py | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index 9a772cd..f82576b 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -89,6 +89,16 @@ class VbaTests(unittest.TestCase): def get_wram_value(self, name): return self.vba.memory[self.wram[name]] + def check_movement(self, direction="d"): + """ + Check if (y, x) before attempting to move and (y, x) after attempting + to move are the same. + """ + start = (self.get_wram_value("MapY"), self.get_wram_value("MapX")) + self.cry.move(direction) + end = (self.get_wram_value("MapY"), self.get_wram_value("MapX")) + return start != end + def test_movement_changes_player_direction(self): player_direction = self.get_wram_value("PlayerDirection") @@ -144,11 +154,7 @@ class VbaTests(unittest.TestCase): runner.handle_mom(skip=False) # confirm that handle_mom is done by attempting to move on the map - first_map_y = self.get_wram_value("MapY") - runner.cry.move("d") - second_map_y = self.get_wram_value("MapY") - - self.assertNotEqual(first_map_y, second_map_y) + self.assertTrue(self.check_movement("d")) def test_speedrunner_walk_into_new_bark_town(self): runner = autoplayer.SpeedRunner(cry=None) @@ -157,13 +163,8 @@ class VbaTests(unittest.TestCase): runner.handle_mom(skip=True) runner.walk_into_new_bark_town(skip=False) - # test again if the game is in a state where the player can walk - first_map_y = self.get_wram_value("MapY") - runner.cry.move("d") - second_map_y = self.get_wram_value("MapY") - - # check that the player has moved - self.assertNotEqual(first_map_y, second_map_y) + # test that the game is in a state such that the player can walk + self.assertTrue(self.check_movement("d")) # check that the map is correct self.assertEqual(self.get_wram_value("MapGroup"), 24) @@ -180,12 +181,7 @@ class VbaTests(unittest.TestCase): runner.handle_elm("cyndaquil", skip=False) # test again if the game is in a state where the player can walk - first_map_y = self.get_wram_value("MapY") - runner.cry.move("u") - second_map_y = self.get_wram_value("MapY") - - # check that the player has moved - self.assertNotEqual(first_map_y, second_map_y) + self.assertTrue(self.check_movement("u")) # check that the map is correct self.assertEqual(self.get_wram_value("MapGroup"), 24) -- cgit v1.2.3 From 13a1da5e84364435895d43b96cc5c821227dc688 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 22 Sep 2013 10:14:17 -0500 Subject: remove vba.shutdown() from another test --- tests/test_vba.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index f82576b..a2a17d6 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -145,8 +145,6 @@ class VbaTests(unittest.TestCase): runner = autoplayer.SpeedRunner(cry=self.cry) def test_speedrunner_handle_mom(self): - self.vba.shutdown() - # TODO: why can't i pass in the current state of the emulator? runner = autoplayer.SpeedRunner(cry=None) runner.setup() -- cgit v1.2.3 From c1fbb59696876011be7fff57986e8e97f15ece35 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 22 Sep 2013 10:21:09 -0500 Subject: a test for moving in circles Well, it's more like a square. --- tests/test_vba.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index a2a17d6..787a151 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -185,5 +185,32 @@ class VbaTests(unittest.TestCase): self.assertEqual(self.get_wram_value("MapGroup"), 24) self.assertEqual(self.get_wram_value("MapNumber"), 5) + def test_moving_back_and_forth(self): + runner = autoplayer.SpeedRunner(cry=None) + runner.setup() + runner.skip_intro(skip=True) + runner.handle_mom(skip=True) + runner.walk_into_new_bark_town(skip=False) + + # must be in New Bark Town + self.assertEqual(self.get_wram_value("MapGroup"), 24) + self.assertEqual(self.get_wram_value("MapNumber"), 4) + + runner.cry.move("l") + runner.cry.move("l") + runner.cry.move("l") + runner.cry.move("d") + runner.cry.move("d") + + for x in range(0, 10): + runner.cry.move("l") + runner.cry.move("d") + runner.cry.move("r") + runner.cry.move("u") + + # must still be in New Bark Town + self.assertEqual(self.get_wram_value("MapGroup"), 24) + self.assertEqual(self.get_wram_value("MapNumber"), 4) + if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From e3f6d91d0672764ffdcb2cb17483b9cba8845437 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 22 Sep 2013 11:39:34 -0500 Subject: basic keyboard writing test --- tests/test_vba.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index 787a151..b9ce832 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -212,5 +212,26 @@ class VbaTests(unittest.TestCase): self.assertEqual(self.get_wram_value("MapGroup"), 24) self.assertEqual(self.get_wram_value("MapNumber"), 4) + def test_keyboard_typing(self): + runner = autoplayer.SpeedRunner(cry=None) + runner.setup() + runner.skip_intro(stop_at_name_selection=True, skip=False, override=False) + + self.cry.vba.press("a", hold=20) + + # wait for "Your name?" to show up + text = self.cry.get_text() + + while "YOUR NAME?" not in text: + self.cry.step(count=50) + text = self.cry.get_text() + + self.cry.write() + + # save this selection + self.cry.vba.press("a", hold=20) + + # TODO: confirm the test was real + if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From e048f192d9a81bf99d6eb5d7f78714cc825b4859 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 22 Sep 2013 12:15:33 -0500 Subject: test keyboard typing functions This tests 18 different names being typed on the keyboard. These are supposed to be typed using the shortest possible sequence of button presses to get to the right letter selection. --- tests/test_vba.py | 72 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 15 deletions(-) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index b9ce832..8527e7b 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -99,6 +99,17 @@ class VbaTests(unittest.TestCase): end = (self.get_wram_value("MapY"), self.get_wram_value("MapX")) return start != end + def bootstrap_name_prompt(self): + runner = autoplayer.SpeedRunner(cry=None) + runner.setup() + runner.skip_intro(stop_at_name_selection=True, skip=False, override=False) + + self.cry.vba.press("a", hold=20) + + # wait for "Your name?" to show up + while "YOUR NAME?" not in self.cry.get_text(): + self.cry.step(count=50) + def test_movement_changes_player_direction(self): player_direction = self.get_wram_value("PlayerDirection") @@ -212,26 +223,57 @@ class VbaTests(unittest.TestCase): self.assertEqual(self.get_wram_value("MapGroup"), 24) self.assertEqual(self.get_wram_value("MapNumber"), 4) - def test_keyboard_typing(self): - runner = autoplayer.SpeedRunner(cry=None) - runner.setup() - runner.skip_intro(stop_at_name_selection=True, skip=False, override=False) - - self.cry.vba.press("a", hold=20) - - # wait for "Your name?" to show up - text = self.cry.get_text() - - while "YOUR NAME?" not in text: - self.cry.step(count=50) - text = self.cry.get_text() + def test_keyboard_typing_dumb_name(self): + self.bootstrap_name_prompt() - self.cry.write() + name = "tRaInEr" + self.cry.write(name) # save this selection self.cry.vba.press("a", hold=20) - # TODO: confirm the test was real + self.assertEqual(name, self.cry.get_player_name()) + + def test_keyboard_typing_cap_name(self): + names = [ + "trainer", + "TRAINER", + "TrAiNeR", + "tRaInEr", + "ExAmPlE", + "Chris", + "Kris", + "beepaaa", + "chris", + "CHRIS", + "Python", + "pYthon", + "pyThon", + "pytHon", + "pythOn", + "pythoN", + "python", + "PyThOn", + ] + + self.bootstrap_name_prompt() + start_state = self.cry.vba.state + + for name in names: + print "Writing name: " + name + + self.cry.vba.state = start_state + + sequence = self.cry.write(name) + + print "sequence is: " + str(sequence) + + # save this selection + self.cry.vba.press("start", hold=20) + self.cry.vba.press("a", hold=20) + + pname = self.cry.get_player_name().replace("@", "") + self.assertEqual(name, pname) if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From 2268dd43b599c691dc38c45afa5569eaf02963ef Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 22 Sep 2013 17:27:21 -0500 Subject: additional words for the keyboard testing --- tests/test_vba.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index 8527e7b..f8bdaa6 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -254,6 +254,10 @@ class VbaTests(unittest.TestCase): "pythoN", "python", "PyThOn", + "Zot", + "Death", + "Hiro", + "HIRO", ] self.bootstrap_name_prompt() -- cgit v1.2.3 From 5fdd27030e0268b6fa494b9219d3a1ac8c2a35cb Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 12 Oct 2013 16:41:50 -0500 Subject: move() can now take a list of movements to make --- tests/test_vba.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index f8bdaa6..b68e24b 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -223,6 +223,29 @@ class VbaTests(unittest.TestCase): self.assertEqual(self.get_wram_value("MapGroup"), 24) self.assertEqual(self.get_wram_value("MapNumber"), 4) + def test_crystal_move_list(self): + runner = autoplayer.SpeedRunner(cry=None) + runner.setup() + runner.skip_intro(skip=True) + runner.handle_mom(skip=True) + runner.walk_into_new_bark_town(skip=False) + + # must be in New Bark Town + self.assertEqual(self.get_wram_value("MapGroup"), 24) + self.assertEqual(self.get_wram_value("MapNumber"), 4) + + first_map_x = self.get_wram_value("MapX") + + runner.cry.move(["l", "l", "l"]) + + # x location should be different + second_map_x = self.get_wram_value("MapX") + self.assertNotEqual(first_map_x, second_map_x) + + # must still be in New Bark Town + self.assertEqual(self.get_wram_value("MapGroup"), 24) + self.assertEqual(self.get_wram_value("MapNumber"), 4) + def test_keyboard_typing_dumb_name(self): self.bootstrap_name_prompt() -- cgit v1.2.3 From 11664e2ac6660a706e1241b543121822fd40166d Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 9 Nov 2013 15:08:04 -0600 Subject: a basic battle test --- tests/test_vba.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index b68e24b..13f1c2c 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -55,6 +55,29 @@ def bootstrap(): return state +def bootstrap_trainer_battle(): + """ + Start a trainer battle. + """ + # setup + cry = vba.crystal(config=None) + runner = autoplayer.SpeedRunner(cry=cry) + + runner.skip_intro(skip=True) + runner.handle_mom(skip=True) + runner.walk_into_new_bark_town(skip=True) + runner.handle_elm("totodile", skip=True) + + # levelgrind a pokemon + # TODO: make new_bark_level_grind able to figure out how to construct its + # initial state if none is provided. + runner.new_bark_level_grind(17, skip=True) + + # TODO: figure out a better way to start a trainer battle :( + runner.cry.start_trainer_battle_lamely() + + return runner.cry.vba.state + class OtherVbaTests(unittest.TestCase): def test_keyboard_planner(self): button_sequence = keyboard.plan_typing("an") @@ -302,5 +325,13 @@ class VbaTests(unittest.TestCase): pname = self.cry.get_player_name().replace("@", "") self.assertEqual(name, pname) + def test_battle_is_player_turn(self): + state = bootstrap_trainer_battle() + self.cry.vba.state = state + + battle = Battle(emulator=self.cry) + + self.assertTrue(battle.is_player_turn()) + if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From cc403392982cfef8ccc9ed2b54ecda5934873a4f Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 9 Nov 2013 15:16:34 -0600 Subject: import Battle for testing --- tests/test_vba.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index 13f1c2c..9c12cc1 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -6,15 +6,19 @@ import unittest import pokemontools.vba.vba as vba +from pokemontools.vba.battle import ( + Battle, + BattleException, +) + try: import pokemontools.vba.vba_autoplayer as autoplayer except ImportError: import pokemontools.vba.autoplayer as autoplayer +autoplayer.vba = vba import pokemontools.vba.keyboard as keyboard -autoplayer.vba = vba - def setup_wram(): """ Loads up some default addresses. Should eventually be replaced with the -- cgit v1.2.3 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.py | 71 +++++++------------------------------------------------ 1 file changed, 8 insertions(+), 63 deletions(-) (limited to 'tests/test_vba.py') diff --git a/tests/test_vba.py b/tests/test_vba.py index 9c12cc1..caa1867 100644 --- a/tests/test_vba.py +++ b/tests/test_vba.py @@ -4,20 +4,16 @@ Tests for VBA automation tools import unittest -import pokemontools.vba.vba as vba - -from pokemontools.vba.battle import ( - Battle, - BattleException, +from setup_vba import ( + vba, + autoplayer, + keyboard, ) -try: - import pokemontools.vba.vba_autoplayer as autoplayer -except ImportError: - import pokemontools.vba.autoplayer as autoplayer -autoplayer.vba = vba - -import pokemontools.vba.keyboard as keyboard +from bootstrapping import ( + bootstrap, + bootstrap_trainer_battle, +) def setup_wram(): """ @@ -39,49 +35,6 @@ def setup_wram(): return wram -def bootstrap(): - """ - Every test needs to be run against a certain minimum context. That context - is constructed by this function. - """ - - cry = vba.crystal(config=None) - runner = autoplayer.SpeedRunner(cry=cry) - - # skip=False means run the skip_intro function instead of just skipping to - # a saved state. - runner.skip_intro(skip=True) - - state = cry.vba.state - - # clean everything up again - cry.vba.shutdown() - - return state - -def bootstrap_trainer_battle(): - """ - Start a trainer battle. - """ - # setup - cry = vba.crystal(config=None) - runner = autoplayer.SpeedRunner(cry=cry) - - runner.skip_intro(skip=True) - runner.handle_mom(skip=True) - runner.walk_into_new_bark_town(skip=True) - runner.handle_elm("totodile", skip=True) - - # levelgrind a pokemon - # TODO: make new_bark_level_grind able to figure out how to construct its - # initial state if none is provided. - runner.new_bark_level_grind(17, skip=True) - - # TODO: figure out a better way to start a trainer battle :( - runner.cry.start_trainer_battle_lamely() - - return runner.cry.vba.state - class OtherVbaTests(unittest.TestCase): def test_keyboard_planner(self): button_sequence = keyboard.plan_typing("an") @@ -329,13 +282,5 @@ class VbaTests(unittest.TestCase): pname = self.cry.get_player_name().replace("@", "") self.assertEqual(name, pname) - def test_battle_is_player_turn(self): - state = bootstrap_trainer_battle() - self.cry.vba.state = state - - battle = Battle(emulator=self.cry) - - self.assertTrue(battle.is_player_turn()) - if __name__ == "__main__": unittest.main() -- cgit v1.2.3