Exemple #1
0
 def setUp(self):
     self.game_map = GameMap()
     self.game_map.load_level([["r", "w"], ["l", "m"]])
Exemple #2
0
class TestGameMap(unittest.TestCase):
    def setUp(self):
        self.game_map = GameMap()
        self.game_map.load_level([["r", "w"], ["l", "m"]])

    def test_tile_at_pos(self):
        self.assertEqual(self.game_map.tile_at_pos(0, 0).type, "road")  # Tile type is not a road.
        self.assertEqual(self.game_map.tile_at_pos(0, 1).type, "water")  # Tile type is not a water.
        self.assertEqual(self.game_map.tile_at_pos(1, 0).type, "land")  # Tile type is not a land.
        self.assertEqual(self.game_map.tile_at_pos(1, 1).type, "mountain")  # Tile type is not a mountain.

    def test_tile_at_coord(self):
        self.assertEqual(self.game_map.tile_at_coord(0, 0).type, "road")  # Tile type is not a road.
        self.assertEqual(self.game_map.tile_at_coord(10, 10).type, "road")  # Tile type is not a road.

    def test_find_path_begin_end(self):
        orig, dest = self.game_map.tile_at_pos(0, 0), self.game_map.tile_at_pos(1, 1)
        path = self.game_map.find_path(orig, dest)
        self.assertEqual(path[0], orig)  # Path doesn't start at the given start tile
        self.assertEqual(path[-1], dest)  # Path doesn't end at the given end tile
        self.assertEqual(len(path), 3)  # Path is of the wrong length

    def test_find_path_one_tile(self):
        orig, dest = self.game_map.tile_at_pos(0, 0), self.game_map.tile_at_pos(0, 0)
        path = self.game_map.find_path(orig, dest)
        self.assertEqual(path[0], orig)  # Path doesn't contain given tile
        self.assertEqual(len(path), 1)  # Path is of the wrong length