Skip to content

Commit

Permalink
Change IMathObject::toString()
Browse files Browse the repository at this point in the history
  • Loading branch information
fintarin committed Feb 18, 2024
1 parent 0ca5d7c commit 6bbeadc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion include/fintamath/core/IMathObject.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#pragma once

#include <concepts>
#include <cstddef>
#include <memory>
#include <ostream>
#include <string>
#include <utility>

#include <fmt/format.h>

#include "fintamath/core/Converter.hpp"
#include "fintamath/core/CoreUtils.hpp"
#include "fintamath/core/MathObjectTypes.hpp"
Expand All @@ -24,7 +27,7 @@ class IMathObject {
virtual std::unique_ptr<IMathObject> clone() && = 0;

virtual std::string toString() const {
return typeid(*this).name();
return fmt::format("MathObject{}", static_cast<size_t>(getType()));
}

virtual std::unique_ptr<IMathObject> toMinimalObject() const {
Expand Down
9 changes: 7 additions & 2 deletions tests/src/core/IMathObjectTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ using namespace fintamath;

namespace {

class TestMathObject final : public IMathObjectCRTP<TestMathObject> {};
class TestMathObject final : public IMathObjectCRTP<TestMathObject> {
public:
static constexpr MathObjectType getTypeStatic() {
return static_cast<size_t>(MathObjectType::IMathObject) + 999;
}
};

}

TEST(IMathObjectTests, toStringTest) {
EXPECT_EQ(TestMathObject().toString(), typeid(TestMathObject).name());
EXPECT_EQ(TestMathObject().toString(), "MathObject999");
}

TEST(IMathObjectTests, cloneTest) {
Expand Down

0 comments on commit 6bbeadc

Please sign in to comment.