More testing improvements.
This commit is contained in:
parent
84fff71344
commit
d0a6a92bc8
3 changed files with 20 additions and 92 deletions
|
@ -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])
|
||||
|
|
|
@ -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<Player>(ent1, {ent1});
|
||||
world.set<Position>(ent1, {{10,1}});
|
||||
world.set<Motion>(ent1, {1,0});
|
||||
world.set<Loot>(ent1, {100});
|
||||
world.set<Inventory>(ent1, {0});
|
||||
world.set<Tile>(ent1, {"Z"});
|
||||
world.set<EnemyConfig>(ent1, {4});
|
||||
|
||||
auto player = world.get<Player>(ent1);
|
||||
REQUIRE(player.entity == ent1);
|
||||
|
||||
auto position = world.get<Position>(ent1);
|
||||
REQUIRE(position.location.x == 10);
|
||||
REQUIRE(position.location.y == 1);
|
||||
|
||||
auto motion = world.get<Motion>(ent1);
|
||||
REQUIRE(motion.dx == 1);
|
||||
REQUIRE(motion.dy == 0);
|
||||
|
||||
auto loot = world.get<Loot>(ent1);
|
||||
REQUIRE(loot.amount == 100);
|
||||
|
||||
auto inv = world.get<Inventory>(ent1);
|
||||
REQUIRE(inv.gold == 0);
|
||||
|
||||
auto tile = world.get<Tile>(ent1);
|
||||
REQUIRE(tile.chr == "Z");
|
||||
}
|
||||
|
||||
TEST_CASE("all components can be facts", "[components]") {
|
||||
World world;
|
||||
auto ent1 = world.entity();
|
||||
|
||||
world.set_the<Player>({ent1});
|
||||
world.set_the<Position>({{10,1}});
|
||||
world.set_the<Motion>({1,0});
|
||||
world.set_the<Loot>({100});
|
||||
world.set_the<Inventory>({0});
|
||||
world.set_the<Tile>({"Z"});
|
||||
world.set_the<EnemyConfig>({4});
|
||||
|
||||
auto player = world.get_the<Player>();
|
||||
REQUIRE(player.entity == ent1);
|
||||
|
||||
auto position = world.get_the<Position>();
|
||||
REQUIRE(position.location.x == 10);
|
||||
REQUIRE(position.location.y == 1);
|
||||
|
||||
auto motion = world.get_the<Motion>();
|
||||
REQUIRE(motion.dx == 1);
|
||||
REQUIRE(motion.dy == 0);
|
||||
|
||||
auto loot = world.get_the<Loot>();
|
||||
REQUIRE(loot.amount == 100);
|
||||
|
||||
auto inv = world.get_the<Inventory>();
|
||||
REQUIRE(inv.gold == 0);
|
||||
|
||||
auto tile = world.get_the<Tile>();
|
||||
REQUIRE(tile.chr == "Z");
|
||||
}
|
||||
|
||||
TEST_CASE("confirm combat works", "[components]") {
|
||||
World world;
|
||||
auto player = world.entity();
|
||||
auto enemy = world.entity();
|
||||
|
||||
world.set<Combat>(player, {100, 10});
|
||||
world.set<Combat>(enemy, {20, 10});
|
||||
|
||||
auto p_fight = world.get<Combat>(player);
|
||||
REQUIRE(p_fight.hp == 100);
|
||||
REQUIRE(p_fight.damage == 10);
|
||||
REQUIRE(p_fight.dead == false);
|
||||
|
||||
auto e_fight = world.get<Combat>(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);
|
||||
}
|
||||
|
|
|
@ -2,16 +2,31 @@
|
|||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
#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));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue