Fixed bug when generating identical fanouts

This commit is contained in:
2026-05-09 08:36:51 +02:00
parent 2bca2a7554
commit 9ce581b5ce
5 changed files with 366 additions and 11 deletions
+64
View File
@@ -175,6 +175,70 @@ TEST_CASE("static_network: same function distinguished by UniqueTag", "[static_n
net.stop();
}
TEST_CASE("static_network: two independent fan-outs of the same element type are wired independently", "[static_network]") {
// Both src_a and src_b fan out to two consumers each.
// Without the FanoutId fix, both would produce FanoutNode<int,2> — the same
// C++ type — and find_node would wire all four consumers to the first instance.
auto src_a = make_node<add10, "src_a">(8);
auto src_b = make_node<negate_val, "src_b">(8);
auto cA = make_node<increment, "cA">(8);
auto cB = make_node<multiply2, "cB">(8);
auto cC = make_node<multiply3, "cC">(8);
auto cD = make_node<square, "cD">(8);
Channel<int> outA(8), outB(8), outC(8), outD(8);
cA.set_output_channel<0>(&outA);
cB.set_output_channel<0>(&outB);
cC.set_output_channel<0>(&outC);
cD.set_output_channel<0>(&outD);
auto net = make_network(
edge(src_a.output<0>(), cA.input<0>()), // src_a → FanoutNode<int,2,0> → cA, cB
edge(src_a.output<0>(), cB.input<0>()),
edge(src_b.output<0>(), cC.input<0>()), // src_b → FanoutNode<int,2,1> → cC, cD
edge(src_b.output<0>(), cD.input<0>())
);
net.start();
src_a.input_channel<0>().push(0); // 0 → +10=10 → {+1=11, *2=20}
src_b.input_channel<0>().push(5); // 5 → negate=-5 → {*3=-15, ^2=25}
REQUIRE(outA.pop() == 11);
REQUIRE(outB.pop() == 20);
REQUIRE(outC.pop() == -15);
REQUIRE(outD.pop() == 25);
net.stop();
}
TEST_CASE("static_network: code reuse - same function at corresponding stages of parallel branches", "[static_network]") {
// Both branches use increment and multiply2 — code reuse via distinct UniqueTag.
// Topology: src → fanout → { increment(tag=1) → multiply2(tag=1) → outA }
// → { increment(tag=2) → multiply2(tag=2) → outB }
auto src = make_node<add10, "src" >(8);
auto incA = make_node<increment, "inc", 1>(8);
auto mulA = make_node<multiply2, "mul", 1>(8);
auto incB = make_node<increment, "inc", 2>(8);
auto mulB = make_node<multiply2, "mul", 2>(8);
Channel<int> outA(8), outB(8);
mulA.set_output_channel<0>(&outA);
mulB.set_output_channel<0>(&outB);
auto net = make_network(
edge(src.output<0>(), incA.input<0>()),
edge(src.output<0>(), incB.input<0>()),
edge(incA.output<0>(), mulA.input<0>()),
edge(incB.output<0>(), mulB.input<0>())
);
net.start();
src.input_channel<0>().push(0); // 0 → +10=10 → both: +1=11 → *2=22
REQUIRE(outA.pop() == 22);
REQUIRE(outB.pop() == 22);
net.stop();
}
TEST_CASE("static_network: label is accessible as static member", "[static_network]") {
using MyNode = decltype(make_node<increment, "my_node">(5));
REQUIRE(MyNode::label() == "my_node");