diff --git a/include/fintamath/literals/Boolean.hpp b/include/fintamath/literals/Boolean.hpp index 29e326726..43b4f6360 100644 --- a/include/fintamath/literals/Boolean.hpp +++ b/include/fintamath/literals/Boolean.hpp @@ -15,7 +15,9 @@ class Boolean final : public ILiteralCRTP { explicit Boolean(const std::string &str); - Boolean(bool val); + template Bool> + Boolean(const Bool val) : name(val ? trueStr : falseStr) { + } std::string toString() const override; @@ -23,6 +25,10 @@ class Boolean final : public ILiteralCRTP { private: std::string name; + + static constexpr std::string_view trueStr = "True"; + + static constexpr std::string_view falseStr = "False"; }; } diff --git a/src/fintamath/literals/Boolean.cpp b/src/fintamath/literals/Boolean.cpp index 9cd0772f3..eef68b3d7 100644 --- a/src/fintamath/literals/Boolean.cpp +++ b/src/fintamath/literals/Boolean.cpp @@ -4,9 +4,6 @@ namespace fintamath { -constexpr std::string_view trueStr = "True"; -constexpr std::string_view falseStr = "False"; - Boolean::Boolean() : name(falseStr) { } @@ -18,9 +15,6 @@ Boolean::Boolean(const std::string &str) { name = str; } -Boolean::Boolean(const bool val) : name(val ? trueStr : falseStr) { -} - std::string Boolean::toString() const { return name; } diff --git a/tests/src/literals/BooleanTests.cpp b/tests/src/literals/BooleanTests.cpp index c869ef12e..a4151328a 100644 --- a/tests/src/literals/BooleanTests.cpp +++ b/tests/src/literals/BooleanTests.cpp @@ -11,15 +11,15 @@ TEST(BooleanTests, constructorTest) { } TEST(BooleanTests, stringConstructorTest) { - EXPECT_EQ(Boolean(std::string("True")), true); - EXPECT_EQ(Boolean(std::string("False")), false); - - EXPECT_THROW(Boolean(std::string("true")), InvalidInputException); - EXPECT_THROW(Boolean(std::string("false")), InvalidInputException); - EXPECT_THROW(Boolean(std::string("10")), InvalidInputException); - EXPECT_THROW(Boolean(std::string("i")), InvalidInputException); - EXPECT_THROW(Boolean(std::string("")), InvalidInputException); - EXPECT_THROW(Boolean(std::string("")), InvalidInputException); + EXPECT_EQ(Boolean("True"), true); + EXPECT_EQ(Boolean("False"), false); + + EXPECT_THROW(Boolean("true"), InvalidInputException); + EXPECT_THROW(Boolean("false"), InvalidInputException); + EXPECT_THROW(Boolean("10"), InvalidInputException); + EXPECT_THROW(Boolean("i"), InvalidInputException); + EXPECT_THROW(Boolean(""), InvalidInputException); + EXPECT_THROW(Boolean(""), InvalidInputException); } TEST(BooleanTests, boolConstructorTest) { @@ -45,6 +45,6 @@ TEST(BooleanTests, opearatorsTest) { } TEST(BooleanTest, getClassTest) { - EXPECT_EQ(Boolean::getClassStatic(), MathObjectClass("Boolean")); - EXPECT_EQ(Boolean::getClassStatic().getParent(), ILiteral::getClassStatic()); + EXPECT_EQ(Boolean().getClass(), MathObjectClass("Boolean")); + EXPECT_EQ(Boolean().getClass().getParent(), ILiteral::getClassStatic()); }