Skip to content

Commit

Permalink
Uncomment fintamath tests & add some new
Browse files Browse the repository at this point in the history
  • Loading branch information
fintarin committed Sep 21, 2023
1 parent def1c2f commit 1a8aa3c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 51 deletions.
4 changes: 2 additions & 2 deletions src/fintamath/functions/powers/Root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ std::unique_ptr<IMathObject> Root::call(const ArgumentsRefVector &argsVect) cons
return mulExpr(multiRootSimplify(*(-lhs), rhsInt), I()())->toMinimalObject();
}

// TODO: solve complex nth roots
// TODO: complex nth roots
return {};
}

Expand Down Expand Up @@ -129,7 +129,7 @@ std::unique_ptr<IMathObject> Root::perfectRoot(const Integer &lhs, const Integer
return lhs.clone();
}

if (rhs == 2) { // TODO: implement perfect nth-roots minimization
if (rhs == 2) { // TODO: perfect nth-roots
Integer remainder;
Integer lhsSqrt = sqrt(lhs, remainder);

Expand Down
110 changes: 61 additions & 49 deletions tests/src/FintamathTests.cpp
Original file line number Diff line number Diff line change
@@ -1,71 +1,83 @@
// #include <gtest/gtest.h>
#include <gtest/gtest.h>

// #include "fintamath/expressions/Expression.hpp"
// #include "fintamath/expressions/ExpressionFunctions.hpp"
// #include "fintamath/literals/Variable.hpp"
// #include "fintamath/literals/constants/E.hpp"
// #include "fintamath/literals/constants/Pi.hpp"
// #include "fintamath/numbers/Real.hpp"
#include "fintamath/expressions/Expression.hpp"
#include "fintamath/expressions/ExpressionFunctions.hpp"
#include "fintamath/literals/Variable.hpp"
#include "fintamath/literals/constants/E.hpp"
#include "fintamath/literals/constants/Pi.hpp"
#include "fintamath/numbers/Real.hpp"

// using namespace fintamath;
using namespace fintamath;

// TEST(FintamathTests, fintamathTests) {
// Expression expr;
// Variable x("x");
// Variable y("y");
TEST(FintamathTests, fintamathTests) {
Expression expr;
Variable x("x");
Variable y("y");

// //-------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------//

// expr = add(e(), pi(), Variable("a"), Variable("b"));
// EXPECT_EQ(expr.toString(), "a + b + E + Pi");
expr = add(e(), pi(), Variable("a"), Variable("b"));
EXPECT_EQ(expr.toString(), "a + b + E + Pi");

// expr = mul(e(), pi(), Variable("a"), Variable("b"));
// EXPECT_EQ(expr.toString(), "E Pi a b");
expr = mul(e(), pi(), Variable("a"), Variable("b"));
EXPECT_EQ(expr.toString(), "E Pi a b");

// expr = pow(Variable("a"), Variable("b")) * Variable("c");
// EXPECT_EQ(expr.toString(), "a^b c");
expr = pow(Variable("a"), Variable("b")) * Variable("c");
EXPECT_EQ(expr.toString(), "a^b c");

// expr = x * x * x * y + 10 * x;
// EXPECT_EQ(expr.toString(), "x^3 y + 10 x");
expr = x * x * x * y + 10 * x;
EXPECT_EQ(expr.toString(), "x^3 y + 10 x");

// expr = x + 10 * x / 10 + (sqrt(x) * 2);
// EXPECT_EQ(expr.toString(), "2 x + 2 sqrt(x)");
expr = x + 10 * x / 10 + (sqrt(x) * 2);
EXPECT_EQ(expr.toString(), "2 x + 2 sqrt(x)");

// expr = eqv(x * x + y * y * y, x * y);
// EXPECT_EQ(expr.toString(), "x^2 - x y + y^3 = 0");
expr = eqv(x * x + y * y * y, x * y);
EXPECT_EQ(expr.toString(), "x^2 - x y + y^3 = 0");

// expr = eqv(x * x + y * y, x * y);
// EXPECT_EQ(expr.toString(), "x^2 - x y + y^2 = 0");
expr = eqv(x * x + y * y, x * y);
EXPECT_EQ(expr.toString(), "x^2 - x y + y^2 = 0");

// expr = eqv(x / x - y / y, x / y);
// EXPECT_EQ(expr.toString(), "x = 0");
expr = eqv(x / x - y / y, x / y);
EXPECT_EQ(expr.toString(), "x = 0");

// expr = Expression("(4x^4 + 1 + 3x^3 + 2x) / (x^2 + x + 2)");
// EXPECT_EQ(expr.toString(), "4 x^2 - x - 7 + (11 x + 15)/(x^2 + x + 2)");
expr = Expression("(4x^4 + 1 + 3x^3 + 2x) / (x^2 + x + 2)");
EXPECT_EQ(expr.toString(), "4 x^2 - x - 7 + (11 x + 15)/(x^2 + x + 2)");

// expr = log(2, 256) + ln(pow(e(), 2));
// EXPECT_EQ(expr.toString(), "10");
expr = log(2, 256) + ln(pow(e(), 2));
EXPECT_EQ(expr.toString(), "10");

// expr = sqrt(Expression(8));
// EXPECT_EQ(expr.toString(), "2 sqrt(2)");
expr = sqrt(Expression(8));
EXPECT_EQ(expr.toString(), "2 sqrt(2)");

// expr = pow(Expression("244706656946119777797996531655819747089832578"), Rational(1, 4));
// EXPECT_EQ(expr.toString(), "sqrt(11) root(2022369065670411386760301914510907000742418, 4)");
expr = pow(Expression("244706656946119777797996531655819747089832578"), Rational(1, 4));
EXPECT_EQ(expr.toString(), "sqrt(11) root(2022369065670411386760301914510907000742418, 4)");

// expr = sin(asin(Variable(x))) + cos(acos(Integer(1)));
// EXPECT_EQ(expr.toString(), "x + 1");
expr = sin(asin(Variable(x))) + cos(acos(Integer(1)));
EXPECT_EQ(expr.toString(), "x + 1");

// expr = Expression("~a & b | ~c -> a <-> b !<-> c");
// EXPECT_EQ(expr.toString(), "(a & b & ~c) | (~a & ~b & ~c) | (~a & c) | (~b & c)");
expr = pow(sin(x), 2) + pow(cos(x), 2) + tan(x) * cot(x);
EXPECT_EQ(expr.toString(), "2");

// //-------------------------------------------------------------------------------------//
expr = sin(Expression("-3Pi/2")) + cos(Expression("Pi/4"));
EXPECT_EQ(expr.toString(), "sqrt(2)/2 + 1");

// expr = eqv(pow(x, 2) - 10, 39);
// EXPECT_EQ(solve(expr).toString(), "x = -7 | x = 7");
expr = Expression("~a & b | ~c -> a <-> b !<-> c");
EXPECT_EQ(expr.toString(), "(a & b & ~c) | (~a & ~b & ~c) | (~a & c) | (~b & c)");

// expr = Expression("-4x^2 + 28x - 49 = 0");
// EXPECT_EQ(solve(expr).toString(), "x = 7/2");
//-------------------------------------------------------------------------------------//

// expr = Expression("-3x^2 + 28x - 49 = 0");
// EXPECT_EQ(solve(expr).precise(2).toString(), "x = 2.3 | x = 7.0");
// }
expr = eqv(pow(x, 2) - 10, 39);
EXPECT_EQ(solve(expr).toString(), "x = -7 | x = 7");

expr = Expression("-4x^2 + 28x - 49 = 0");
EXPECT_EQ(solve(expr).toString(), "x = 7/2");

expr = Expression("x^2 + 4x + 5 = 0");
EXPECT_EQ(solve(expr).toString(), "x = -2 - I | x = -2 + I");

expr = Expression("3x^2 + 11x + 15 = 0");
EXPECT_EQ(solve(expr).toString(), "x = -1/6 I sqrt(59) - 11/6 | x = 1/6 I sqrt(59) - 11/6");

expr = Expression("-3x^2 + 28x - 49 = 0");
EXPECT_EQ(solve(expr).precise(2).toString(), "x = 2.3 | x = 7.0");
}

0 comments on commit 1a8aa3c

Please sign in to comment.