This commit is contained in:
Connor
2026-02-20 14:53:28 +09:00
parent cf20ed827e
commit c081aa868f
6 changed files with 336 additions and 10 deletions

View File

@@ -0,0 +1,122 @@
#include <doctest/doctest.h>
#include "Components/Configs/WorldConfig.hpp"
#include "Core/WorldInstance.h"
#include "Components/Support.h"
TEST_SUITE("Support") {
TEST_CASE("grounded support has SupportsAvailable equal to MaxSupport") {
WorldInstance world{ WorldConfig{} };
auto e = world.GetEcsWorld().entity();
Support_Helper(e, { 0, 0 }, 5, true);
auto s = e.get<Support>();
CHECK(s.SupportsAvailable == 5);
}
TEST_CASE("vertical neighbor costs 1 point") {
WorldInstance world{ WorldConfig{} };
auto ground = world.GetEcsWorld().entity();
Support_Helper(ground, { 0, 0 }, 5, true);
auto above = world.GetEcsWorld().entity();
Support_Helper(above, { 0, 1 }, 5);
auto s = above.get<Support>();
CHECK(s.SupportsAvailable == 4);
}
TEST_CASE("horizontal neighbor costs 2 points") {
WorldInstance world{ WorldConfig{} };
auto ground = world.GetEcsWorld().entity();
Support_Helper(ground, { 0, 0 }, 5, true);
auto beside = world.GetEcsWorld().entity();
Support_Helper(beside, { 1, 0 }, 5);
auto s = beside.get<Support>();
CHECK(s.SupportsAvailable == 3);
}
TEST_CASE("floating support has SupportsAvailable zero") {
WorldInstance world{ WorldConfig{} };
auto e = world.GetEcsWorld().entity();
Support_Helper(e, { 5, 5 }, 5);
auto s = e.get<Support>();
CHECK(s.SupportsAvailable == 0);
}
TEST_CASE("CanRemove returns false when removal disconnects a support") {
WorldInstance world{ WorldConfig{} };
// chain: ground(0,0) -> (0,1) -> (0,2)
auto ground = world.GetEcsWorld().entity();
Support_Helper(ground, { 0, 0 }, 5, true);
auto mid = world.GetEcsWorld().entity();
Support_Helper(mid, { 0, 1 }, 5);
auto top = world.GetEcsWorld().entity();
Support_Helper(top, { 0, 2 }, 5);
// removing (0,1) disconnects (0,2)
std::vector<Vector2> toRemove = { { 0, 1 } };
CHECK_FALSE(CanRemove(world.GetEcsWorld(), toRemove));
}
TEST_CASE("CanRemove returns true when removing a leaf node") {
WorldInstance world{ WorldConfig{} };
auto ground = world.GetEcsWorld().entity();
Support_Helper(ground, { 0, 0 }, 5, true);
auto leaf = world.GetEcsWorld().entity();
Support_Helper(leaf, { 0, 1 }, 5);
// removing the leaf leaves only the grounded anchor — valid
std::vector<Vector2> toRemove = { { 0, 1 } };
CHECK(CanRemove(world.GetEcsWorld(), toRemove));
}
TEST_CASE("CanRemove returns false when removal would unsupport a RequiresSupport entity") {
WorldInstance world{ WorldConfig{} };
// grounded support at (0,0); machine one tile above at (0,1)
auto ground = world.GetEcsWorld().entity();
Support_Helper(ground, { 0, 0 }, 5, true);
auto machine = world.GetEcsWorld().entity();
machine.set<TilePosition>({ { 0, 1 } });
machine.add<RequiresSupport>();
// removing the only support at (0,0) leaves the machine at (0,1) unsupported
std::vector<Vector2> toRemove = { { 0, 0 } };
CHECK_FALSE(CanRemove(world.GetEcsWorld(), toRemove));
}
TEST_CASE("CanRemove returns true when RequiresSupport entity still has support") {
WorldInstance world{ WorldConfig{} };
// chain: ground(0,0) -> leaf(0,1); machine one tile above leaf at (0,2)
auto ground = world.GetEcsWorld().entity();
Support_Helper(ground, { 0, 0 }, 5, true);
auto leaf = world.GetEcsWorld().entity();
Support_Helper(leaf, { 0, 1 }, 5);
auto machine = world.GetEcsWorld().entity();
machine.set<TilePosition>({ { 0, 2 } });
machine.add<RequiresSupport>();
// sibling at (1,0) is a horizontal leaf; removing it doesn't affect (0,1)
auto sibling = world.GetEcsWorld().entity();
Support_Helper(sibling, { 1, 0 }, 5);
std::vector<Vector2> toRemove = { { 1, 0 } };
CHECK(CanRemove(world.GetEcsWorld(), toRemove));
}
}