From 7c8fa28fbd97bd87896ce2af93b5913c0b6a6d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com> Date: Wed, 8 Jun 2022 12:17:06 +0200 Subject: [PATCH] Change TinyMatrix and TinyVector output to conform language's syntax --- src/algebra/TinyMatrix.hpp | 7 +++++-- src/algebra/TinyVector.hpp | 4 ++-- tests/test_BinaryExpressionProcessor_shift.cpp | 12 ++++++------ tests/test_TinyMatrix.cpp | 6 +++--- tests/test_TinyVector.cpp | 4 ++-- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/algebra/TinyMatrix.hpp b/src/algebra/TinyMatrix.hpp index f4c662328..e34f98ed8 100644 --- a/src/algebra/TinyMatrix.hpp +++ b/src/algebra/TinyMatrix.hpp @@ -150,11 +150,14 @@ class [[nodiscard]] TinyMatrix { os << '['; for (size_t i = 0; i < M; ++i) { - os << '(' << NaNHelper(A(i, 0)); + if (i > 0) { + os << ','; + } + os << '[' << NaNHelper(A(i, 0)); for (size_t j = 1; j < N; ++j) { os << ',' << NaNHelper(A(i, j)); } - os << ')'; + os << ']'; } os << ']'; diff --git a/src/algebra/TinyVector.hpp b/src/algebra/TinyVector.hpp index 3ca3d2a38..ae616a484 100644 --- a/src/algebra/TinyVector.hpp +++ b/src/algebra/TinyVector.hpp @@ -100,11 +100,11 @@ class [[nodiscard]] TinyVector PUGS_INLINE constexpr friend std::ostream& operator<<(std::ostream& os, const TinyVector& v) { - os << '(' << NaNHelper(v.m_values[0]); + os << '[' << NaNHelper(v.m_values[0]); for (size_t i = 1; i < N; ++i) { os << ',' << NaNHelper(v.m_values[i]); } - os << ')'; + os << ']'; return os; } diff --git a/tests/test_BinaryExpressionProcessor_shift.cpp b/tests/test_BinaryExpressionProcessor_shift.cpp index 127e90161..834e86cfe 100644 --- a/tests/test_BinaryExpressionProcessor_shift.cpp +++ b/tests/test_BinaryExpressionProcessor_shift.cpp @@ -130,22 +130,22 @@ fout << createSocketServer(0) << "\n";)"; REQUIRE(std::string_view(line) == "(2.3, 4)"); fin.getline(line, 1023); - REQUIRE(std::string_view(line) == "((2.3), (4))"); + REQUIRE(std::string_view(line) == "([2.3], [4])"); fin.getline(line, 1023); - REQUIRE(std::string_view(line) == "((2.3,4), (3,2))"); + REQUIRE(std::string_view(line) == "([2.3,4], [3,2])"); fin.getline(line, 1023); - REQUIRE(std::string_view(line) == "((2.3,4,-1), (3,2,1))"); + REQUIRE(std::string_view(line) == "([2.3,4,-1], [3,2,1])"); fin.getline(line, 1023); - REQUIRE(std::string_view(line) == "([(2.3)], [(4)])"); + REQUIRE(std::string_view(line) == "([[2.3]], [[4]])"); fin.getline(line, 1023); - REQUIRE(std::string_view(line) == "([(2.3,4)(2,0.3)], [(3,2.3)(1,-4)])"); + REQUIRE(std::string_view(line) == "([[2.3,4],[2,0.3]], [[3,2.3],[1,-4]])"); fin.getline(line, 1023); - REQUIRE(std::string_view(line) == "([(2.3,4,-1)(2,7,2.3)(6,2,8)], [(3,2,1)(1,2,5)(2.1,3,-2.6)])"); + REQUIRE(std::string_view(line) == "([[2.3,4,-1],[2,7,2.3],[6,2,8]], [[3,2,1],[1,2,5],[2.1,3,-2.6]])"); fin.getline(line, 1023); REQUIRE(std::string_view(line) == "(foo, bar)"); diff --git a/tests/test_TinyMatrix.cpp b/tests/test_TinyMatrix.cpp index 81c187dc2..2f4c09d4a 100644 --- a/tests/test_TinyMatrix.cpp +++ b/tests/test_TinyMatrix.cpp @@ -272,8 +272,8 @@ TEST_CASE("TinyMatrix", "[algebra]") SECTION("checking for matrices output") { - REQUIRE(Catch::Detail::stringify(A) == "[(1,2,3,4)(5,6,7,8)(9,10,11,12)]"); - REQUIRE(Catch::Detail::stringify(TinyMatrix<1, 1, int>(7)) == "[(7)]"); + REQUIRE(Catch::Detail::stringify(A) == "[[1,2,3,4],[5,6,7,8],[9,10,11,12]]"); + REQUIRE(Catch::Detail::stringify(TinyMatrix<1, 1, int>(7)) == "[[7]]"); } #ifndef NDEBUG @@ -287,7 +287,7 @@ TEST_CASE("TinyMatrix", "[algebra]") A_ost << A; std::ostringstream ref_ost; - ref_ost << "[(1,nan,3)(2,nan,nan)]"; + ref_ost << "[[1,nan,3],[2,nan,nan]]"; REQUIRE(A_ost.str() == ref_ost.str()); } diff --git a/tests/test_TinyVector.cpp b/tests/test_TinyVector.cpp index 0613e721c..9c4dc2e5a 100644 --- a/tests/test_TinyVector.cpp +++ b/tests/test_TinyVector.cpp @@ -30,7 +30,7 @@ TEST_CASE("TinyVector", "[algebra]") REQUIRE(((z[0] == 0) and (z[1] == 0) and (z[2] == 0))); v = TinyVector<3, int>(3, 2, 4); - REQUIRE(Catch::Detail::stringify(v) == "(3,2,4)"); + REQUIRE(Catch::Detail::stringify(v) == "[3,2,4]"); TinyVector<3, int> w(1, 2, 6); REQUIRE(dot(v, w) == 31); @@ -96,7 +96,7 @@ TEST_CASE("TinyVector", "[algebra]") x_ost << x; std::ostringstream ref_ost; - ref_ost << "(nan,1,nan)"; + ref_ost << "[nan,1,nan]"; REQUIRE(x_ost.str() == ref_ost.str()); } -- GitLab