diff --git a/modules/types/include/hephaestus/types/type_formatting.h b/modules/types/include/hephaestus/types/type_formatting.h index 01991dee..8e0b4a19 100644 --- a/modules/types/include/hephaestus/types/type_formatting.h +++ b/modules/types/include/hephaestus/types/type_formatting.h @@ -18,9 +18,12 @@ namespace heph::types { //================================================================================================= -// Vector +// Array and Vector //================================================================================================= -template +template +concept ArrayOrVectorType = ArrayType || VectorType; + +template [[nodiscard]] inline auto toString(const T& vec) -> std::string { std::stringstream ss; diff --git a/modules/types/tests/type_formatting_tests.cpp b/modules/types/tests/type_formatting_tests.cpp index 5c9e2f5d..88d82d16 100644 --- a/modules/types/tests/type_formatting_tests.cpp +++ b/modules/types/tests/type_formatting_tests.cpp @@ -3,6 +3,7 @@ //================================================================================================= #include +#include #include #include #include @@ -18,6 +19,42 @@ using namespace ::testing; // NOLINT(google-build-using-namespace) namespace heph::types::tests { +//================================================================================================= +// Array +//================================================================================================= + +TEST(TypeFormattingTests, ConvertEmptyArray) { + const std::array arr = {}; + const std::string result = toString(arr); + EXPECT_EQ(result, ""); +} + +TEST(TypeFormattingTests, ConvertIntArray) { + const std::array arr = { 1, 2, 3 }; + const std::string result = toString(arr); + const std::string expected = " Index: 0, Value: 1\n" + " Index: 1, Value: 2\n" + " Index: 2, Value: 3\n"; + EXPECT_EQ(result, expected); +} + +TEST(TypeFormattingTests, ConvertDoubleArray) { + const std::array arr = { 1.1, 2.2, 3.3 }; // NOLINT(cppcoreguidelines-avoid-magic-numbers) + const std::string result = toString(arr); + const std::string expected = " Index: 0, Value: 1.1\n" + " Index: 1, Value: 2.2\n" + " Index: 2, Value: 3.3\n"; + EXPECT_EQ(result, expected); +} + +TEST(TypeFormattingTests, ConvertStringArray) { + const std::array arr = { "one", "two", "three" }; + const std::string result = toString(arr); + const std::string expected = " Index: 0, Value: one\n" + " Index: 1, Value: two\n" + " Index: 2, Value: three\n"; + EXPECT_EQ(result, expected); +} //================================================================================================= // Vector //=================================================================================================