diff --git a/src/algebra/Vector.hpp b/src/algebra/Vector.hpp index 2a3e1bd296a4b07e0dd32e9f3017892a2cea290f..6950df9d74f6478c0c3346c9fa6c96aaff65781d 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 5a8f2f77ced534e9f1e2029e228dd2ed6fc372fd..ff6d1185495d29582027f1fc37b1fabf6bfd1265 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()); }