Files
mortal-maze-the-game/tests/test_pixel_combat_resources.py

63 lines
2.9 KiB
Python

"""Pruebas sin motor: python -m unittest discover -s tests -v."""
from pathlib import Path
import math
import re
import unittest
try:
from .art_asset_helpers import atlas_path, atlas_regions, rgba_png
except ImportError: # unittest discover -s tests imports each module at the top level.
from art_asset_helpers import atlas_path, atlas_regions, rgba_png
ROOT = Path(__file__).resolve().parents[1]
FRAMES = ROOT / "player/characters/animations/guitarist_frames.tres"
class PixelCombatResourceTests(unittest.TestCase):
def test_all_animation_cells_exist_and_fit_atlas(self):
text = FRAMES.read_text(encoding="utf-8")
width, height, _ = rgba_png(atlas_path(ROOT, text))
declared = re.findall(r'\[sub_resource type="AtlasTexture" id="([^"]+)"\]', text)
used = re.findall(r'SubResource\("([^"]+)"\)', text)
self.assertGreaterEqual(len(declared), 40)
self.assertEqual(set(declared), set(used))
self.assertEqual(len(declared), len(set(declared)))
for x, y, w, h in atlas_regions(text).values():
self.assertEqual((w, h), (192, 192))
self.assertLessEqual(x + w, width)
self.assertLessEqual(y + h, height)
def test_player_poses_and_pixel_scale(self):
names = set(re.findall(r'"name": &"([^"]+)"', FRAMES.read_text()))
self.assertTrue({"idle", "walk", "jump", "fall", "punch", "ground_pound",
"land", "pound_land", "special_start", "special", "special_end", "hurt"} <= names)
scene = (ROOT / "player/player.tscn").read_text()
self.assertIn("size = Vector2(26, 52)", scene)
self.assertIn("texture_filter = 1", scene)
self.assertIn("scale = Vector2(0.5, 0.5)", scene)
self.assertIn("speed_scale = 1.0", scene)
def test_new_asset_has_no_external_dependencies(self):
frames = FRAMES.read_text(encoding="utf-8")
self.assertEqual(atlas_path(ROOT, frames).suffix, ".png")
self.assertNotIn('.svg', frames)
for rel in ("player/player.gd", "enemies/walker/walker.gd", str(FRAMES.relative_to(ROOT))):
for path in re.findall(r'res://([^"\s]+)', (ROOT / rel).read_text()):
self.assertTrue((ROOT / path).is_file(), path)
def test_pulse_rounding_preserves_the_damage_budget(self):
# Invariante matematica de la formula de dano acumulado de GDScript.
# test_pixel_combat_runtime.gd comprueba por separado el comportamiento real.
for total in range(1, 101):
for count in range(1, 9):
dealt = 0
for index in range(count):
cumulative = math.ceil(total * (index + 1) / count)
damage = cumulative - dealt
self.assertGreaterEqual(damage, 0)
dealt = cumulative
self.assertEqual(dealt, total)
if __name__ == "__main__":
unittest.main()