diff --git a/src/utils/Array.hpp b/src/utils/Array.hpp
index bae84f1147f54c18aee9b81220cc42c12d9bdf17..54786db88592d7371e7b7fa5e9acd0aaec4fffe5 100644
--- a/src/utils/Array.hpp
+++ b/src/utils/Array.hpp
@@ -24,17 +24,6 @@ class [[nodiscard]] Array
   friend Array<std::add_const_t<DataType>>;
 
  public:
-  friend std::ostream& operator<<(std::ostream& os, const Array& x)
-  {
-    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;
-  }
-
   PUGS_INLINE size_t size() const noexcept
   {
     return m_values.extent(0);
@@ -121,6 +110,17 @@ class [[nodiscard]] Array
 #endif   // NDEBUG
   }
 
+  friend std::ostream& operator<<(std::ostream& os, const Array& x)
+  {
+    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;
+  }
+
   PUGS_INLINE
   Array() = default;
 
diff --git a/tests/test_Array.cpp b/tests/test_Array.cpp
index dd6f57ea61bd52632477cb16fc7f6556757036f5..5b9889f396f6413b4c704e48ffa1497bf6edb8fe 100644
--- a/tests/test_Array.cpp
+++ b/tests/test_Array.cpp
@@ -232,7 +232,44 @@ TEST_CASE("Array", "[utils]")
     }
   }
 
+  SECTION("output")
+  {
+    Array<int> x{5};
+    x[0] = 2;
+    x[1] = 6;
+    x[2] = 2;
+    x[3] = 3;
+    x[4] = 7;
+
+    std::ostringstream array_ost;
+    array_ost << x;
+    std::ostringstream ref_ost;
+    ref_ost << 0 << ':' << x[0];
+    for (size_t i = 1; i < x.size(); ++i) {
+      ref_ost << ' ' << i << ':' << x[i];
+    }
+    REQUIRE(array_ost.str() == ref_ost.str());
+  }
+
 #ifndef NDEBUG
+
+  SECTION("output with signaling NaN")
+  {
+    Array<double> x{5};
+    x[0] = 2;
+    x[2] = 3;
+
+    std::ostringstream array_ost;
+    array_ost << x;
+    std::ostringstream ref_ost;
+    ref_ost << 0 << ':' << 2 << ' ';
+    ref_ost << 1 << ":nan ";
+    ref_ost << 2 << ':' << 3 << ' ';
+    ref_ost << 3 << ":nan ";
+    ref_ost << 4 << ":nan";
+    REQUIRE(array_ost.str() == ref_ost.str());
+  }
+
   SECTION("checking for bounds violation")
   {
     REQUIRE_THROWS_AS(a[10], AssertError);
diff --git a/tests/test_Vector.cpp b/tests/test_Vector.cpp
index ff6d1185495d29582027f1fc37b1fabf6bfd1265..e31bf166713b70f69ca108d7dace6dc07179dc5b 100644
--- a/tests/test_Vector.cpp
+++ b/tests/test_Vector.cpp
@@ -362,11 +362,11 @@ TEST_CASE("Vector", "[algebra]")
   SECTION("output")
   {
     Vector<int> x{5};
-    x[0] = 0;
-    x[1] = 1;
+    x[0] = 3;
+    x[1] = 7;
     x[2] = 2;
-    x[3] = 3;
-    x[4] = 4;
+    x[3] = 1;
+    x[4] = -4;
 
     std::ostringstream vector_ost;
     vector_ost << x;
@@ -432,6 +432,24 @@ TEST_CASE("Vector", "[algebra]")
   }
 
 #ifndef NDEBUG
+
+  SECTION("output with signaling NaN")
+  {
+    Vector<double> x{5};
+    x[0] = 3;
+    x[2] = 2;
+
+    std::ostringstream vector_ost;
+    vector_ost << x;
+    std::ostringstream ref_ost;
+    ref_ost << 0 << ':' << 3 << ' ';
+    ref_ost << 1 << ":nan ";
+    ref_ost << 2 << ':' << 2 << ' ';
+    ref_ost << 3 << ":nan ";
+    ref_ost << 4 << ":nan";
+    REQUIRE(vector_ost.str() == ref_ost.str());
+  }
+
   SECTION("invalid dot product")
   {
     Vector<int> x{5};