From 18ca083ba213142416f7f7d28458f8c0ee3144b2 Mon Sep 17 00:00:00 2001 From: Charles Peyrat Date: Fri, 11 Dec 2020 18:59:07 +0100 Subject: [PATCH] Added a connexity test --- squirrelbattle/tests/mapgeneration_test.py | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 squirrelbattle/tests/mapgeneration_test.py diff --git a/squirrelbattle/tests/mapgeneration_test.py b/squirrelbattle/tests/mapgeneration_test.py new file mode 100644 index 0000000..abaed1b --- /dev/null +++ b/squirrelbattle/tests/mapgeneration_test.py @@ -0,0 +1,29 @@ +# 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: + self.generator = randomwalk.Generator() + + 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 = m.neighbourhood(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 += m.neighbourhood(y, x) + self.assertFalse(any([any([t.can_walk() for t in l]) for l in m.tiles]))