Skip to content

Commit

Permalink
Merge pull request junyanz#35 from AshishS-1123/test-bug-fixes
Browse files Browse the repository at this point in the history
Fixed some bugs in unittests
  • Loading branch information
jostbr authored Apr 15, 2021
2 parents 9b98423 + 98b1823 commit 0e865b2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/maze.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def generate_maze(self, start_coor = (0, 0)):
visited_cells = list() # Stack of visited cells for backtracking

print("\nGenerating the maze with depth-first search...")
time_start = time.clock()
time_start = time.time()

while visit_counter < self.grid_size: # While there are unvisited cells
neighbour_indices = self.find_neighbours(k_curr, l_curr) # Find neighbour indicies
Expand All @@ -226,7 +226,7 @@ def generate_maze(self, start_coor = (0, 0)):
path.append((k_curr, l_curr)) # Add coordinates to part of generation path

print("Number of moves performed: {}".format(len(path)))
print("Execution time for algorithm: {:.4f}".format(time.clock() - time_start))
print("Execution time for algorithm: {:.4f}".format(time.time() - time_start))

self.grid[self.entry_coor[0]][self.entry_coor[1]].set_as_entry_exit("entry",
self.num_rows-1, self.num_cols-1)
Expand Down
52 changes: 27 additions & 25 deletions tests/cell_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_entry_exit(self):
# Check if we can make the exit on the right wall in a corner
cell = Cell(2, 2)
cell.set_as_entry_exit(True, 2, 2)
self.assertEqual(cell.walls["right"], False)
self.assertEqual(cell.walls["right"], True)

def test_remove_walls(self):
"""Test the Cell::remove_walls method"""
Expand All @@ -60,7 +60,7 @@ def test_remove_walls(self):

# Remove the cell to the left
cell = Cell(0, 1)
cell.remove_walls(1, 0)
cell.remove_walls(0, 0)
self.assertEqual(cell.walls["left"], False)

# Remove the cell above
Expand All @@ -79,31 +79,33 @@ def test_is_walls_between(self):
Note that cells are constructed with neighbors on each side.
We'll need to remove some walls to get full coverage.
"""
# Create a base cell for which we will be testing whether walls exist
cell = Cell (1, 1)

# Create a cell appearing to the top of this cell
cell_top = Cell(0,1)
# Create a cell appearing to the right of this cell
cell_right = Cell(1,2)
# Create a cell appearing to the bottom of this cell
cell_bottom = Cell(2,1)
# Create a cell appearing to the left of this cell
cell_left = Cell(1,0)


# check for walls between all these cells
self.assertEqual(cell.is_walls_between(cell_top), True)
self.assertEqual(cell.is_walls_between(cell_right), True)
self.assertEqual(cell.is_walls_between(cell_bottom), True)
self.assertEqual(cell.is_walls_between(cell_left), True)

# remove top wall of 'cell' and bottom wall of 'cell_top'
cell.remove_walls(0,1)
cell_top.remove_walls(1,1)

# We should have walls on all sides of a new cell
cell = Cell (0, 0)
self.assertEqual(cell.walls, {"top": True, "right": True, "bottom": True, "left": True})

# Remove the wall to the right
cell2 = Cell(1, 0)
cell2.remove_walls(1, 2)
self.assertEqual(cell.walls, {"top": True, "right": False, "bottom": True, "left": True})

# Remove the wall to the left
cell3 = Cell(0, 2)
cell3.remove_walls(0, 1)
self.assertEqual(cell.walls, {"top": True, "right": True, "bottom": True, "left": False})

# Remove the wall on the top
cell4 = Cell(1, 2)
cell4.remove_walls(0, 2)
self.assertEqual(cell.walls, {"top": False, "right": True, "bottom": True, "left": True})
# check that there are no walls between these cells
self.assertEqual(cell.is_walls_between(cell_top), False)

# Remove the wall on the bottom
cell5 = Cell(2, 2)
cell5.remove_walls(3, 2)
self.assertEqual(cell.walls, {"top": True, "right": True, "bottom": False, "left": True})


if __name__ == "__main__":
unittest.main()
unittest.main()

0 comments on commit 0e865b2

Please sign in to comment.