From d0a6a92bc8869ab5797275536caf7a52eeeea96d Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Fri, 21 Feb 2025 13:21:13 -0500 Subject: [PATCH] More testing improvements. --- meson.build | 1 + tests/components.cpp | 94 ++------------------------------------------ tests/textures.cpp | 17 +++++++- 3 files changed, 20 insertions(+), 92 deletions(-) diff --git a/meson.build b/meson.build index c39ad6f..31158e2 100644 --- a/meson.build +++ b/meson.build @@ -105,6 +105,7 @@ executable('runtests', sources + [ 'tests/pathing.cpp', 'tests/spatialmap.cpp', 'tests/tilemap.cpp', + 'tests/components.cpp', 'tests/textures.cpp', ], override_options: exe_defaults, dependencies: dependencies + [catch2]) diff --git a/tests/components.cpp b/tests/components.cpp index 095acec..222a17b 100644 --- a/tests/components.cpp +++ b/tests/components.cpp @@ -5,95 +5,7 @@ using namespace components; using namespace DinkyECS; -TEST_CASE("all components can work in the world", "[components]") { - World world; - auto ent1 = world.entity(); - - world.set(ent1, {ent1}); - world.set(ent1, {{10,1}}); - world.set(ent1, {1,0}); - world.set(ent1, {100}); - world.set(ent1, {0}); - world.set(ent1, {"Z"}); - world.set(ent1, {4}); - - auto player = world.get(ent1); - REQUIRE(player.entity == ent1); - - auto position = world.get(ent1); - REQUIRE(position.location.x == 10); - REQUIRE(position.location.y == 1); - - auto motion = world.get(ent1); - REQUIRE(motion.dx == 1); - REQUIRE(motion.dy == 0); - - auto loot = world.get(ent1); - REQUIRE(loot.amount == 100); - - auto inv = world.get(ent1); - REQUIRE(inv.gold == 0); - - auto tile = world.get(ent1); - REQUIRE(tile.chr == "Z"); -} - -TEST_CASE("all components can be facts", "[components]") { - World world; - auto ent1 = world.entity(); - - world.set_the({ent1}); - world.set_the({{10,1}}); - world.set_the({1,0}); - world.set_the({100}); - world.set_the({0}); - world.set_the({"Z"}); - world.set_the({4}); - - auto player = world.get_the(); - REQUIRE(player.entity == ent1); - - auto position = world.get_the(); - REQUIRE(position.location.x == 10); - REQUIRE(position.location.y == 1); - - auto motion = world.get_the(); - REQUIRE(motion.dx == 1); - REQUIRE(motion.dy == 0); - - auto loot = world.get_the(); - REQUIRE(loot.amount == 100); - - auto inv = world.get_the(); - REQUIRE(inv.gold == 0); - - auto tile = world.get_the(); - REQUIRE(tile.chr == "Z"); -} - -TEST_CASE("confirm combat works", "[components]") { - World world; - auto player = world.entity(); - auto enemy = world.entity(); - - world.set(player, {100, 10}); - world.set(enemy, {20, 10}); - - auto p_fight = world.get(player); - REQUIRE(p_fight.hp == 100); - REQUIRE(p_fight.damage == 10); - REQUIRE(p_fight.dead == false); - - auto e_fight = world.get(enemy); - REQUIRE(e_fight.hp == 20); - REQUIRE(e_fight.damage == 10); - REQUIRE(e_fight.dead == false); - - for(int i = 0; e_fight.hp > 0 && i < 100; i++) { - p_fight.attack(e_fight); - } -} - -TEST_CASE("MapConfig loads from JSON", "[components]") { - +TEST_CASE("confirm component loading works", "[components]") { + components::ComponentMap comp_map; + components::configure(comp_map); } diff --git a/tests/textures.cpp b/tests/textures.cpp index 4901447..e705c3c 100644 --- a/tests/textures.cpp +++ b/tests/textures.cpp @@ -2,16 +2,31 @@ #include #include #include "textures.hpp" +#include "levelmanager.hpp" using namespace fmt; TEST_CASE("test texture management", "[textures]") { - textures::init(); auto spider = textures::get("hairy_spider"); + REQUIRE(spider.sprite != nullptr); + REQUIRE(spider.texture != nullptr); auto image = textures::load_image("assets/hairy_spider-256.png"); auto img_ptr = textures::get_surface(0); REQUIRE(img_ptr != nullptr); + + auto floor_ptr = textures::get_floor(); + REQUIRE(floor_ptr != nullptr); + + auto ceiling_ptr = textures::get_ceiling(); + REQUIRE(ceiling_ptr != nullptr); + + LevelManager levels; + GameLevel level = levels.current(); + auto& tiles = level.map->tiles(); + auto map = textures::convert_char_to_texture(tiles.$tile_ids); + REQUIRE(matrix::width(map) == matrix::width(tiles.$tile_ids)); + REQUIRE(matrix::height(map) == matrix::height(tiles.$tile_ids)); }