Started to convert from catch2 to fuc2.
This commit is contained in:
parent
4deda37665
commit
b8b42d5681
10 changed files with 615 additions and 493 deletions
|
|
@ -1,4 +1,3 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include "graphics/textures.hpp"
|
||||
#include "algos/dinkyecs.hpp"
|
||||
#include "game/config.hpp"
|
||||
|
|
@ -10,13 +9,16 @@
|
|||
#include "graphics/animation.hpp"
|
||||
#include "game/sound.hpp"
|
||||
#include "game/components.hpp"
|
||||
#include <fuc2/testing.hpp>
|
||||
|
||||
using namespace components;
|
||||
using namespace textures;
|
||||
using namespace std::chrono_literals;
|
||||
using namespace animation;
|
||||
using namespace fuc2;
|
||||
|
||||
Animation load_animation(const string& name) {
|
||||
namespace animation_tests {
|
||||
Animation load_animation(const string& name) {
|
||||
auto anim = animation::load("assets/animation.json", "rat_king_boss");
|
||||
anim.set_form("attack");
|
||||
|
||||
|
|
@ -27,14 +29,14 @@ Animation load_animation(const string& name) {
|
|||
}
|
||||
|
||||
return anim;
|
||||
}
|
||||
}
|
||||
|
||||
void FAKE_RENDER() {
|
||||
void FAKE_RENDER() {
|
||||
std::this_thread::sleep_for(Random::milliseconds(5, 32));
|
||||
}
|
||||
}
|
||||
|
||||
void PLAY_TEST(Animation &anim) {
|
||||
REQUIRE(anim.transform.looped == false);
|
||||
void PLAY_TEST(Animation &anim) {
|
||||
CHECK(anim.transform.looped == false);
|
||||
anim.play();
|
||||
|
||||
while(anim.playing) {
|
||||
|
|
@ -42,10 +44,10 @@ void PLAY_TEST(Animation &anim) {
|
|||
FAKE_RENDER();
|
||||
}
|
||||
|
||||
REQUIRE(anim.playing == false);
|
||||
}
|
||||
CHECK(anim.playing == false);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Animation is a Sheet + Sequence + Transform.
|
||||
*
|
||||
* A Sheet is just a grid of images with a predefined size for each cell. Arbitrary sized cells not supported.
|
||||
|
|
@ -56,7 +58,7 @@ void PLAY_TEST(Animation &anim) {
|
|||
*
|
||||
* I like the ganim8 onLoop concept, just a callback that says what to do when the animation has looped.
|
||||
*/
|
||||
TEST_CASE("new animation system", "[animation-new]") {
|
||||
void test_new_animation_system() {
|
||||
textures::init();
|
||||
sound::init();
|
||||
sound::mute(true);
|
||||
|
|
@ -67,7 +69,7 @@ TEST_CASE("new animation system", "[animation-new]") {
|
|||
// test that toggled works
|
||||
anim.transform.toggled = true;
|
||||
PLAY_TEST(anim);
|
||||
REQUIRE(anim.sequence.current == anim.sequence.frames.size() - 1);
|
||||
CHECK(anim.sequence.current == anim.sequence.frames.size() - 1);
|
||||
anim.transform.toggled = false;
|
||||
|
||||
bool onLoop_ran = false;
|
||||
|
|
@ -78,7 +80,7 @@ TEST_CASE("new animation system", "[animation-new]") {
|
|||
};
|
||||
|
||||
PLAY_TEST(anim);
|
||||
REQUIRE(onLoop_ran == true);
|
||||
CHECK(onLoop_ran == true);
|
||||
|
||||
// only runs twice
|
||||
anim.onLoop = [](auto& seq, auto& tr) -> bool {
|
||||
|
|
@ -92,11 +94,11 @@ TEST_CASE("new animation system", "[animation-new]") {
|
|||
};
|
||||
|
||||
PLAY_TEST(anim);
|
||||
REQUIRE(anim.sequence.loop_count == 2);
|
||||
}
|
||||
CHECK(anim.sequence.loop_count == 2);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("confirm frame sequencing works", "[animation-new]") {
|
||||
void test_confirm_frame_sequencing_works() {
|
||||
textures::init();
|
||||
sound::init();
|
||||
sound::mute(true);
|
||||
|
|
@ -125,11 +127,11 @@ TEST_CASE("confirm frame sequencing works", "[animation-new]") {
|
|||
FAKE_RENDER();
|
||||
}
|
||||
|
||||
REQUIRE(loop_ran == true);
|
||||
REQUIRE(anim.playing == false);
|
||||
}
|
||||
CHECK(loop_ran == true);
|
||||
CHECK(anim.playing == false);
|
||||
}
|
||||
|
||||
TEST_CASE("confirm transition changes work", "[animation-new]") {
|
||||
void test_confirm_transition_changes_work() {
|
||||
textures::init();
|
||||
sound::init();
|
||||
sound::mute(true);
|
||||
|
|
@ -141,10 +143,10 @@ TEST_CASE("confirm transition changes work", "[animation-new]") {
|
|||
auto anim = load_animation("rat_king_boss");
|
||||
|
||||
// also testing that onFrame being null means it's not run
|
||||
REQUIRE(anim.onFrame == nullptr);
|
||||
CHECK(anim.onFrame == nullptr);
|
||||
|
||||
anim.play();
|
||||
REQUIRE(anim.playing == true);
|
||||
CHECK(anim.playing == true);
|
||||
|
||||
while(anim.playing) {
|
||||
anim.update();
|
||||
|
|
@ -152,12 +154,12 @@ TEST_CASE("confirm transition changes work", "[animation-new]") {
|
|||
FAKE_RENDER();
|
||||
}
|
||||
|
||||
REQUIRE(anim.playing == false);
|
||||
REQUIRE(pos == sf::Vector2f{100, 100});
|
||||
REQUIRE(scale != sf::Vector2f{0,0});
|
||||
}
|
||||
CHECK(anim.playing == false);
|
||||
CHECK(pos == sf::Vector2f{100, 100});
|
||||
CHECK(scale != sf::Vector2f{0,0});
|
||||
}
|
||||
|
||||
TEST_CASE("playing with delta time", "[animation-new]") {
|
||||
void test_playing_with_delta_time() {
|
||||
animation::Timer timer;
|
||||
timer.start();
|
||||
|
||||
|
|
@ -166,4 +168,17 @@ TEST_CASE("playing with delta time", "[animation-new]") {
|
|||
auto [tick_count, alpha] = timer.commit();
|
||||
// fmt::println("tick: {}, alpha: {}", tick_count, alpha);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fuc2::Set TESTS{
|
||||
.name="ai functionality",
|
||||
.tests={
|
||||
TEST(test_new_animation_system),
|
||||
TEST(test_confirm_frame_sequencing_works),
|
||||
TEST(test_confirm_transition_changes_work),
|
||||
TEST(test_playing_with_delta_time),
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,18 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
#include <fuc2/testing.hpp>
|
||||
|
||||
using namespace fmt;
|
||||
using namespace fuc2;
|
||||
|
||||
TEST_CASE("base test", "[base]") {
|
||||
REQUIRE(1 == 1);
|
||||
namespace base_tests {
|
||||
void test_base_test() {
|
||||
CHECK(1 == 1);
|
||||
}
|
||||
|
||||
fuc2::Set TESTS{
|
||||
.name="base template",
|
||||
.tests={
|
||||
TEST(test_base_test),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include "game/rituals.hpp"
|
||||
|
|
@ -11,12 +10,15 @@
|
|||
#include "game/components.hpp"
|
||||
#include "ai/ai.hpp"
|
||||
#include "graphics/palette.hpp"
|
||||
#include <fuc2/testing.hpp>
|
||||
|
||||
using namespace combat;
|
||||
using namespace boss;
|
||||
using namespace components;
|
||||
using namespace fuc2;
|
||||
|
||||
TEST_CASE("battle operations fantasy", "[fail]") {
|
||||
namespace battle_tests {
|
||||
void test_battle_operations_fantasy() {
|
||||
ai::reset();
|
||||
ai::init("ai");
|
||||
|
||||
|
|
@ -83,7 +85,7 @@ TEST_CASE("battle operations fantasy", "[fail]") {
|
|||
case BattleHostState::disagree:
|
||||
// fmt::println("REBELIOUS ACT: {}", wants_to);
|
||||
battle.clear_requests();
|
||||
REQUIRE(battle.$player_requests.size() == 0);
|
||||
CHECK(battle.$player_requests.size() == 0);
|
||||
break;
|
||||
case BattleHostState::not_host:
|
||||
if(wants_to == "kill_enemy") {
|
||||
|
|
@ -96,14 +98,14 @@ TEST_CASE("battle operations fantasy", "[fail]") {
|
|||
}
|
||||
}
|
||||
|
||||
REQUIRE(!battle.next());
|
||||
CHECK(!battle.next());
|
||||
dbc::check(battle_count < 1000, "infinite battle loop");
|
||||
}
|
||||
|
||||
dbc::check(host_combat_loop < 1000, "infinite host combat loop, host won't die!");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("boss/systems.cpp works", "[combat-battle]") {
|
||||
void test_boss_systems_work() {
|
||||
components::init();
|
||||
gui::Backend backend;
|
||||
guecs::init(&backend);
|
||||
|
|
@ -131,7 +133,7 @@ TEST_CASE("boss/systems.cpp works", "[combat-battle]") {
|
|||
battle.player_request("kill_enemy");
|
||||
int pending_ap = battle.player_pending_ap();
|
||||
|
||||
REQUIRE(pending_ap < host_combat.ap);
|
||||
CHECK(pending_ap < host_combat.ap);
|
||||
|
||||
System::plan_battle(battle, fight->$world, fight->$boss_id);
|
||||
|
||||
|
|
@ -140,5 +142,14 @@ TEST_CASE("boss/systems.cpp works", "[combat-battle]") {
|
|||
System::combat(*action, fight->$world, fight->$boss_id, 0);
|
||||
}
|
||||
|
||||
REQUIRE(host_combat.ap == pending_ap);
|
||||
CHECK(host_combat.ap == pending_ap);
|
||||
}
|
||||
|
||||
fuc2::Set TESTS{
|
||||
.name="battle tests",
|
||||
.tests={
|
||||
TEST(test_battle_operations_fantasy),
|
||||
TEST(test_boss_systems_work),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,17 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include <fuc2/testing.hpp>
|
||||
|
||||
TEST_CASE("view based camera system", "[camera]") {
|
||||
REQUIRE(1 == 1);
|
||||
using namespace fuc2;
|
||||
|
||||
namespace camera_tests {
|
||||
void test_view_based_camera_system() {
|
||||
CHECK(1 == 1);
|
||||
}
|
||||
|
||||
fuc2::Set TESTS{
|
||||
.name="camera tests (EMPTY!)",
|
||||
.tests={
|
||||
TEST(test_view_based_camera_system),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <fuc2/testing.hpp>
|
||||
#include "game/components.hpp"
|
||||
#include "algos/dinkyecs.hpp"
|
||||
#include "game/config.hpp"
|
||||
|
|
@ -7,7 +7,10 @@
|
|||
using namespace components;
|
||||
using namespace DinkyECS;
|
||||
|
||||
TEST_CASE("confirm component loading works", "[components]") {
|
||||
using namespace fuc2;
|
||||
|
||||
namespace component_tests {
|
||||
void test_confirm_component_loading_works() {
|
||||
std::vector<std::string> test_list{
|
||||
"assets/enemies.json", "assets/items.json", "assets/devices.json"};
|
||||
|
||||
|
|
@ -24,12 +27,12 @@ TEST_CASE("confirm component loading works", "[components]") {
|
|||
auto ent = world.entity();
|
||||
components::configure_entity(world, ent, components);
|
||||
auto tile = components::get<Tile>(components[0]);
|
||||
REQUIRE(tile.display != L' ');
|
||||
CHECK(tile.display != L' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("make sure json_mods works", "[components]") {
|
||||
void test_make_sure_json_mods_works() {
|
||||
auto config = settings::get("bosses");
|
||||
// this confirms that loading something with an optional
|
||||
// field works with the json conversions in json_mods.hpp
|
||||
|
|
@ -47,4 +50,13 @@ TEST_CASE("make sure json_mods works", "[components]") {
|
|||
|
||||
components::configure_entity(world, rat_king, config["RAT_KING"]["components"]);
|
||||
auto boss = world.get<AnimatedScene>(rat_king);
|
||||
}
|
||||
|
||||
fuc2::Set TESTS{
|
||||
.name="components",
|
||||
.tests={
|
||||
TEST(test_make_sure_json_mods_works),
|
||||
TEST(test_confirm_component_loading_works),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,28 +1,40 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <fuc2/testing.hpp>
|
||||
#include "game/config.hpp"
|
||||
#include <iostream>
|
||||
|
||||
TEST_CASE("confirm basic config loader ops", "[config]") {
|
||||
using namespace fuc2;
|
||||
|
||||
namespace config_tests {
|
||||
void test_confirm_basic_config_loader_ops() {
|
||||
settings::Config::set_base_dir("./");
|
||||
auto config = settings::get("devices");
|
||||
auto data_list = config.json();
|
||||
auto the_keys = config.keys();
|
||||
|
||||
REQUIRE(the_keys.size() > 0);
|
||||
CHECK(the_keys.size() > 0);
|
||||
|
||||
for(auto& [key, data] : data_list.items()) {
|
||||
auto wide1 = config.wstring(key, "name");
|
||||
auto& comps = data["components"];
|
||||
|
||||
for(auto& comp_data : comps) {
|
||||
REQUIRE(comp_data.contains("_type"));
|
||||
CHECK(comp_data.contains("_type"));
|
||||
}
|
||||
}
|
||||
|
||||
auto indexed = settings::get("tests/config_test.json");
|
||||
auto& test_0 = indexed[0];
|
||||
REQUIRE(test_0["test"] == 0);
|
||||
CHECK(test_0["test"] == 0);
|
||||
|
||||
auto& test_1 = indexed[1];
|
||||
REQUIRE(test_1["test"] == 1);
|
||||
CHECK(test_1["test"] == 1);
|
||||
}
|
||||
|
||||
fuc2::Set TESTS{
|
||||
.name="config",
|
||||
.tests={
|
||||
TEST(test_confirm_basic_config_loader_ops),
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <fuc2/testing.hpp>
|
||||
#include "dbc.hpp"
|
||||
|
||||
using namespace dbc;
|
||||
|
||||
TEST_CASE("basic feature tests", "[dbc]") {
|
||||
namespace dbc_tests {
|
||||
void test_basic_dbc_features() {
|
||||
log("Logging a message.");
|
||||
|
||||
pre("confirm positive cases work", 1 == 1);
|
||||
|
|
@ -15,4 +16,13 @@ TEST_CASE("basic feature tests", "[dbc]") {
|
|||
post("confirm postitive post with lamdba", [&]{ return 1 == 1;});
|
||||
|
||||
check(1 == 1, "one equals 1");
|
||||
}
|
||||
|
||||
fuc2::Set TESTS{
|
||||
.name="dbc",
|
||||
.tests={
|
||||
TEST(test_basic_dbc_features),
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <fuc2/testing.hpp>
|
||||
#include "algos/dinkyecs.hpp"
|
||||
#include <iostream>
|
||||
#include <fmt/core.h>
|
||||
|
|
@ -6,44 +6,46 @@
|
|||
using namespace fmt;
|
||||
using DinkyECS::Entity;
|
||||
using std::string;
|
||||
using namespace fuc2;
|
||||
|
||||
struct Point {
|
||||
namespace dinkyecs_tests {
|
||||
struct Point {
|
||||
size_t x;
|
||||
size_t y;
|
||||
};
|
||||
};
|
||||
|
||||
struct Player {
|
||||
struct Player {
|
||||
string name;
|
||||
Entity eid;
|
||||
};
|
||||
};
|
||||
|
||||
struct Position {
|
||||
struct Position {
|
||||
Point location;
|
||||
};
|
||||
};
|
||||
|
||||
struct Motion {
|
||||
struct Motion {
|
||||
int dx;
|
||||
int dy;
|
||||
bool random=false;
|
||||
};
|
||||
};
|
||||
|
||||
struct Velocity {
|
||||
struct Velocity {
|
||||
double x, y;
|
||||
};
|
||||
};
|
||||
|
||||
struct Gravity {
|
||||
struct Gravity {
|
||||
double level;
|
||||
};
|
||||
};
|
||||
|
||||
struct DaGUI {
|
||||
struct DaGUI {
|
||||
int event;
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
/*
|
||||
* Using a function catches instances where I'm not copying
|
||||
* the data into the world.
|
||||
*/
|
||||
void configure(DinkyECS::World &world, Entity &test) {
|
||||
void configure(DinkyECS::World &world, Entity &test) {
|
||||
println("---Configuring the base system.");
|
||||
Entity test2 = world.entity();
|
||||
|
||||
|
|
@ -69,83 +71,87 @@ void configure(DinkyECS::World &world, Entity &test) {
|
|||
|
||||
println("--- Creating facts (singletons)");
|
||||
world.set_the<Gravity>({0.9});
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("confirm ECS system works", "[ecs]") {
|
||||
void test_confirm_ECS_system_works() {
|
||||
DinkyECS::World world;
|
||||
Entity test = world.entity();
|
||||
|
||||
configure(world, test);
|
||||
|
||||
Position &pos = world.get<Position>(test);
|
||||
REQUIRE(pos.location.x == 10);
|
||||
REQUIRE(pos.location.y == 20);
|
||||
CHECK(pos.location.x == 10);
|
||||
CHECK(pos.location.y == 20);
|
||||
|
||||
Velocity &vel = world.get<Velocity>(test);
|
||||
REQUIRE(vel.x == 1);
|
||||
REQUIRE(vel.y == 2);
|
||||
CHECK(vel.x == 1);
|
||||
CHECK(vel.y == 2);
|
||||
|
||||
world.query<Position>([](const auto &ent, auto &pos) {
|
||||
REQUIRE(ent > 0);
|
||||
REQUIRE(pos.location.x >= 0);
|
||||
REQUIRE(pos.location.y >= 0);
|
||||
CHECK(ent > 0);
|
||||
CHECK(pos.location.x >= 0);
|
||||
CHECK(pos.location.y >= 0);
|
||||
});
|
||||
|
||||
world.query<Velocity>([](const auto &ent, auto &vel) {
|
||||
REQUIRE(ent > 0);
|
||||
REQUIRE(vel.x >= 0);
|
||||
REQUIRE(vel.y >= 0);
|
||||
CHECK(ent > 0);
|
||||
CHECK(vel.x >= 0);
|
||||
CHECK(vel.y >= 0);
|
||||
});
|
||||
|
||||
println("--- Manually get the velocity in position system:");
|
||||
world.query<Position>([&](const auto &ent, auto &pos) {
|
||||
Velocity &vel = world.get<Velocity>(ent);
|
||||
|
||||
REQUIRE(ent > 0);
|
||||
REQUIRE(pos.location.x >= 0);
|
||||
REQUIRE(pos.location.y >= 0);
|
||||
REQUIRE(ent > 0);
|
||||
REQUIRE(vel.x >= 0);
|
||||
REQUIRE(vel.y >= 0);
|
||||
CHECK(ent > 0);
|
||||
CHECK(pos.location.x >= 0);
|
||||
CHECK(pos.location.y >= 0);
|
||||
CHECK(ent > 0);
|
||||
CHECK(vel.x >= 0);
|
||||
CHECK(vel.y >= 0);
|
||||
});
|
||||
|
||||
println("--- Query only entities with Position and Velocity:");
|
||||
world.query<Position, Velocity>([&](const auto &ent, auto &pos, auto &vel) {
|
||||
Gravity &grav = world.get_the<Gravity>();
|
||||
REQUIRE(grav.level <= 1.0f);
|
||||
REQUIRE(grav.level > 0.5f);
|
||||
REQUIRE(ent > 0);
|
||||
REQUIRE(pos.location.x >= 0);
|
||||
REQUIRE(pos.location.y >= 0);
|
||||
REQUIRE(ent > 0);
|
||||
REQUIRE(vel.x >= 0);
|
||||
REQUIRE(vel.y >= 0);
|
||||
CHECK(grav.level <= 1.0f);
|
||||
CHECK(grav.level > 0.5f);
|
||||
CHECK(ent > 0);
|
||||
CHECK(pos.location.x >= 0);
|
||||
CHECK(pos.location.y >= 0);
|
||||
CHECK(ent > 0);
|
||||
CHECK(vel.x >= 0);
|
||||
CHECK(vel.y >= 0);
|
||||
});
|
||||
|
||||
// now remove Velocity
|
||||
REQUIRE(world.has<Velocity>(test));
|
||||
CHECK(world.has<Velocity>(test));
|
||||
world.remove<Velocity>(test);
|
||||
REQUIRE_THROWS(world.get<Velocity>(test));
|
||||
REQUIRE(!world.has<Velocity>(test));
|
||||
|
||||
BLOWS_UP([&]() {
|
||||
world.get<Velocity>(test);
|
||||
});
|
||||
|
||||
CHECK(!world.has<Velocity>(test));
|
||||
|
||||
println("--- After remove test, should only result in test2:");
|
||||
world.query<Position, Velocity>([&](const auto &ent, auto &pos, auto &vel) {
|
||||
auto &in_position = world.get<Position>(ent);
|
||||
auto &in_velocity = world.get<Velocity>(ent);
|
||||
REQUIRE(pos.location.x >= 0);
|
||||
REQUIRE(pos.location.y >= 0);
|
||||
REQUIRE(in_position.location.x == pos.location.x);
|
||||
REQUIRE(in_position.location.y == pos.location.y);
|
||||
REQUIRE(in_velocity.x == vel.x);
|
||||
REQUIRE(in_velocity.y == vel.y);
|
||||
CHECK(pos.location.x >= 0);
|
||||
CHECK(pos.location.y >= 0);
|
||||
CHECK(in_position.location.x == pos.location.x);
|
||||
CHECK(in_position.location.y == pos.location.y);
|
||||
CHECK(in_velocity.x == vel.x);
|
||||
CHECK(in_velocity.y == vel.y);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
enum GUIEvent {
|
||||
enum GUIEvent {
|
||||
HIT, MISS
|
||||
};
|
||||
};
|
||||
|
||||
TEST_CASE("confirm that the event system works", "[ecs]") {
|
||||
void test_confirm_that_the_event_system_works() {
|
||||
DinkyECS::World world;
|
||||
DinkyECS::Entity player = world.entity();
|
||||
|
||||
|
|
@ -158,18 +164,18 @@ TEST_CASE("confirm that the event system works", "[ecs]") {
|
|||
// just count down and should get the same number
|
||||
while(world.has_event<GUIEvent>()) {
|
||||
auto [event, entity, data] = world.recv<GUIEvent>();
|
||||
REQUIRE(event == GUIEvent::HIT);
|
||||
REQUIRE(entity == player);
|
||||
CHECK(event == GUIEvent::HIT);
|
||||
CHECK(entity == player);
|
||||
auto &str_data = std::any_cast<string&>(data);
|
||||
REQUIRE(string{"hello"} == str_data);
|
||||
CHECK(string{"hello"} == str_data);
|
||||
i--;
|
||||
}
|
||||
|
||||
REQUIRE(i == 0);
|
||||
}
|
||||
CHECK(i == 0);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("confirm copying and constants", "[ecs-constants]") {
|
||||
void test_confirm_copying_and_constants() {
|
||||
DinkyECS::World world1;
|
||||
|
||||
Player player_info{"Zed", world1.entity()};
|
||||
|
|
@ -184,19 +190,19 @@ TEST_CASE("confirm copying and constants", "[ecs-constants]") {
|
|||
auto &test1 = world1.get<Position>(player_info.eid);
|
||||
auto &test2 = world2.get<Position>(player_info.eid);
|
||||
|
||||
REQUIRE(test2.location.x == test1.location.x);
|
||||
REQUIRE(test2.location.y == test1.location.y);
|
||||
CHECK(test2.location.x == test1.location.x);
|
||||
CHECK(test2.location.y == test1.location.y);
|
||||
|
||||
// check for accidental reference
|
||||
test1.location.x = 100;
|
||||
REQUIRE(test2.location.x != test1.location.x);
|
||||
CHECK(test2.location.x != test1.location.x);
|
||||
|
||||
// test the facts copy over
|
||||
auto &player2 = world2.get_the<Player>();
|
||||
REQUIRE(player2.eid == player_info.eid);
|
||||
}
|
||||
CHECK(player2.eid == player_info.eid);
|
||||
}
|
||||
|
||||
TEST_CASE("can destroy all entity", "[ecs-destroy]") {
|
||||
void test_can_destroy_all_entity() {
|
||||
DinkyECS::World world;
|
||||
auto entity = world.entity();
|
||||
|
||||
|
|
@ -206,7 +212,18 @@ TEST_CASE("can destroy all entity", "[ecs-destroy]") {
|
|||
|
||||
world.destroy(entity);
|
||||
|
||||
REQUIRE(!world.has<Velocity>(entity));
|
||||
REQUIRE(!world.has<Gravity>(entity));
|
||||
REQUIRE(!world.has<Motion>(entity));
|
||||
CHECK(!world.has<Velocity>(entity));
|
||||
CHECK(!world.has<Gravity>(entity));
|
||||
CHECK(!world.has<Motion>(entity));
|
||||
}
|
||||
|
||||
fuc2::Set TESTS{
|
||||
.name="dinkyecs",
|
||||
.tests={
|
||||
TEST(test_confirm_ECS_system_works),
|
||||
TEST(test_confirm_that_the_event_system_works),
|
||||
TEST(test_confirm_copying_and_constants),
|
||||
TEST(test_can_destroy_all_entity),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
25
tests/main.cpp
Normal file
25
tests/main.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include <fuc2/run.hpp>
|
||||
|
||||
using namespace fuc2;
|
||||
|
||||
TEST_SET(ai_tests);
|
||||
TEST_SET(animation_tests);
|
||||
TEST_SET(base_tests);
|
||||
TEST_SET(battle_tests);
|
||||
TEST_SET(camera_tests);
|
||||
TEST_SET(component_tests);
|
||||
TEST_SET(config_tests);
|
||||
TEST_SET(dbc_tests);
|
||||
TEST_SET(dinkyecs_tests);
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
run(ai_tests::TESTS);
|
||||
run(animation_tests::TESTS);
|
||||
run(base_tests::TESTS);
|
||||
run(battle_tests::TESTS);
|
||||
run(camera_tests::TESTS);
|
||||
run(component_tests::TESTS);
|
||||
run(config_tests::TESTS);
|
||||
run(dbc_tests::TESTS);
|
||||
run(dinkyecs_tests::TESTS);
|
||||
}
|
||||
|
|
@ -1,12 +1,4 @@
|
|||
tests = files(
|
||||
'animation.cpp',
|
||||
'base.cpp',
|
||||
'battle.cpp',
|
||||
'camera.cpp',
|
||||
'components.cpp',
|
||||
'config.cpp',
|
||||
'dbc.cpp',
|
||||
'dinkyecs.cpp',
|
||||
'event_router.cpp',
|
||||
'fsm.cpp',
|
||||
'inventory.cpp',
|
||||
|
|
@ -27,6 +19,14 @@ tests = files(
|
|||
)
|
||||
|
||||
fuc2_tests = files(
|
||||
'dinkyecs.cpp',
|
||||
'dbc.cpp',
|
||||
'ai.cpp',
|
||||
'animation.cpp',
|
||||
'base.cpp',
|
||||
'battle.cpp',
|
||||
'camera.cpp',
|
||||
'components.cpp',
|
||||
'config.cpp',
|
||||
'main.cpp'
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue