Skip to content
Snippets Groups Projects
Commit ef9a9edc authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Make Vector output more readable and use NaNHelper

parent 75e9b183
No related branches found
No related tags found
1 merge request!105Add NaNHelper utility
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define VECTOR_HPP #define VECTOR_HPP
#include <utils/Array.hpp> #include <utils/Array.hpp>
#include <utils/NaNHelper.hpp>
#include <utils/PugsAssert.hpp> #include <utils/PugsAssert.hpp>
#include <utils/PugsMacros.hpp> #include <utils/PugsMacros.hpp>
#include <utils/PugsUtils.hpp> #include <utils/PugsUtils.hpp>
...@@ -28,8 +29,11 @@ class Vector // LCOV_EXCL_LINE ...@@ -28,8 +29,11 @@ class Vector // LCOV_EXCL_LINE
friend std::ostream& friend std::ostream&
operator<<(std::ostream& os, const Vector& x) operator<<(std::ostream& os, const Vector& x)
{ {
for (size_t i = 0; i < x.size(); ++i) { if (x.size() > 0) {
os << ' ' << x[i]; os << 0 << ':' << NaNHelper(x[0]);
}
for (size_t i = 1; i < x.size(); ++i) {
os << ' ' << i << ':' << NaNHelper(x[i]);
} }
return os; return os;
} }
......
...@@ -371,8 +371,9 @@ TEST_CASE("Vector", "[algebra]") ...@@ -371,8 +371,9 @@ TEST_CASE("Vector", "[algebra]")
std::ostringstream vector_ost; std::ostringstream vector_ost;
vector_ost << x; vector_ost << x;
std::ostringstream ref_ost; std::ostringstream ref_ost;
for (size_t i = 0; i < x.size(); ++i) { ref_ost << 0 << ':' << x[0];
ref_ost << ' ' << x[i]; for (size_t i = 1; i < x.size(); ++i) {
ref_ost << ' ' << i << ':' << x[i];
} }
REQUIRE(vector_ost.str() == ref_ost.str()); REQUIRE(vector_ost.str() == ref_ost.str());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment