Fix broken tests

This commit is contained in:
Yohann D'ANELLO 2020-11-11 16:58:20 +01:00
parent ac22aef860
commit 8db00bcaa6
3 changed files with 19 additions and 10 deletions

View File

@ -47,11 +47,9 @@ class Game:
""" """
# TODO generate a new map procedurally # TODO generate a new map procedurally
self.map = Map.load("resources/example_map_2.txt") self.map = Map.load("resources/example_map_2.txt")
self.map.currenty = 1
self.map.currentx = 6
self.player = Player() self.player = Player()
self.map.add_entity(self.player) self.map.add_entity(self.player)
self.player.move(1, 14) self.player.move(self.map.start_y, self.map.start_x)
self.map.spawn_random_entities(randint(3, 10)) self.map.spawn_random_entities(randint(3, 10))
@staticmethod @staticmethod

View File

@ -12,6 +12,9 @@ class TestEntities(unittest.TestCase):
Load example map that can be used in tests. Load example map that can be used in tests.
""" """
self.map = Map.load("resources/example_map.txt") self.map = Map.load("resources/example_map.txt")
self.player = Player()
self.map.add_entity(self.player)
self.player.move(self.map.start_y, self.map.start_x)
def test_basic_entities(self) -> None: def test_basic_entities(self) -> None:
""" """
@ -48,21 +51,29 @@ class TestEntities(unittest.TestCase):
entity = Hedgehog() entity = Hedgehog()
self.map.add_entity(entity) self.map.add_entity(entity)
entity.move(2, 6) entity.move(3, 6)
self.map.tick() self.map.tick()
self.assertFalse(entity.y == 2 and entity.x == 6) self.assertTrue(entity.y == 2 and entity.x == 6)
def test_items(self) -> None: def test_items(self) -> None:
""" """
Test some random stuff with items. Test some random stuff with items.
""" """
item = Item() item = Item()
self.map.add_entity(item)
self.assertFalse(item.held) self.assertFalse(item.held)
item.hold() item.hold(self.player)
self.assertTrue(item.held) self.assertTrue(item.held)
item.drop(42, 42) item.drop(2, 6)
self.assertEqual(item.y, 42) self.assertEqual(item.y, 2)
self.assertEqual(item.x, 42) self.assertEqual(item.x, 6)
# Pick up item
self.player.move_down()
self.assertTrue(item.held)
self.assertEqual(item.held_by, self.player)
self.assertIn(item, self.player.inventory)
self.assertNotIn(item, self.map.entities)
def test_bombs(self) -> None: def test_bombs(self) -> None:
""" """

View File

@ -19,7 +19,7 @@ class TestInterfaces(unittest.TestCase):
Try to load a map from a file. Try to load a map from a file.
""" """
m = Map.load("resources/example_map.txt") m = Map.load("resources/example_map.txt")
self.assertEqual(m.width, 52) self.assertEqual(m.width, 44)
self.assertEqual(m.height, 17) self.assertEqual(m.height, 17)
def test_tiles(self) -> None: def test_tiles(self) -> None: