Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
Added tests for the JsonLevelGenerator. The transformation of the map…
Browse files Browse the repository at this point in the history
… may not be what we need.
  • Loading branch information
danalex97 committed Jul 25, 2017
1 parent 8683d66 commit 97787a3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion aimmo-game/simulation/custom_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _setup_meta(self):
self.meta = element
self.world_map = EmptyMapGenerator.get_map_by_corners(
self.settings,
(0, self.meta["raws"] + 1, 0, self.meta["cols"] + 1))
(0, self.meta["raws"] - 1, 0, self.meta["cols"] - 1))

def _register_json(self, json_map):
self.json_map = json_map
Expand Down
37 changes: 35 additions & 2 deletions aimmo-game/tests/test_simulation/test_custom_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def get_map(self):
.by_map(map)
.by_models(parsers)
.generate_json())
self._setup_meta()
self._register_decoders()
self._json_decode_map()

Expand All @@ -106,5 +107,37 @@ def test_json_simple_map(self):
mock_level = get_mock_level("map_simple.txt", ["real_model.json"])
mock_map = mock_level.get_map()

# for cell in mock_map.all_cells():
# print("CELL: (" + str(cell.location.x) + " " + str(cell.location.y) + ")")
self.assertEquals(mock_map.num_cols, 2)
self.assertEquals(mock_map.num_rows, 5)

# 1 2 3 0 0
# 0 0 1 0 2

self.assertFalse(mock_map.get_cell(Location(0, 0)).habitable)
self.assertTrue(mock_map.get_cell(Location(0, 1)).generates_score)
self.assertTrue(isinstance(mock_map.get_cell(Location(0, 2)).pickup, HealthPickup))
self.assertTrue(mock_map.get_cell(Location(1, 4)).generates_score)
self.assertFalse(mock_map.get_cell(Location(1, 2)).habitable)

def test_json_big_map(self):
mock_level = get_mock_level("map_big.txt", ["real_model.json"])
mock_map = mock_level.get_map()

self.assertEquals(mock_map.num_cols, 7)
self.assertEquals(mock_map.num_rows, 11)

# 0 0 0 2 0 0 0 0 0 0 0
# 0 0 2 2 0 0 0 0 0 0 0
# 0 0 2 2 0 1 1 1 1 0 0
# 0 0 0 2 0 0 0 0 1 0 0
# 0 0 0 0 0 0 0 0 1 0 0
# 0 0 0 0 0 0 0 0 0 0 0
# 0 0 0 0 0 0 0 0 0 0 0

score_locations = [(0,3), (1,2), (1,3), (2,2), (2,3), (3,3)]
obstacle_locations = [(2,5), (2,6), (2,7), (2,8), (3,8), (4,8)]

for x, y in score_locations:
self.assertTrue(mock_map.get_cell(Location(x, y)).generates_score)
for x, y in obstacle_locations:
self.assertFalse(mock_map.get_cell(Location(x, y)).habitable)

0 comments on commit 97787a3

Please sign in to comment.