From ef9a9edc6e2bbeca5242951d7c8eda8ddaf1f887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com> Date: Sat, 31 Jul 2021 15:41:16 +0200 Subject: [PATCH] Make Vector output more readable and use NaNHelper --- src/algebra/Vector.hpp | 8 ++++++-- tests/test_Vector.cpp | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/algebra/Vector.hpp b/src/algebra/Vector.hpp index 2a3e1bd29..6950df9d7 100644 --- a/src/algebra/Vector.hpp +++ b/src/algebra/Vector.hpp @@ -2,6 +2,7 @@ #define VECTOR_HPP #include <utils/Array.hpp> +#include <utils/NaNHelper.hpp> #include <utils/PugsAssert.hpp> #include <utils/PugsMacros.hpp> #include <utils/PugsUtils.hpp> @@ -28,8 +29,11 @@ class Vector // LCOV_EXCL_LINE friend std::ostream& operator<<(std::ostream& os, const Vector& x) { - for (size_t i = 0; i < x.size(); ++i) { - os << ' ' << x[i]; + if (x.size() > 0) { + os << 0 << ':' << NaNHelper(x[0]); + } + for (size_t i = 1; i < x.size(); ++i) { + os << ' ' << i << ':' << NaNHelper(x[i]); } return os; } diff --git a/tests/test_Vector.cpp b/tests/test_Vector.cpp index 5a8f2f77c..ff6d11854 100644 --- a/tests/test_Vector.cpp +++ b/tests/test_Vector.cpp @@ -371,8 +371,9 @@ TEST_CASE("Vector", "[algebra]") std::ostringstream vector_ost; vector_ost << x; std::ostringstream ref_ost; - for (size_t i = 0; i < x.size(); ++i) { - ref_ost << ' ' << x[i]; + ref_ost << 0 << ':' << x[0]; + for (size_t i = 1; i < x.size(); ++i) { + ref_ost << ' ' << i << ':' << x[i]; } REQUIRE(vector_ost.str() == ref_ost.str()); } -- GitLab