2021-01-10 09:46:17 +00:00
|
|
|
# Copyright (C) 2020-2021 by ÿnérant, eichhornchen, nicomarg, charlse
|
2020-11-27 15:33:17 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-10-09 16:17:41 +00:00
|
|
|
import unittest
|
|
|
|
|
2021-01-10 10:25:53 +00:00
|
|
|
from ..display.texturepack import TexturePack
|
|
|
|
from ..interfaces import Map, Slope, Tile
|
|
|
|
from ..resources import ResourceManager
|
2020-10-09 16:17:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestInterfaces(unittest.TestCase):
|
2020-10-09 16:24:13 +00:00
|
|
|
def test_map(self) -> None:
|
2020-10-16 16:05:49 +00:00
|
|
|
"""
|
2020-12-13 20:29:25 +00:00
|
|
|
Creates a map and checks that it is well parsed.
|
2020-10-16 16:05:49 +00:00
|
|
|
"""
|
2020-11-11 15:09:03 +00:00
|
|
|
m = Map.load_from_string("0 0\n.#\n#.\n")
|
2020-10-09 16:17:41 +00:00
|
|
|
self.assertEqual(m.width, 2)
|
|
|
|
self.assertEqual(m.height, 2)
|
2020-11-06 19:26:10 +00:00
|
|
|
self.assertEqual(m.draw_string(TexturePack.ASCII_PACK), ".#\n#.")
|
2020-11-06 15:13:28 +00:00
|
|
|
|
|
|
|
def test_load_map(self) -> None:
|
|
|
|
"""
|
2020-12-13 20:29:25 +00:00
|
|
|
Tries to load a map from a file.
|
2020-11-06 15:13:28 +00:00
|
|
|
"""
|
2020-11-19 01:49:59 +00:00
|
|
|
m = Map.load(ResourceManager.get_asset_path("example_map.txt"))
|
2020-11-11 21:36:42 +00:00
|
|
|
self.assertEqual(m.width, 52)
|
2020-11-06 15:13:28 +00:00
|
|
|
self.assertEqual(m.height, 17)
|
|
|
|
|
|
|
|
def test_tiles(self) -> None:
|
|
|
|
"""
|
2020-12-13 20:29:25 +00:00
|
|
|
Tests some things about tiles.
|
2020-11-06 15:13:28 +00:00
|
|
|
"""
|
|
|
|
self.assertFalse(Tile.FLOOR.is_wall())
|
|
|
|
self.assertTrue(Tile.WALL.is_wall())
|
|
|
|
self.assertFalse(Tile.EMPTY.is_wall())
|
|
|
|
self.assertTrue(Tile.FLOOR.can_walk())
|
|
|
|
self.assertFalse(Tile.WALL.can_walk())
|
2020-11-10 20:41:54 +00:00
|
|
|
self.assertFalse(Tile.EMPTY.can_walk())
|
2020-11-06 20:23:17 +00:00
|
|
|
self.assertRaises(ValueError, Tile.from_ascii_char, 'unknown')
|
2020-12-18 20:21:00 +00:00
|
|
|
|
|
|
|
def test_slope(self) -> None:
|
|
|
|
"""
|
|
|
|
Test good behaviour of slopes (basically vectors, compared according to
|
|
|
|
the determinant)
|
|
|
|
"""
|
|
|
|
a = Slope(1, 1)
|
|
|
|
b = Slope(0, 1)
|
|
|
|
self.assertTrue(b < a)
|
|
|
|
self.assertTrue(b <= a)
|
|
|
|
self.assertTrue(a <= a)
|
|
|
|
self.assertTrue(a == a)
|
|
|
|
self.assertTrue(a > b)
|
|
|
|
self.assertTrue(a >= b)
|
|
|
|
|
|
|
|
# def test_visibility(self) -> None:
|
|
|
|
# m = Map.load(ResourceManager.get_asset_path("example_map_3.txt"))
|
|
|
|
# m.compute_visibility(1, 1, 50)
|