diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index aaace485deb7ed83e66d80c2e75d9bce2cc9bc21..e7665f8944202ff0c139ca1ccce1403026891f50 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -197,6 +197,7 @@ add_executable (mpi_unit_tests test_MeshLineNodeBoundary.cpp test_MeshNodeBoundary.cpp test_MeshNodeInterface.cpp + test_MeshVariant.cpp test_Messenger.cpp test_OFStream.cpp test_ParallelChecker_read.cpp diff --git a/tests/test_MeshVariant.cpp b/tests/test_MeshVariant.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f03f70273b5e03709a49e18d58ce7c8536a563b1 --- /dev/null +++ b/tests/test_MeshVariant.cpp @@ -0,0 +1,98 @@ +#include <catch2/catch_test_macros.hpp> +#include <catch2/matchers/catch_matchers_all.hpp> + +#include <MeshDataBaseForTests.hpp> +#include <mesh/Mesh.hpp> +#include <mesh/MeshVariant.hpp> + +// clazy:excludeall=non-pod-global-static + +TEST_CASE("MeshVariant", "[mesh]") +{ + SECTION("1D") + { + auto mesh_v = MeshDataBaseForTests::get().unordered1DMesh(); + auto mesh = mesh_v->get<Mesh<1>>(); + + const std::string error_msg = + R"(error: invalid mesh type type +- required Mesh<3ul> +- contains Mesh<1ul>)"; + + REQUIRE_THROWS_WITH(mesh_v->get<Mesh<3>>(), error_msg); + + REQUIRE(mesh->id() == mesh_v->id()); + REQUIRE(mesh->numberOfCells() == mesh_v->numberOfCells()); + REQUIRE(mesh->numberOfFaces() == mesh_v->numberOfFaces()); + REQUIRE(mesh->numberOfEdges() == mesh_v->numberOfEdges()); + REQUIRE(mesh->numberOfNodes() == mesh_v->numberOfNodes()); + + { + std::ostringstream os_v; + os_v << *mesh_v; + + std::ostringstream os; + os << *mesh; + + REQUIRE(os_v.str() == os.str()); + } + } + + SECTION("2D") + { + auto mesh_v = MeshDataBaseForTests::get().hybrid2DMesh(); + auto mesh = mesh_v->get<Mesh<2>>(); + + const std::string error_msg = + R"(error: invalid mesh type type +- required Mesh<1ul> +- contains Mesh<2ul>)"; + + REQUIRE_THROWS_WITH(mesh_v->get<Mesh<1>>(), error_msg); + + REQUIRE(mesh->id() == mesh_v->id()); + REQUIRE(mesh->numberOfCells() == mesh_v->numberOfCells()); + REQUIRE(mesh->numberOfFaces() == mesh_v->numberOfFaces()); + REQUIRE(mesh->numberOfEdges() == mesh_v->numberOfEdges()); + REQUIRE(mesh->numberOfNodes() == mesh_v->numberOfNodes()); + + { + std::ostringstream os_v; + os_v << *mesh_v; + + std::ostringstream os; + os << *mesh; + + REQUIRE(os_v.str() == os.str()); + } + } + + SECTION("3D") + { + auto mesh_v = MeshDataBaseForTests::get().hybrid3DMesh(); + auto mesh = mesh_v->get<Mesh<3>>(); + + const std::string error_msg = + R"(error: invalid mesh type type +- required Mesh<2ul> +- contains Mesh<3ul>)"; + + REQUIRE_THROWS_WITH(mesh_v->get<Mesh<2>>(), error_msg); + + REQUIRE(mesh->id() == mesh_v->id()); + REQUIRE(mesh->numberOfCells() == mesh_v->numberOfCells()); + REQUIRE(mesh->numberOfFaces() == mesh_v->numberOfFaces()); + REQUIRE(mesh->numberOfEdges() == mesh_v->numberOfEdges()); + REQUIRE(mesh->numberOfNodes() == mesh_v->numberOfNodes()); + + { + std::ostringstream os_v; + os_v << *mesh_v; + + std::ostringstream os; + os << *mesh; + + REQUIRE(os_v.str() == os.str()); + } + } +}