Skip to content

Commit

Permalink
Added a test for the automatic level class generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
danalex97 committed Jul 28, 2017
1 parent 9c345e3 commit 533a0a4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aimmo-game/simulation/custom_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def find_element_by_code(json, code):

#### Dragons be here

def generate_level_class(level_nbr):
def generate_level_class(level_nbr, LEVELS=LEVELS, COMPLETION_CHECKS=COMPLETION_CHECKS):
level_name = "Level" + str(level_nbr)
level_id = "level" + str(level_nbr)

Expand Down
22 changes: 22 additions & 0 deletions aimmo-game/tests/test_simulation/test_custom_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from simulation.pickups import DamagePickup
from simulation.pickups import InvulnerabilityPickup

from simulation.levels.levels import LEVELS
from simulation.custom_map import generate_level_class

from simulation.custom_map import JsonLevelGenerator
from simulation.levels.levels import RawLevelGenerator
from .levels.test_parsers import MockParser
Expand Down Expand Up @@ -68,3 +71,22 @@ def test_json_big_map(self):
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)

class TestAutomaticLevelGenerators(unittest.TestCase):
def test_generate_level_class(self):
def completed_check(self, y):
return False

COMPLETION_CHECKS = {
"level50" : completed_check
}
LEVELS = {
"level50" : {}
}
my_class = generate_level_class(50, LEVELS, COMPLETION_CHECKS)

self.assertEquals(my_class.__name__, "Level50")
instance = my_class({})

self.assertTrue(hasattr(instance, 'get_map'))
self.assertTrue(hasattr(instance, 'check_complete'))

0 comments on commit 533a0a4

Please sign in to comment.