summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBryan Bishop <kanzure@gmail.com>2013-09-22 10:10:46 -0500
committerBryan Bishop <kanzure@gmail.com>2013-09-22 10:10:46 -0500
commit1d92396ca92d25cf19bdf47ce467e467e8638d08 (patch)
treedece26e082bb15aebc0293276e4ee2ef80b75a85 /tests
parent3151acd42c6f7f448499b6cdf20a603ff7c150e8 (diff)
reduce some duplicated code inside some tests
Those movement checks are now collapsed into a single function that each test can individually call.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_vba.py32
1 files changed, 14 insertions, 18 deletions
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)