From 8a5669d0d937e175b201afa3687d264010a11d45 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Fri, 13 Dec 2024 16:45:57 -0500 Subject: [PATCH 1/4] cleaning up mah and making attributetype printable --- src/wmtk/attribute/AttributeType.cpp | 24 ++++++++++++++++++++++ src/wmtk/attribute/AttributeType.hpp | 17 +++++++++------ src/wmtk/attribute/CMakeLists.txt | 1 + src/wmtk/attribute/MeshAttributeHandle.hpp | 21 +++++++------------ 4 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 src/wmtk/attribute/AttributeType.cpp diff --git a/src/wmtk/attribute/AttributeType.cpp b/src/wmtk/attribute/AttributeType.cpp new file mode 100644 index 0000000000..a3fc3185ff --- /dev/null +++ b/src/wmtk/attribute/AttributeType.cpp @@ -0,0 +1,24 @@ +#include "AttributeType.hpp" +namespace wmtk::attribute { +const std::string_view attribute_type_name(AttributeType pt) { + + switch(pt) { + case AttributeType::Char: + return attribute_type_traits::name; + case AttributeType::Int64: + return attribute_type_traits::name; + case AttributeType::Double: + return attribute_type_traits::name; + case AttributeType::Rational: + return attribute_type_traits::name; + default: + break; + } + return ""; +} + +const std::string_view attribute_type_traits::name = "Rational"; +const std::string_view attribute_type_traits::name = "Double"; +const std::string_view attribute_type_traits::name = "Int64"; +const std::string_view attribute_type_traits::name = "Char"; +} diff --git a/src/wmtk/attribute/AttributeType.hpp b/src/wmtk/attribute/AttributeType.hpp index 3cccfddf19..c7e3938f50 100644 --- a/src/wmtk/attribute/AttributeType.hpp +++ b/src/wmtk/attribute/AttributeType.hpp @@ -5,32 +5,36 @@ namespace wmtk::attribute { enum class AttributeType { Char = 0, Int64 = 1, Double = 2, Rational = 3 }; template -struct type_from_attribute_type_enum +struct attribute_type_traits { }; template <> -struct type_from_attribute_type_enum +struct attribute_type_traits { using type = char; + const static std::string_view name; }; template <> -struct type_from_attribute_type_enum +struct attribute_type_traits { using type = double; + const static std::string_view name; }; template <> -struct type_from_attribute_type_enum +struct attribute_type_traits { using type = int64_t; + const static std::string_view name; }; template <> -struct type_from_attribute_type_enum +struct attribute_type_traits { using type = wmtk::Rational; + const static std::string_view name; }; template -using type_from_attribute_type_enum_t = typename type_from_attribute_type_enum::type; +using type_from_attribute_type_enum_t = typename attribute_type_traits::type; template inline constexpr auto attribute_type_enum_from_type() -> AttributeType @@ -53,4 +57,5 @@ inline constexpr auto attribute_type_enum_from_type() -> AttributeType return AttributeType::Char; } } +const std::string_view attribute_type_name(AttributeType pt); } // namespace wmtk::attribute diff --git a/src/wmtk/attribute/CMakeLists.txt b/src/wmtk/attribute/CMakeLists.txt index cd8f3506ca..7b2d12439b 100644 --- a/src/wmtk/attribute/CMakeLists.txt +++ b/src/wmtk/attribute/CMakeLists.txt @@ -35,6 +35,7 @@ set(SRC_FILES Accessor.hpp AttributeType.hpp + AttributeType.cpp ) target_sources(wildmeshing_toolkit PRIVATE ${SRC_FILES}) diff --git a/src/wmtk/attribute/MeshAttributeHandle.hpp b/src/wmtk/attribute/MeshAttributeHandle.hpp index 5faf2539e4..7c895088f0 100644 --- a/src/wmtk/attribute/MeshAttributeHandle.hpp +++ b/src/wmtk/attribute/MeshAttributeHandle.hpp @@ -10,6 +10,7 @@ #include #include +#include namespace wmtk { class Mesh; @@ -76,21 +77,13 @@ class MeshAttributeHandle bool operator==(const MeshAttributeHandle& o) const { -#if defined(MTAO_DEBUG_MESH_COMP) - std::visit( - [&](const auto& h, const auto& oh) { - spdlog::warn( - "{} {} == {} {}", - std::string(h), - fmt::ptr(m_mesh), - std::string(oh), - fmt::ptr(m_mesh)); - }, - m_handle, - o.m_handle); -#endif - return m_handle == o.m_handle && m_mesh == o.m_mesh; + return std::tie(m_mesh, m_handle) == std::tie(o.m_mesh, o.m_handle); } + bool operator<(const MeshAttributeHandle& o) const + { + return std::tie(m_mesh, m_handle) < std::tie(o.m_mesh, o.m_handle); + } + // reutrns if the target mesh is the same as the one represented in the handle bool is_same_mesh(const Mesh&) const; From 09d6105c5ca7800570120b4da5ab12216fd48c31 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Sat, 14 Dec 2024 20:11:24 -0500 Subject: [PATCH 2/4] adding test for attribute type name functions --- components/CMakeLists.txt | 4 +++- components/cmake/add_component_test.cmake | 2 +- components/multimesh/CMakeLists.txt | 2 ++ tests/attributes/CMakeLists.txt | 2 ++ tests/attributes/attribute_type.cpp | 18 ++++++++++++++++++ 5 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 tests/attributes/attribute_type.cpp diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index c749617482..88ff42b97c 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -8,7 +8,9 @@ include(add_component_test) # wmtk::component_utils add_subdirectory(utils) -if(WILDMESHING_TOOLKIT_TOPLEVEL_PROJECT) +option(WMTK_ENABLE_COMPONENT_TESTS "Enable unit tests for components" ${WILDMESHING_TOOLKIT_TOPLEVEL_PROJECT}) + +if(WMTK_ENABLE_COMPONENT_TESTS) add_subdirectory(tests) endif() diff --git a/components/cmake/add_component_test.cmake b/components/cmake/add_component_test.cmake index 3f37286467..d03336ccf1 100644 --- a/components/cmake/add_component_test.cmake +++ b/components/cmake/add_component_test.cmake @@ -1,6 +1,6 @@ function(add_component_test COMPONENT_TARGET_NAME ...) - if(NOT WILDMESHING_TOOLKIT_TOPLEVEL_PROJECT) + if(NOT WMTK_ENABLE_COMPONENT_TESTS) return() endif() list(REMOVE_AT ARGV 0) diff --git a/components/multimesh/CMakeLists.txt b/components/multimesh/CMakeLists.txt index fd6bd15574..01b1c1c952 100644 --- a/components/multimesh/CMakeLists.txt +++ b/components/multimesh/CMakeLists.txt @@ -1,3 +1,5 @@ set(COMPONENT_NAME multimesh) add_subdirectory("src/wmtk/components/${COMPONENT_NAME}") +if(WMTK_ENABLE_COMPONENT_TESTS) add_subdirectory("tests") +endif() diff --git a/tests/attributes/CMakeLists.txt b/tests/attributes/CMakeLists.txt index 0961cf7e74..cb8927e215 100644 --- a/tests/attributes/CMakeLists.txt +++ b/tests/attributes/CMakeLists.txt @@ -8,6 +8,8 @@ set(TEST_SOURCES old_wmtk_attributecollection.cpp transaction_stack.cpp + + attribute_type.cpp ) target_sources(wmtk_tests PRIVATE ${TEST_SOURCES}) diff --git a/tests/attributes/attribute_type.cpp b/tests/attributes/attribute_type.cpp new file mode 100644 index 0000000000..fe640680c1 --- /dev/null +++ b/tests/attributes/attribute_type.cpp @@ -0,0 +1,18 @@ +#include + +#include +#include + + +using namespace wmtk::attribute; + +TEST_CASE("test_attribute_type_names", "[attributes]") +{ + using AT = AttributeType; + CHECK(attribute_type_name(AT::Char) == "Char"); + CHECK(attribute_type_name(AT::Double) == "Double"); + CHECK(attribute_type_name(AT::Int64) == "Int64"); + CHECK(attribute_type_name(AT::Rational) == "Rational"); + +} + From f58b053d188803bcec86e58ee57622af54d9af25 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Sat, 14 Dec 2024 20:29:46 -0500 Subject: [PATCH 3/4] converting string_view to string in catch2 --- tests/attributes/attribute_type.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/attributes/attribute_type.cpp b/tests/attributes/attribute_type.cpp index fe640680c1..09f5f3caee 100644 --- a/tests/attributes/attribute_type.cpp +++ b/tests/attributes/attribute_type.cpp @@ -9,10 +9,11 @@ using namespace wmtk::attribute; TEST_CASE("test_attribute_type_names", "[attributes]") { using AT = AttributeType; - CHECK(attribute_type_name(AT::Char) == "Char"); - CHECK(attribute_type_name(AT::Double) == "Double"); - CHECK(attribute_type_name(AT::Int64) == "Int64"); - CHECK(attribute_type_name(AT::Rational) == "Rational"); + // converting to string because some compilers fail with this combo of catch + string_view comparisons? + CHECK(std::string(attribute_type_name(AT::Char)) == "Char"); + CHECK(std::string(attribute_type_name(AT::Double)) == "Double"); + CHECK(std::string(attribute_type_name(AT::Int64)) == "Int64"); + CHECK(std::string(attribute_type_name(AT::Rational)) == "Rational"); } From 01aa6a1f664b7443ded6d06e8e5424dffffde273 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Sat, 14 Dec 2024 20:33:06 -0500 Subject: [PATCH 4/4] making input component only do tests if component test flag is active --- components/input/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/input/CMakeLists.txt b/components/input/CMakeLists.txt index 95150517d2..4486ff7448 100644 --- a/components/input/CMakeLists.txt +++ b/components/input/CMakeLists.txt @@ -1,3 +1,5 @@ set(COMPONENT_NAME input) add_subdirectory("src/wmtk/components/input") +if(WMTK_ENABLE_COMPONENT_TESTS) add_subdirectory("tests") +endif()