2020-11-27 16:33:17 +01:00
|
|
|
# Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-10-09 18:17:41 +02:00
|
|
|
import unittest
|
|
|
|
|
2020-11-19 02:18:08 +01:00
|
|
|
from squirrelbattle.display.texturepack import TexturePack
|
|
|
|
from squirrelbattle.interfaces import Map, Tile
|
2020-11-19 02:49:59 +01:00
|
|
|
from squirrelbattle.resources import ResourceManager
|
2020-10-09 18:17:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestInterfaces(unittest.TestCase):
|
2020-10-09 18:24:13 +02:00
|
|
|
def test_map(self) -> None:
|
2020-10-16 18:05:49 +02:00
|
|
|
"""
|
|
|
|
Create a map and check that it is well parsed.
|
|
|
|
"""
|
2020-11-11 16:09:03 +01:00
|
|
|
m = Map.load_from_string("0 0\n.#\n#.\n")
|
2020-10-09 18:17:41 +02:00
|
|
|
self.assertEqual(m.width, 2)
|
|
|
|
self.assertEqual(m.height, 2)
|
2020-11-06 20:26:10 +01:00
|
|
|
self.assertEqual(m.draw_string(TexturePack.ASCII_PACK), ".#\n#.")
|
2020-11-06 16:13:28 +01:00
|
|
|
|
|
|
|
def test_load_map(self) -> None:
|
|
|
|
"""
|
|
|
|
Try to load a map from a file.
|
|
|
|
"""
|
2020-11-19 02:49:59 +01:00
|
|
|
m = Map.load(ResourceManager.get_asset_path("example_map.txt"))
|
2020-11-11 22:36:42 +01:00
|
|
|
self.assertEqual(m.width, 52)
|
2020-11-06 16:13:28 +01:00
|
|
|
self.assertEqual(m.height, 17)
|
|
|
|
|
|
|
|
def test_tiles(self) -> None:
|
|
|
|
"""
|
|
|
|
Test some things about tiles.
|
|
|
|
"""
|
|
|
|
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 21:41:54 +01:00
|
|
|
self.assertFalse(Tile.EMPTY.can_walk())
|
2020-11-06 21:23:17 +01:00
|
|
|
self.assertRaises(ValueError, Tile.from_ascii_char, 'unknown')
|