test(tests): added test suite

The test suite is extensive. Note that LLMs were used to aid in the development of the test suite. All LLM generated code was manually reviewed.
This commit is contained in:
2026-11-09 13:53:17 -05:00
parent 74e55a6859
commit cb20faeb3d
202 changed files with 35505 additions and 953 deletions

View File

@@ -0,0 +1,62 @@
#include <array>
#include <catch2/catch_test_macros.hpp>
#include "serif/utils/dependencies/dependencies.hpp"
namespace
{
namespace dependencies = serif::utils::dependencies;
struct Source
{
};
template <int Index>
struct Stage
{
};
}
TEST_CASE("Requested dependency branches follow topology independently of declaration order", "[unit][utils][dependencies]")
{
int input = 2;
const auto context = dependencies::make_dependency_context(dependencies::borrow<Source>(input));
std::array<int, 8> calls{};
const auto branch = [&]<int Result, int Input>()
{
return dependencies::make_computation<Stage<Result>, dependencies::InputList<Stage<Input>>>([&](const int value)
{
++calls[Result];
return value + Result;
});
};
const auto graph = dependencies::make_computation_graph(
branch.template operator()<4, 2>(),
dependencies::make_computation<Stage<6>, dependencies::InputList<Stage<4>, Stage<5>>>([&](const int left, const int right)
{
++calls[6];
return left + right;
}),
branch.template operator()<2, 1>(),
branch.template operator()<7, 3>(),
branch.template operator()<5, 3>(),
branch.template operator()<1, 0>(),
dependencies::make_computation<Stage<0>, dependencies::InputList<Source>>([&](const int value)
{
++calls[0];
return value;
}),
branch.template operator()<3, 1>());
auto cache = dependencies::make_computation_cache(graph, context);
REQUIRE(cache.try_prepare(context, dependencies::RequestedResults<Stage<4>>{}));
CHECK(cache.get<Stage<4>>() == 9);
CHECK(calls == std::array{1, 1, 1, 0, 1, 0, 0, 0});
REQUIRE(cache.try_prepare(context, dependencies::RequestedResults<Stage<6>>{}));
CHECK(cache.get<Stage<6>>() == 20);
CHECK(calls == std::array{1, 1, 1, 1, 1, 1, 1, 0});
input = 5;
REQUIRE(cache.try_prepare(context, dependencies::RequestedResults<Stage<4>, Stage<7>>{}));
CHECK(cache.get<Stage<4>>() == 12);
CHECK(cache.get<Stage<7>>() == 16);
CHECK(calls == std::array{2, 2, 2, 2, 2, 1, 1, 1});
CHECK(cache.report().status<Stage<5>>() == dependencies::PreparationStatus::not_required);
CHECK(cache.report().status<Stage<6>>() == dependencies::PreparationStatus::not_required);
}