Skip to content
Snippets Groups Projects
Commit 9acfa827 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.
parent d5726f98
No related branches found
No related tags found
1 merge request!105Add NaNHelper utility
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <Kokkos_CopyViews.hpp> #include <Kokkos_CopyViews.hpp>
#include <iostream>
template <typename DataType> template <typename DataType>
class [[nodiscard]] Table class [[nodiscard]] Table
{ {
...@@ -126,6 +128,18 @@ class [[nodiscard]] Table ...@@ -126,6 +128,18 @@ class [[nodiscard]] Table
#endif // NDEBUG #endif // NDEBUG
} }
friend std::ostream& operator<<(std::ostream& os, const Table& t)
{
for (size_t i = 0; i < t.numberOfRows(); ++i) {
os << i << '|';
for (size_t j = 0; j < t.numberOfColumns(); ++j) {
os << ' ' << j << ':' << NaNHelper(t(i, j));
}
os << '\n';
}
return os;
}
PUGS_INLINE PUGS_INLINE
Table() = default; Table() = default;
......
...@@ -157,7 +157,6 @@ TEST_CASE("Table", "[utils]") ...@@ -157,7 +157,6 @@ TEST_CASE("Table", "[utils]")
} }
SECTION("checking for Kokkos::View encaspulation") SECTION("checking for Kokkos::View encaspulation")
{
{ {
Kokkos::View<double**> kokkos_view("anonymous", 10, 3); Kokkos::View<double**> kokkos_view("anonymous", 10, 3);
for (size_t i = 0; i < 10; ++i) { for (size_t i = 0; i < 10; ++i) {
...@@ -176,9 +175,45 @@ TEST_CASE("Table", "[utils]") ...@@ -176,9 +175,45 @@ TEST_CASE("Table", "[utils]")
} }
} }
} }
SECTION("output")
{
Table<double> table(3, 2);
table(0, 0) = 1;
table(0, 1) = 3;
table(1, 0) = 7;
table(1, 1) = -2;
table(2, 0) = 4;
table(2, 1) = -5;
std::ostringstream table_ost;
table_ost << table;
std::ostringstream ref_ost;
ref_ost << "0| " << 0 << ':' << 1. << ' ' << 1 << ':' << 3. << '\n';
ref_ost << "1| " << 0 << ':' << 7. << ' ' << 1 << ':' << -2. << '\n';
ref_ost << "2| " << 0 << ':' << 4. << ' ' << 1 << ':' << -5. << '\n';
REQUIRE(table_ost.str() == ref_ost.str());
} }
#ifndef NDEBUG #ifndef NDEBUG
SECTION("output with signaling NaN")
{
Table<double> table(3, 2);
table(0, 0) = 1;
table(1, 1) = -2;
table(2, 1) = -5;
std::ostringstream table_ost;
table_ost << table;
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(table_ost.str() == ref_ost.str());
}
SECTION("checking for bounds violation") SECTION("checking for bounds violation")
{ {
REQUIRE_THROWS_AS(a(4, 0), AssertError); REQUIRE_THROWS_AS(a(4, 0), AssertError);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment