improved print method

This commit is contained in:
2025-03-19 00:56:39 +03:00
parent 9b6d0beb03
commit f85243e892
2 changed files with 10 additions and 4 deletions

View File

@@ -8,6 +8,7 @@
#include <stdexcept>
#include <utility>
#include "Vector3.hpp"
#include <iomanip>
namespace omath
{
@@ -296,15 +297,20 @@ namespace omath
std::string ToString() const noexcept
{
std::ostringstream oss;
oss << "[[";
for (size_t i = 0; i < Rows; ++i)
{
if (i > 0)
oss << " [";
for (size_t j = 0; j < Columns; ++j)
{
oss << At(i, j);
oss << std::setw(9) << std::fixed << std::setprecision(3) << At(i, j);
if (j != Columns - 1)
oss << ' ';
oss << ", ";
}
oss << '\n';
oss << (i == Rows - 1 ? "]]" : "]\n");
}
return oss.str();
}

View File

@@ -127,7 +127,7 @@ TEST_F(UnitTestMat, ToString)
{
const std::string str = m2.ToString();
EXPECT_FALSE(str.empty());
EXPECT_EQ(str, "1 2\n3 4\n");
EXPECT_EQ(str, "[[ 1.000, 2.000]\n [ 3.000, 4.000]]");
}
// Test assignment operators