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

Add output for Table and the associated tests

Use NaNHelper to handle bad data output
parent 9acfa827
No related branches found
No related tags found
1 merge request!105Add NaNHelper utility
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <utils/PugsUtils.hpp> #include <utils/PugsUtils.hpp>
#include <utils/Types.hpp> #include <utils/Types.hpp>
#include <iostream>
template <typename DataType> template <typename DataType>
class DenseMatrix // LCOV_EXCL_LINE class DenseMatrix // LCOV_EXCL_LINE
{ {
...@@ -246,6 +248,19 @@ class DenseMatrix // LCOV_EXCL_LINE ...@@ -246,6 +248,19 @@ class DenseMatrix // LCOV_EXCL_LINE
PUGS_INLINE PUGS_INLINE
DenseMatrix& operator=(DenseMatrix&&) = default; DenseMatrix& operator=(DenseMatrix&&) = default;
friend std::ostream&
operator<<(std::ostream& os, const DenseMatrix& A)
{
for (size_t i = 0; i < A.numberOfRows(); ++i) {
os << i << '|';
for (size_t j = 0; j < A.numberOfColumns(); ++j) {
os << ' ' << j << ':' << NaNHelper(A(i, j));
}
os << '\n';
}
return os;
}
template <typename DataType2> template <typename DataType2>
DenseMatrix(const DenseMatrix<DataType2>& A) DenseMatrix(const DenseMatrix<DataType2>& A)
{ {
......
...@@ -373,7 +373,44 @@ TEST_CASE("DenseMatrix", "[algebra]") ...@@ -373,7 +373,44 @@ TEST_CASE("DenseMatrix", "[algebra]")
REQUIRE(C(1, 1) == 137); REQUIRE(C(1, 1) == 137);
} }
SECTION("output")
{
DenseMatrix<double> A(3, 2);
A(0, 0) = 1;
A(0, 1) = 3;
A(1, 0) = -8;
A(1, 1) = -2;
A(2, 0) = 4;
A(2, 1) = -5;
std::ostringstream A_ost;
A_ost << A;
std::ostringstream ref_ost;
ref_ost << "0| " << 0 << ':' << 1. << ' ' << 1 << ':' << 3. << '\n';
ref_ost << "1| " << 0 << ':' << -8. << ' ' << 1 << ':' << -2. << '\n';
ref_ost << "2| " << 0 << ':' << 4. << ' ' << 1 << ':' << -5. << '\n';
REQUIRE(A_ost.str() == ref_ost.str());
}
#ifndef NDEBUG #ifndef NDEBUG
SECTION("output with signaling NaN")
{
DenseMatrix<double> A(3, 2);
A(0, 0) = 1;
A(1, 1) = -2;
A(2, 1) = -5;
std::ostringstream A_ost;
A_ost << A;
std::ostringstream ref_ost;
ref_ost << "0| " << 0 << ':' << 1. << ' ' << 1 << ":nan\n";
ref_ost << "1| " << 0 << ":nan " << 1 << ':' << -2. << '\n';
ref_ost << "2| " << 0 << ":nan " << 1 << ':' << -5. << '\n';
REQUIRE(A_ost.str() == ref_ost.str());
}
SECTION("non square identity matrix") SECTION("non square identity matrix")
{ {
DenseMatrix<int> A(2, 3); DenseMatrix<int> A(2, 3);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment