diff --git a/include/fintamath/expressions/Expression.hpp b/include/fintamath/expressions/Expression.hpp index 56e2d1964..c8e4de64f 100644 --- a/include/fintamath/expressions/Expression.hpp +++ b/include/fintamath/expressions/Expression.hpp @@ -94,16 +94,6 @@ class Expression final : public IExpressionCRTP { static void registerExpressionConstructor(ExpressionConstructor constructor); protected: - Expression &add(const Expression &rhs) override; - - Expression &substract(const Expression &rhs) override; - - Expression &multiply(const Expression &rhs) override; - - Expression ÷(const Expression &rhs) override; - - Expression &negate() override; - ArgumentPtr simplify() const override; private: @@ -169,30 +159,6 @@ class Expression final : public IExpressionCRTP { mutable bool isSimplified = false; }; -Expression operator+(const Variable &lhs, const Variable &rhs); - -Expression operator+(const Expression &lhs, const Variable &rhs); - -Expression operator+(const Variable &lhs, const Expression &rhs); - -Expression operator-(const Variable &lhs, const Variable &rhs); - -Expression operator-(const Expression &lhs, const Variable &rhs); - -Expression operator-(const Variable &lhs, const Expression &rhs); - -Expression operator*(const Variable &lhs, const Variable &rhs); - -Expression operator*(const Expression &lhs, const Variable &rhs); - -Expression operator*(const Variable &lhs, const Expression &rhs); - -Expression operator/(const Variable &lhs, const Variable &rhs); - -Expression operator/(const Expression &lhs, const Variable &rhs); - -Expression operator/(const Variable &lhs, const Expression &rhs); - template void Expression::registerExpressionConstructor(ExpressionConstructor constructor) { getExpressionMaker()[Function::getClassStatic()] = [maker = std::move(constructor)](ArgumentPtrVector &&args) { diff --git a/include/fintamath/expressions/ExpressionFunctions.hpp b/include/fintamath/expressions/ExpressionFunctions.hpp index 87a4b3485..a3795556d 100644 --- a/include/fintamath/expressions/ExpressionFunctions.hpp +++ b/include/fintamath/expressions/ExpressionFunctions.hpp @@ -5,21 +5,19 @@ namespace fintamath { -Expression add(const auto &...args) { - return (Expression(args) + ...); -} +Expression operator+(const Expression &lhs, const Expression &rhs); -Expression mul(const auto &...args) { - return (Expression(args) * ...); -} +Expression operator+(const Expression &rhs); -Expression sub(const Expression &lhs, const Expression &rhs); +Expression operator-(const Expression &lhs, const Expression &rhs); -Expression div(const Expression &lhs, const Expression &rhs); +Expression operator-(const Expression &rhs); -Expression mod(const Expression &lhs, const Expression &rhs); +Expression operator*(const Expression &lhs, const Expression &rhs); -Expression neg(const Expression &rhs); +Expression operator/(const Expression &lhs, const Expression &rhs); + +Expression mod(const Expression &lhs, const Expression &rhs); Expression eqv(const Expression &lhs, const Expression &rhs); diff --git a/include/fintamath/expressions/IExpression.hpp b/include/fintamath/expressions/IExpression.hpp index 5d8e83942..5ab17d38e 100644 --- a/include/fintamath/expressions/IExpression.hpp +++ b/include/fintamath/expressions/IExpression.hpp @@ -6,7 +6,6 @@ #include #include -#include "fintamath/core/IArithmetic.hpp" #include "fintamath/core/IMathObject.hpp" #include "fintamath/core/MathObjectClass.hpp" #include "fintamath/core/Parser.hpp" @@ -18,7 +17,7 @@ namespace fintamath { -class IExpression : public IArithmetic { +class IExpression : public IMathObject { FINTAMATH_PARENT_CLASS_BODY(IExpression) public: diff --git a/include/fintamath/expressions/IExpressionBaseCRTP.hpp b/include/fintamath/expressions/IExpressionBaseCRTP.hpp index 46f88baf7..886cdc4f4 100644 --- a/include/fintamath/expressions/IExpressionBaseCRTP.hpp +++ b/include/fintamath/expressions/IExpressionBaseCRTP.hpp @@ -9,9 +9,9 @@ class IExpressionBaseCRTP_ : public IExpression { #endif // I_EXPRESSION_BASE_CRTP -#define I_ARITHMETIC_CRTP I_EXPRESSION_BASE_CRTP -#include "fintamath/core/IArithmeticCRTP.hpp" -#undef I_ARITHMETIC_CRTP +#define I_MATH_OBJECT_CRTP I_EXPRESSION_BASE_CRTP +#include "fintamath/core/IMathObjectCRTP.hpp" +#undef I_MATH_OBJECT_CRTP private: #if !defined(I_EXPRESSION_BASE_CRTP) && !defined(NDEBUG) diff --git a/include/fintamath/expressions/IExpressionCRTP.hpp b/include/fintamath/expressions/IExpressionCRTP.hpp index f1dd73f03..68e86bd25 100644 --- a/include/fintamath/expressions/IExpressionCRTP.hpp +++ b/include/fintamath/expressions/IExpressionCRTP.hpp @@ -33,27 +33,6 @@ class IExpressionCRTP_ : public IExpressionBaseCRTP { return true; } -protected: - Derived &add(const Derived &rhs) override { - throw InvalidInputBinaryOperatorException("+", this->toString(), rhs.toString()); - } - - Derived &substract(const Derived &rhs) override { - throw InvalidInputBinaryOperatorException("-", this->toString(), rhs.toString()); - } - - Derived &multiply(const Derived &rhs) override { - throw InvalidInputBinaryOperatorException("*", this->toString(), rhs.toString()); - } - - Derived ÷(const Derived &rhs) override { - throw InvalidInputBinaryOperatorException("/", this->toString(), rhs.toString()); - } - - Derived &negate() override { - throw InvalidInputUnaryOperatorException("-", this->toString(), InvalidInputUnaryOperatorException::Type::Prefix); - } - private: #if !defined(I_EXPRESSION_CRTP) && !defined(NDEBUG) }; diff --git a/include/fintamath/functions/IFunction.hpp b/include/fintamath/functions/IFunction.hpp index a5a5c360f..4023997be 100644 --- a/include/fintamath/functions/IFunction.hpp +++ b/include/fintamath/functions/IFunction.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "fintamath/core/IMathObject.hpp" diff --git a/include/fintamath/literals/Boolean.hpp b/include/fintamath/literals/Boolean.hpp index 43b4f6360..7c752d389 100644 --- a/include/fintamath/literals/Boolean.hpp +++ b/include/fintamath/literals/Boolean.hpp @@ -21,7 +21,7 @@ class Boolean final : public ILiteralCRTP { std::string toString() const override; - operator bool() const; + explicit operator bool() const; private: std::string name; diff --git a/src/fintamath/config/TypeConfig.cpp b/src/fintamath/config/TypeConfig.cpp index c190eeaf5..c59f312b4 100644 --- a/src/fintamath/config/TypeConfig.cpp +++ b/src/fintamath/config/TypeConfig.cpp @@ -119,12 +119,12 @@ namespace fintamath::detail { TypeConfig::TypeConfig() { - IMathObject::registerType(); - IMathObject::registerType(); IMathObject::registerType(); + IMathObject::registerType(); + IMathObject::registerType(); + IMathObject::registerType(); IArithmetic::registerType(); - IArithmetic::registerType(); IComparable::registerType(); diff --git a/src/fintamath/expressions/Expression.cpp b/src/fintamath/expressions/Expression.cpp index 66526fe26..34f99ace3 100644 --- a/src/fintamath/expressions/Expression.cpp +++ b/src/fintamath/expressions/Expression.cpp @@ -82,36 +82,6 @@ const std::shared_ptr &Expression::getFunction() const { return func; } -Expression &Expression::add(const Expression &rhs) { - child = makeExpr(Add{}, *child, *rhs.child); - isSimplified = false; - return *this; -} - -Expression &Expression::substract(const Expression &rhs) { - child = makeExpr(Sub{}, *child, *rhs.child); - isSimplified = false; - return *this; -} - -Expression &Expression::multiply(const Expression &rhs) { - child = makeExpr(Mul{}, *child, *rhs.child); - isSimplified = false; - return *this; -} - -Expression &Expression::divide(const Expression &rhs) { - child = makeExpr(Div{}, *child, *rhs.child); - isSimplified = false; - return *this; -} - -Expression &Expression::negate() { - child = makeExpr(Neg{}, *child); - isSimplified = false; - return *this; -} - const ArgumentPtrVector &Expression::getChildren() const { simplifyMutable(); childrenCached.front() = child; @@ -530,54 +500,6 @@ bool Expression::doesArgMatch(const MathObjectClass &expectedType, const Argumen return true; } -Expression operator+(const Variable &lhs, const Variable &rhs) { - return Expression(addExpr(lhs, rhs)); -} - -Expression operator+(const Expression &lhs, const Variable &rhs) { - return Expression(addExpr(lhs, rhs)); -} - -Expression operator+(const Variable &lhs, const Expression &rhs) { - return Expression(addExpr(lhs, rhs)); -} - -Expression operator-(const Variable &lhs, const Variable &rhs) { - return Expression(subExpr(lhs, rhs)); -} - -Expression operator-(const Expression &lhs, const Variable &rhs) { - return Expression(subExpr(lhs, rhs)); -} - -Expression operator-(const Variable &lhs, const Expression &rhs) { - return Expression(subExpr(lhs, rhs)); -} - -Expression operator*(const Variable &lhs, const Variable &rhs) { - return Expression(mulExpr(lhs, rhs)); -} - -Expression operator*(const Expression &lhs, const Variable &rhs) { - return Expression(mulExpr(lhs, rhs)); -} - -Expression operator*(const Variable &lhs, const Expression &rhs) { - return Expression(mulExpr(lhs, rhs)); -} - -Expression operator/(const Variable &lhs, const Variable &rhs) { - return Expression(divExpr(lhs, rhs)); -} - -Expression operator/(const Expression &lhs, const Variable &rhs) { - return Expression(divExpr(lhs, rhs)); -} - -Expression operator/(const Variable &lhs, const Expression &rhs) { - return Expression(divExpr(lhs, rhs)); -} - namespace detail { std::unique_ptr makeExpr(const IFunction &func, ArgumentPtrVector args) { diff --git a/src/fintamath/expressions/ExpressionFunctions.cpp b/src/fintamath/expressions/ExpressionFunctions.cpp index 99293a5b0..d0ff9aae9 100644 --- a/src/fintamath/expressions/ExpressionFunctions.cpp +++ b/src/fintamath/expressions/ExpressionFunctions.cpp @@ -2,6 +2,11 @@ #include "fintamath/expressions/Expression.hpp" #include "fintamath/functions/arithmetic/Abs.hpp" +#include "fintamath/functions/arithmetic/Add.hpp" +#include "fintamath/functions/arithmetic/Div.hpp" +#include "fintamath/functions/arithmetic/Mul.hpp" +#include "fintamath/functions/arithmetic/Neg.hpp" +#include "fintamath/functions/arithmetic/Sub.hpp" #include "fintamath/functions/calculus/Derivative.hpp" #include "fintamath/functions/comparison/Eqv.hpp" #include "fintamath/functions/comparison/Less.hpp" @@ -47,20 +52,32 @@ namespace fintamath { -Expression sub(const Expression &lhs, const Expression &rhs) { - return lhs - rhs; +Expression operator+(const Expression &lhs, const Expression &rhs) { + return Expression(addExpr(lhs, rhs)); } -Expression div(const Expression &lhs, const Expression &rhs) { - return lhs / rhs; +Expression operator+(const Expression &rhs) { + return rhs; } -Expression mod(const Expression &lhs, const Expression &rhs) { - return Expression(modExpr(lhs, rhs)); +Expression operator-(const Expression &lhs, const Expression &rhs) { + return Expression(subExpr(lhs, rhs)); +} + +Expression operator-(const Expression &rhs) { + return Expression(negExpr(rhs)); +} + +Expression operator*(const Expression &lhs, const Expression &rhs) { + return Expression(mulExpr(lhs, rhs)); +} + +Expression operator/(const Expression &lhs, const Expression &rhs) { + return Expression(divExpr(lhs, rhs)); } -Expression neg(const Expression &rhs) { - return -rhs; +Expression mod(const Expression &lhs, const Expression &rhs) { + return Expression(modExpr(lhs, rhs)); } Expression eqv(const Expression &lhs, const Expression &rhs) { diff --git a/src/fintamath/expressions/functions/ExpressionFunctionSolve.cpp b/src/fintamath/expressions/functions/ExpressionFunctionSolve.cpp index eb213668f..361b48f94 100644 --- a/src/fintamath/expressions/functions/ExpressionFunctionSolve.cpp +++ b/src/fintamath/expressions/functions/ExpressionFunctionSolve.cpp @@ -135,11 +135,11 @@ ArgumentPtrVector solveQuadraticEquation(const ArgumentPtrVector &coeffAtPow) { const Expression b(coeffAtPow[1]); const Expression c(coeffAtPow[0]); - const ArgumentPtr discriminantArg = sub(pow(b, 2), mul(4, a, c)).toMinimalObject(); + const ArgumentPtr discriminantArg = (pow(b, 2) - (4 * a * c)).toMinimalObject(); const Expression discriminant(discriminantArg); - const Expression firstRoot = div(add(neg(b), sqrt(discriminant)), mul(2, a)); - const Expression secondRoot = div(sub(neg(b), sqrt(discriminant)), mul(2, a)); + const Expression firstRoot = (-b + sqrt(discriminant)) / 2 * a; + const Expression secondRoot = (-b - sqrt(discriminant)) / (2 * a); return {firstRoot.getChildren().front(), secondRoot.getChildren().front()}; } diff --git a/tests/src/FintamathTests.cpp b/tests/src/FintamathTests.cpp index b6b462387..1ced8cacf 100644 --- a/tests/src/FintamathTests.cpp +++ b/tests/src/FintamathTests.cpp @@ -15,10 +15,10 @@ TEST(FintamathTests, fintamathTest) { //-------------------------------------------------------------------------------------// - expr = add(e(), pi(), Variable("a"), Variable("b")); + expr = e() + pi() + Variable("a") + Variable("b"); EXPECT_EQ(expr.toString(), "a + b + E + Pi"); - expr = mul(e(), pi(), Variable("a"), Variable("b")); + expr = e() * pi() * Variable("a") * Variable("b"); EXPECT_EQ(expr.toString(), "E Pi a b"); expr = pow(Variable("a"), Variable("b")) * Variable("c"); diff --git a/tests/src/expressions/ExpressionFunctionsTests.cpp b/tests/src/expressions/ExpressionFunctionsTests.cpp index 74f108d21..bfd154f17 100644 --- a/tests/src/expressions/ExpressionFunctionsTests.cpp +++ b/tests/src/expressions/ExpressionFunctionsTests.cpp @@ -1,53 +1,71 @@ #include #include "fintamath/expressions/ExpressionFunctions.hpp" - -#include "fintamath/literals/Variable.hpp" +#include "fintamath/functions/arithmetic/Add.hpp" +#include "fintamath/functions/arithmetic/Mul.hpp" +#include "fintamath/literals/Boolean.hpp" +#include "fintamath/literals/constants/E.hpp" using namespace fintamath; TEST(ExpressionFunctionsTests, addTest) { - EXPECT_EQ(add(Variable("a"), -1, Expression("b^2")).toString(), "a + b^2 - 1"); - EXPECT_EQ(add(10, Expression("a+2")).toString(), "a + 12"); - EXPECT_EQ(add(Variable("a"), Expression("a+2")).toString(), "2 a + 2"); - EXPECT_EQ(add(Expression("b+2"), Expression("a+2")).toString(), "a + b + 4"); - EXPECT_EQ(add(Expression("10+a^3"), Expression("a^2")).toString(), "a^3 + a^2 + 10"); - EXPECT_EQ(add(Expression("a*b"), Expression("b*a")).toString(), "2 a b"); - EXPECT_EQ(add(Expression("a+b"), Expression("a+b")).toString(), "2 a + 2 b"); + EXPECT_EQ((Variable("a") + Variable("a")).toString(), "2 a"); + EXPECT_EQ((Variable("a") + Variable("b")).toString(), "a + b"); + EXPECT_EQ((Variable("a") + -1 + Expression("b^2")).toString(), "a + b^2 - 1"); + EXPECT_EQ((10 + Expression("a+2")).toString(), "a + 12"); + EXPECT_EQ((Variable("a") + Expression("a+2")).toString(), "2 a + 2"); + EXPECT_EQ((Expression("b+2") + Expression("a+2")).toString(), "a + b + 4"); + EXPECT_EQ((Expression("10+a^3") + Expression("a^2")).toString(), "a^3 + a^2 + 10"); + EXPECT_EQ((Expression("a*b") + Expression("b*a")).toString(), "2 a b"); + EXPECT_EQ((Expression("a+b") + Expression("a+b")).toString(), "2 a + 2 b"); } -TEST(ExpressionFunctionsTests, mulTest) { - EXPECT_EQ(mul(Variable("a"), -1, Expression("a*2")).toString(), "-2 a^2"); - EXPECT_EQ(mul(10, Expression("a+2")).toString(), "10 a + 20"); - EXPECT_EQ(mul(Variable("a"), Expression("a^3+a^2")).toString(), "a^4 + a^3"); - EXPECT_EQ(mul(5, Expression("a+3"), Expression("a+2")).toString(), "5 a^2 + 25 a + 30"); - EXPECT_EQ(mul(Expression("a+b"), Expression("3 b + c")).toString(), "3 a b + a c + 3 b^2 + b c"); +TEST(ExpressionFunctionsTests, unaryPlusTest) { + EXPECT_EQ((+Variable("a")).toString(), "a"); + EXPECT_EQ((+Expression("a")).toString(), "a"); + EXPECT_EQ((+Expression("a+3")).toString(), "a + 3"); + EXPECT_EQ((+Expression("(a+b)^2")).toString(), "a^2 + 2 a b + b^2"); } TEST(ExpressionFunctionsTests, subTest) { - EXPECT_EQ(sub(Variable("a"), Expression("b^2")).toString(), "a - b^2"); - EXPECT_EQ(sub(10, Expression("a+2")).toString(), "-a + 8"); - EXPECT_EQ(sub(Variable("a"), Expression("a+2")).toString(), "-2"); - EXPECT_EQ(sub(Expression("b+2"), Expression("a+2")).toString(), "-a + b"); - EXPECT_EQ(sub(Expression("10+a^3"), Expression("a^2")).toString(), "a^3 - a^2 + 10"); - EXPECT_EQ(sub(Expression("a*b"), Expression("b*a")).toString(), "0"); - EXPECT_EQ(sub(Expression("a+b"), Expression("a+b")).toString(), "0"); + EXPECT_EQ((Variable("a") - Variable("a")).toString(), "0"); + EXPECT_EQ((Variable("a") - Variable("b")).toString(), "a - b"); + EXPECT_EQ((Variable("a") - Expression("b^2")).toString(), "a - b^2"); + EXPECT_EQ((10 - Expression("a+2")).toString(), "-a + 8"); + EXPECT_EQ((Variable("a") - Expression("a+2")).toString(), "-2"); + EXPECT_EQ((Expression("b+2") - Expression("a+2")).toString(), "-a + b"); + EXPECT_EQ((Expression("10+a^3") - Expression("a^2")).toString(), "a^3 - a^2 + 10"); + EXPECT_EQ((Expression("a*b") - Expression("b*a")).toString(), "0"); + EXPECT_EQ((Expression("a+b") - Expression("a+b")).toString(), "0"); } -TEST(ExpressionFunctionsTests, divTest) { - EXPECT_EQ(div(Variable("a"), Expression("b^2")).toString(), "a/(b^2)"); - EXPECT_EQ(div(10, Expression("a+2")).toString(), "10/(a + 2)"); - EXPECT_EQ(div(Variable("a"), Expression("a+2")).toString(), "1 - 2/(a + 2)"); - EXPECT_EQ(div(Expression("b+2"), Expression("a+2")).toString(), "(b + 2)/(a + 2)"); - EXPECT_EQ(div(Expression("10+a^3"), Expression("a^2")).toString(), "a + 10/(a^2)"); - EXPECT_EQ(div(Expression("a*b"), Expression("b*a")).toString(), "1"); - EXPECT_EQ(div(Expression("a+b"), Expression("a+b")).toString(), "1"); +TEST(ExpressionFunctionsTests, negTest) { + EXPECT_EQ((-Variable("a")).toString(), "-a"); + EXPECT_EQ((-Expression("a")).toString(), "-a"); + EXPECT_EQ((-Expression("a+3")).toString(), "-a - 3"); + EXPECT_EQ((-Expression("(a+b)^2")).toString(), "-a^2 - 2 a b - b^2"); } -TEST(ExpressionFunctionsTests, negTest) { - EXPECT_EQ(neg(Expression("a")).toString(), "-a"); - EXPECT_EQ(neg(Expression("a+3")).toString(), "-a - 3"); - EXPECT_EQ(neg(Expression("(a+b)^2")).toString(), "-a^2 - 2 a b - b^2"); +TEST(ExpressionFunctionsTests, mulTest) { + EXPECT_EQ((Variable("a") * Variable("a")).toString(), "a^2"); + EXPECT_EQ((Variable("a") * Variable("b")).toString(), "a b"); + EXPECT_EQ((Variable("a") * -1 * Expression("a*2")).toString(), "-2 a^2"); + EXPECT_EQ((10 * Expression("a+2")).toString(), "10 a + 20"); + EXPECT_EQ((Variable("a") * Expression("a^3+a^2")).toString(), "a^4 + a^3"); + EXPECT_EQ((5 * Expression("a+3") * Expression("a+2")).toString(), "5 a^2 + 25 a + 30"); + EXPECT_EQ((Expression("a+b") * Expression("3 b + c")).toString(), "3 a b + a c + 3 b^2 + b c"); +} + +TEST(ExpressionFunctionsTests, divTest) { + EXPECT_EQ((Variable("a") / Variable("a")).toString(), "1"); + EXPECT_EQ((Variable("a") / Variable("b")).toString(), "a/b"); + EXPECT_EQ((Variable("a") / Expression("b^2")).toString(), "a/(b^2)"); + EXPECT_EQ((10 / Expression("a+2")).toString(), "10/(a + 2)"); + EXPECT_EQ((Variable("a") / Expression("a+2")).toString(), "1 - 2/(a + 2)"); + EXPECT_EQ((Expression("b+2") / Expression("a+2")).toString(), "(b + 2)/(a + 2)"); + EXPECT_EQ((Expression("10+a^3") / Expression("a^2")).toString(), "a + 10/(a^2)"); + EXPECT_EQ((Expression("a*b") / Expression("b*a")).toString(), "1"); + EXPECT_EQ((Expression("a+b") / Expression("a+b")).toString(), "1"); } TEST(ExpressionFunctionsTests, eqvTest) { @@ -313,3 +331,11 @@ TEST(ExpressionFunctionsTests, negInfTest) { TEST(ExpressionFunctionsTests, complexInfTest) { EXPECT_EQ(complexInf().toString(), "ComplexInf"); } + +TEST(ExpressionFunctionsTests, negativeTest) { + EXPECT_THROW(Boolean(true) + Boolean(false), InvalidInputException); + EXPECT_THROW(Add() / Mul(), InvalidInputException); + EXPECT_THROW(sin(Boolean(true)), InvalidInputException); + EXPECT_THROW(eqv(Boolean(true), Boolean(false)), InvalidInputException); + EXPECT_THROW(orL(Integer(1), Integer(2)), InvalidInputException); +} diff --git a/tests/src/expressions/ExpressionTests.cpp b/tests/src/expressions/ExpressionTests.cpp index 87f045446..0fba33d51 100644 --- a/tests/src/expressions/ExpressionTests.cpp +++ b/tests/src/expressions/ExpressionTests.cpp @@ -97,66 +97,6 @@ TEST(ExpressionTests, equalsTest) { // TODO: implement more tests } -TEST(ExpressionTests, variableVariablePlusOperatorTest) { - EXPECT_EQ(Variable("a") + Variable("a"), Expression("2a")); - EXPECT_EQ(Variable("a") + Variable("b"), Expression("a+b")); -} - -TEST(ExpressionTests, variableExpressionPlusOperatorTest) { - EXPECT_EQ(Variable("a") + Expression("a+b"), Expression("2a+b")); - EXPECT_EQ(Variable("a") + Expression("b+c"), Expression("a+b+c")); -} - -TEST(ExpressionTests, expressionVariablePlusOperatorTest) { - EXPECT_EQ(Expression("a+b") + Variable("a"), Expression("2a+b")); - EXPECT_EQ(Expression("b+c") + Variable("a"), Expression("a+b+c")); -} - -TEST(ExpressionTests, variableVariableMinusOperatorTest) { - EXPECT_EQ(Variable("a") - Variable("a"), Expression("0")); - EXPECT_EQ(Variable("a") - Variable("b"), Expression("a-b")); -} - -TEST(ExpressionTests, variableExpressionMinusOperatorTest) { - EXPECT_EQ(Variable("a") - Expression("a-b"), Expression("b")); - EXPECT_EQ(Variable("a") - Expression("b-c"), Expression("a-b+c")); -} - -TEST(ExpressionTests, expressionVariableMinusOperatorTest) { - EXPECT_EQ(Expression("a-b") - Variable("a"), Expression("-b")); - EXPECT_EQ(Expression("b-c") - Variable("a"), Expression("-a+b-c")); -} - -TEST(ExpressionTests, variableVariableMultiplyOperatorTest) { - EXPECT_EQ(Variable("a") * Variable("a"), Expression("a^2")); - EXPECT_EQ(Variable("a") * Variable("b"), Expression("ab")); -} - -TEST(ExpressionTests, variableExpressionMultiplyOperatorTest) { - EXPECT_EQ(Variable("a") * Expression("a*b"), Expression("a^2 b")); - EXPECT_EQ(Variable("a") * Expression("b*c"), Expression("abc")); -} - -TEST(ExpressionTests, expressionVariableMultiplyOperatorTest) { - EXPECT_EQ(Expression("a*b") * Variable("a"), Expression("a^2 b")); - EXPECT_EQ(Expression("b*c") * Variable("a"), Expression("abc")); -} - -TEST(ExpressionTests, variableVariableDivideOperatorTest) { - EXPECT_EQ(Variable("a") / Variable("a"), Expression("1")); - EXPECT_EQ(Variable("a") / Variable("b"), Expression("a/b")); -} - -TEST(ExpressionTests, variableExpressionDivideOperatorTest) { - EXPECT_EQ(Variable("a") / Expression("a/b"), Expression("b")); - EXPECT_EQ(Variable("a") / Expression("b/c"), Expression("(ac)/b")); -} - -TEST(ExpressionTests, expressionVariableDivideOperatorTest) { - EXPECT_EQ(Expression("a/b") / Variable("a"), Expression("1/b")); - EXPECT_EQ(Expression("b/c") / Variable("a"), Expression("b/c/a")); -} - TEST(ExpressionTests, getClassTest) { EXPECT_EQ(Expression().getClass(), MathObjectClass("Expression")); EXPECT_EQ(Expression().getClassStatic().getParent(), IExpression::getClassStatic()); diff --git a/tests/src/expressions/IExpressionTests.cpp b/tests/src/expressions/IExpressionTests.cpp index 83f04f723..20e5552c8 100644 --- a/tests/src/expressions/IExpressionTests.cpp +++ b/tests/src/expressions/IExpressionTests.cpp @@ -104,13 +104,5 @@ TEST(IExpressionTests, toMinimalObjectTest) { TEST(IExpressionTests, getClassTest) { EXPECT_EQ(IExpression::getClassStatic(), MathObjectClass("IExpression")); - EXPECT_EQ(IExpression::getClassStatic().getParent(), IArithmetic::getClassStatic()); -} - -TEST(IExpressionTests, arithmeticTest) { - EXPECT_THROW(cast(*sinExpr(Integer(1).clone())) + cast(*sinExpr(Integer(1).clone())), InvalidInputException); - EXPECT_THROW(cast(*sinExpr(Integer(1).clone())) - cast(*sinExpr(Integer(1).clone())), InvalidInputException); - EXPECT_THROW(cast(*sinExpr(Integer(1).clone())) * cast(*sinExpr(Integer(1).clone())), InvalidInputException); - EXPECT_THROW(cast(*sinExpr(Integer(1).clone())) / cast(*sinExpr(Integer(1).clone())), InvalidInputException); - EXPECT_THROW(-cast(*sinExpr(Integer(1).clone())), InvalidInputException); + EXPECT_EQ(IExpression::getClassStatic().getParent(), IMathObject::getClassStatic()); }