Skip to content

Commit

Permalink
Issue-46: Remove static function from create_map, Update Unit Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tysterman74 committed Feb 11, 2024
1 parent 3fef623 commit 90d0e6e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Map/MapManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var current_map: MapBase
var map_width_array: Array[int] = [1, 3, 5, 7, 9, 11, 9, 7, 5, 3, 1]

#map_floors_width changes the width of the map's floors
static func create_map(map_floors_width: Array[int]) -> MapBase: ## Generates and Populates a map with rooms that have random room types. More in depth algorithms will be added in the future
func create_map(map_floors_width: Array[int]) -> MapBase: ## Generates and Populates a map with rooms that have random room types. More in depth algorithms will be added in the future
var _map: MapBase = MapBase.new()
var _grid: Array[Array] = [] ## 2d array to return. this will be populated with rooms
var _max_floor_size: int = map_floors_width.max()
Expand All @@ -31,7 +31,7 @@ static func create_map(map_floors_width: Array[int]) -> MapBase: ## Generates an
return _map as MapBase

func _ready():
current_map = MapManager.create_map(map_width_array)
current_map = create_map(map_width_array)

func is_map_initialized() -> bool:
return current_map != null
7 changes: 6 additions & 1 deletion Tests/test_map.gd
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
extends GutTest ## Tests for MapManager, more will be added in the future

var test_generator = load("res://Map/MapManager.gd")
var map_manager: MapManager = null

func test_map_gen():
map_manager = test_generator.new()
var test_width: Array[int] = [1,3,5,3,1]
var test_map: MapBase = test_generator.create_map(test_width)
var test_map: MapBase = map_manager.create_map(test_width)
var expected_null_array: Array[Array] = [[0,0], [0,1], [0,3],[0,4],[1,0],[1,4],[3,0],[3,4],[4,0],[4,1],[4,3],[4,4]]
var expected_exists_array: Array[Array] = [[0,2],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[2,4],[3,1],[3,2],[3,3],[4,2]]
for couple: Array[int] in expected_null_array:
Expand All @@ -14,3 +16,6 @@ func test_map_gen():
for couple: Array[int] in expected_exists_array:
var _room = test_map.rooms[couple[0]][couple[1]]
assert_not_null(_room, "Expected not null at %s but got %s" % [couple, _room])

func after_each():
map_manager.free()

0 comments on commit 90d0e6e

Please sign in to comment.