From ecbe1b99a6510daa309f4902b4c2ad824a571414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com> Date: Thu, 7 Mar 2024 15:02:38 +0100 Subject: [PATCH] Add few tests for MeshVariant --- tests/CMakeLists.txt | 1 + tests/test_MeshVariant.cpp | 98 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 tests/test_MeshVariant.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index aaace485d..e7665f894 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 000000000..f03f70273 --- /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()); + } + } +} -- GitLab