# Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse # SPDX-License-Identifier: GPL-3.0-or-later import unittest from squirrelbattle.interfaces import Map, Tile from squirrelbattle.mapgeneration import randomwalk class TestRandomWalk(unittest.TestCase): def setUp(self) -> None: #we set no_lone_walls to true for 100% coverage params = randomwalk.DEFAULT_PARAMS params["no_lone_walls"] = True self.generator = randomwalk.Generator(params = params) def test_starting(self) -> None: """ Create a map and check that the whole map is accessible from the starting position using a depth-first search """ m = self.generator.run() self.assertTrue(m.tiles[m.start_y][m.start_x].can_walk()) #DFS queue = Map.neighbourhood(m.tiles, m.start_y, m.start_x) while queue != []: y, x = queue.pop() if m.tiles[y][x].can_walk(): m.tiles[y][x] = Tile.WALL queue += Map.neighbourhood(m.tiles, y, x) self.assertFalse(any([any([t.can_walk() for t in l]) for l in m.tiles]))