squirrel-battle/dungeonbattle/tests/entities_test.py

82 lines
2.5 KiB
Python

import unittest
from dungeonbattle.entities.items import Bomb, Item
from dungeonbattle.entities.monsters import Squirrel
from dungeonbattle.entities.player import Player
from dungeonbattle.interfaces import Entity, Map
class TestEntities(unittest.TestCase):
def setUp(self) -> None:
"""
Load example map that can be used in tests.
"""
self.map = Map.load("example_map.txt")
def test_basic_entities(self) -> None:
"""
Test some random stuff with basic entities.
"""
entity = Entity()
entity.move(42, 64)
self.assertEqual(entity.y, 42)
self.assertEqual(entity.x, 64)
self.assertIsNone(entity.act(self.map))
def test_fighting_entities(self) -> None:
"""
Test some random stuff with fighting entities.
"""
entity = Squirrel()
self.assertIsNone(entity.act(self.map))
self.assertEqual(entity.maxhealth, 10)
self.assertEqual(entity.maxhealth, entity.health)
self.assertEqual(entity.strength, 3)
self.assertIsNone(entity.hit(entity))
self.assertFalse(entity.dead)
self.assertIsNone(entity.hit(entity))
self.assertFalse(entity.dead)
self.assertIsNone(entity.hit(entity))
self.assertFalse(entity.dead)
self.assertIsNone(entity.hit(entity))
self.assertTrue(entity.dead)
def test_items(self) -> None:
"""
Test some random stuff with items.
"""
item = Item()
self.assertFalse(item.held)
item.hold()
self.assertTrue(item.held)
item.drop(42, 42)
self.assertEqual(item.y, 42)
self.assertEqual(item.x, 42)
def test_bombs(self) -> None:
"""
Test some random stuff with bombs.
"""
item = Bomb()
squirrel = Squirrel()
self.map.add_entity(item)
self.map.add_entity(squirrel)
squirrel.health = 2
squirrel.move(41, 42)
item.act(self.map)
self.assertFalse(squirrel.dead)
item.drop(42, 42)
self.assertEqual(item.y, 42)
self.assertEqual(item.x, 42)
item.act(self.map)
self.assertTrue(squirrel.dead)
def test_players(self) -> None:
"""
Test some random stuff with players.
"""
player = Player()
self.assertEqual(player.strength, 5)
self.assertEqual(player.health, player.maxhealth)
self.assertEqual(player.maxhealth, 20)