diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index cfa57f3705d98fa968cec090750e71ef582e1a05..bb27b9e14a494b55fa7043b836c88a9125ad0e9f 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -88,6 +88,7 @@ ogs_add_executable(testrunner ${TEST_SOURCES}) target_sources( testrunner PRIVATE ProcessLib/Graph/TestGet.cpp ProcessLib/Graph/TestApply.cpp + ProcessLib/Graph/TestCheckEvalOrderRT.cpp ) target_link_libraries( diff --git a/Tests/ProcessLib/Graph/TestCheckEvalOrderRT.cpp b/Tests/ProcessLib/Graph/TestCheckEvalOrderRT.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f4262c3ac86d463a122103a42cf4cff9cfb35055 --- /dev/null +++ b/Tests/ProcessLib/Graph/TestCheckEvalOrderRT.cpp @@ -0,0 +1,164 @@ +/** + * \file + * \copyright + * Copyright (c) 2012-2024, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#include <gtest/gtest.h> + +#include "ProcessLib/Graph/CheckEvalOrderRT.h" + +namespace TestCheckEvalOrderRT +{ +struct NoOp +{ + void eval(); +}; + +struct OutD +{ + void eval(double&) {} +}; + +struct InD +{ + void eval(double const&) {} +}; + +struct InSOutD +{ + void eval(double&, std::string const&) {} +}; + +struct OutCD +{ + void eval(double&, char&) {} +}; + +struct InCSOutIU +{ + void eval(char const&, unsigned&, std::string const&, int&); +}; + +struct InIU +{ + void eval(unsigned const&, int const&); +}; +} // namespace TestCheckEvalOrderRT + +TEST(ProcessLib_Graph_CheckEvalOrderRT, Success) +{ + using namespace TestCheckEvalOrderRT; + + { + using Models = std::tuple<NoOp>; + using Inputs = std::tuple<>; + + ASSERT_TRUE( + (ProcessLib::Graph::isEvalOrderCorrectRT<Models, Inputs>())); + } + + { + using Models = std::tuple<OutD>; + using Inputs = std::tuple<>; + + ASSERT_TRUE( + (ProcessLib::Graph::isEvalOrderCorrectRT<Models, Inputs>())); + } + + { + using Models = std::tuple<InD>; + using Inputs = std::tuple<double>; + + ASSERT_TRUE( + (ProcessLib::Graph::isEvalOrderCorrectRT<Models, Inputs>())); + } + + { + using Models = std::tuple<OutD, InD>; + using Inputs = std::tuple<>; + + ASSERT_TRUE( + (ProcessLib::Graph::isEvalOrderCorrectRT<Models, Inputs>())); + } + + { + using Models = std::tuple<InSOutD, NoOp, InD>; + using Inputs = std::tuple<std::string>; + + ASSERT_TRUE( + (ProcessLib::Graph::isEvalOrderCorrectRT<Models, Inputs>())); + } + + { + using Models = std::tuple<OutCD, NoOp, InCSOutIU, InD, InIU>; + using Inputs = std::tuple<std::string>; + + ASSERT_TRUE( + (ProcessLib::Graph::isEvalOrderCorrectRT<Models, Inputs>())); + } + + { + using Models = std::tuple<NoOp, OutCD, InD, InCSOutIU, InIU>; + using Inputs = std::tuple<std::string>; + + ASSERT_TRUE( + (ProcessLib::Graph::isEvalOrderCorrectRT<Models, Inputs>())); + } +} + +TEST(ProcessLib_Graph_CheckEvalOrderRT, Fail) +{ + using namespace TestCheckEvalOrderRT; + + { + using Models = std::tuple<InD>; + using Inputs = std::tuple<>; + + ASSERT_FALSE( + (ProcessLib::Graph::isEvalOrderCorrectRT<Models, Inputs>())) + << "Expected to fail since the required double value is not " + "provided as an input."; + } + + { + using Models = std::tuple<InD, OutD>; + using Inputs = std::tuple<>; + + ASSERT_FALSE( + (ProcessLib::Graph::isEvalOrderCorrectRT<Models, Inputs>())) + << "Expected to fail: double value is consumed before being " + "computed."; + } + + { + using Models = std::tuple<NoOp, InSOutD, OutD, InD>; + using Inputs = std::tuple<std::string>; + + ASSERT_FALSE( + (ProcessLib::Graph::isEvalOrderCorrectRT<Models, Inputs>())) + << "Expected to fail: double value has two producers."; + } + + { + using Models = std::tuple<OutCD, InIU, NoOp, InCSOutIU, InD>; + using Inputs = std::tuple<std::string>; + + ASSERT_FALSE( + (ProcessLib::Graph::isEvalOrderCorrectRT<Models, Inputs>())) + << "Expected to fail: wrong evaluation order."; + } + + { + using Models = std::tuple<NoOp, OutCD, InD, OutD, InCSOutIU, InIU>; + using Inputs = std::tuple<std::string>; + + ASSERT_FALSE( + (ProcessLib::Graph::isEvalOrderCorrectRT<Models, Inputs>())) + << "Expected to fail: double value has two producers."; + } +}