Skip to content
Snippets Groups Projects
Commit bb81230e authored by Dmitri Naumov's avatar Dmitri Naumov Committed by Christoph Lehmann
Browse files

[T] Add a failing cyclic test for named functions.

parent 982c583d
No related branches found
No related tags found
No related merge requests found
......@@ -60,6 +60,21 @@ private:
double _z;
};
class I : public NumLib::NamedFunctionProvider
{
public:
double i(double arg_x) const
{
return -arg_x;
}
std::vector<NumLib::NamedFunction>
getNamedFunctions() const override
{
return {{"i", {"x"}, BaseLib::easyBind(&I::i, this)}};
}
};
TEST(NumLib, NamedFunctionCaller)
{
F f_inst;
......@@ -93,6 +108,33 @@ TEST(NumLib, NamedFunctionCaller)
EXPECT_EQ(f_inst.f(g_inst.g(x), y), f_caller.call({x, y}));
}
TEST(NumLib, NamedFunctionCallerCyclicGraph)
{
// Construct a cyclic case with f(g(i(f(...), y)))
F f_inst;
G g_inst;
I i_inst;
NumLib::NamedFunctionCaller caller{ "x", "y" };
for (auto&& f_named : f_inst.getNamedFunctions()) {
caller.addNamedFunction(std::move(f_named));
}
for (auto&& g_named : g_inst.getNamedFunctions()) {
caller.addNamedFunction(std::move(g_named));
}
for (auto&& i_named : i_inst.getNamedFunctions()) {
caller.addNamedFunction(std::move(i_named));
}
caller.plug("f", "g_arg", "g");
caller.plug("f", "y", "y");
caller.plug("g", "x", "i");
caller.plug("i", "x", "f");
ASSERT_ANY_THROW(caller.applyPlugs());
}
TEST(NumLib, NamedFunctionNoLeaks)
{
auto num_const = InstanceCounter<H>::getNumberOfConstructions();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment