Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fintarin committed Jul 2, 2023
1 parent bde7468 commit 62d685e
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions tests/src/expressions/ExpressionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ TEST(ExpressionTests, stringConstructorTest) {
EXPECT_EQ(Expression("(a b)^-1").toString(), "1/(a b)");
EXPECT_EQ(Expression("(a b)^-2").toString(), "1/(a^2 b^2)");

EXPECT_EQ(Expression("7 2^(2/3)").toString(), "7*2^(2/3)");
EXPECT_EQ(Expression("2^(2/3) 3^(2/3)").toString(), "6^(2/3)");
EXPECT_EQ(Expression("2^x 3^x").toString(), "6^x");

EXPECT_EQ(Expression("2%a").toString(), "1/50 a");
EXPECT_EQ(Expression("2!!!!a!!!").toString(), "2 a!!!");
EXPECT_EQ(Expression("sin a").toString(), "sin(a)");
Expand Down Expand Up @@ -323,6 +327,20 @@ TEST(ExpressionTests, stringConstructorTest) {
EXPECT_EQ(Expression("(6x^8 - 7x^6 + 9x^4 - 4x^2 + 8) / (2x^3 - x^2 + 3x - 1)").toString(),
"3 x^5 + 3/2 x^4 - 29/4 x^3 - 35/8 x^2 + 223/16 x + 317/32 + (-1289 x^2 - 505 x + 573)/(64 x^3 - 32 x^2 + "
"96 x - 32)");
EXPECT_EQ(
Expression("(x^(4/3) - 8x^(1/3) y)/(x^(2/3) + 2 * (xy)^(1/3) + 4y^(2/3)) / (1 - 2 * (y/x)^(1/3))").toString(),
"1");
EXPECT_EQ(Expression("((2xy)/(x^2 - y^2) + (x - y)/(2x + 2y)) * (2x)/(x + y) + y/(y - x)").toString(), "x^(2/3)");
EXPECT_EQ(Expression("(2xy)^(1/3) * (4x^2 y)^(1/3) * (27y)^(1/3)").toString(), "3 4^(1/3) 2^(1/3) x y");

EXPECT_EQ(Expression("(x/y)^2").toString(), "(x^2)/(y^2)");
EXPECT_EQ(Expression("sqrt(x^2)").toString(), "abs(x)");
EXPECT_EQ(Expression("(x^10)^(1/10))").toString(), "abs(x)");
EXPECT_EQ(Expression("(x^3)^(1/3)").toString(), "x");
EXPECT_EQ(Expression("sqrt(x)^2").toString(), "x");
EXPECT_EQ(Expression("sqrt(x) * sqrt(x)").toString(), "x");
EXPECT_EQ(Expression("abs(x)^3").toString(), "abs(x^3)");
EXPECT_EQ(Expression("abs(x^3)").toString(), "abs(x^3)");

EXPECT_EQ(Expression("(a+b+1-1)^1000/(a+b+1-1)^998").toString(), "a^2 + 2 a b + b^2");
EXPECT_EQ(Expression("(a+b)^1000/(a+b)^998").toString(), "a^2 + 2 a b + b^2");
Expand Down Expand Up @@ -361,8 +379,7 @@ TEST(ExpressionTests, stringConstructorTest) {
EXPECT_EQ(Expression("cos(b) log(b, a)").toString(), "log(b, a) cos(b)");
EXPECT_EQ(Expression("cos(a) log(b, c)").toString(), "log(b, c) cos(a)");
EXPECT_EQ(Expression("cos(b^2) log(b, c)").toString(), "log(b, c) cos(b^2)");
// EXPECT_EQ(Expression("(x + y^(3))^(2) * (sin(x))/(ln(2)) / x^(2) - (2 sin(x) y^(3))/(x ln(2))").toString(),
// "TODO"); // TODO! fix sort
EXPECT_EQ(Expression("(x + y^(3))^(2) * (sin(x))/(ln(2)) / x^(2) - (2 sin(x) y^(3))/(x ln(2))").toString(), "TODO");

EXPECT_EQ(Expression("a=a").toString(), "True");
EXPECT_EQ(Expression("a+a=2*a").toString(), "True");
Expand Down Expand Up @@ -561,10 +578,8 @@ TEST(ExpressionTests, stringConstructorTest) {
EXPECT_EQ(Expression("ln((10 E)^2) - ln(10 E 10 E)").toString(), "0");
EXPECT_EQ(Expression("ln((10 E)^2) - 2 ln(10 E)").toString(), "0");
EXPECT_EQ(Expression("3 ln((10 E)^2) - 2 ln(10 E)").toString(), "ln(10000 E^4)");
EXPECT_EQ(Expression("ln((10 E)^(2ab)) - 2 a ln(10 E) b").toString(),
"ln(10^(2 a b) E^(2 a b) 10^(-2 a b) E^(-2 a b))"); // TODO: 0 - mul powers minimization
EXPECT_EQ(Expression("ln((10 E)^(2 ln(2))) - 2 ln(2) ln(10 E)").toString(),
"ln(10^0 E^0)"); // TODO: 0 - mul powers minimization
EXPECT_EQ(Expression("ln((10 E)^(2ab)) - 2 a ln(10 E) b").toString(), "0");
EXPECT_EQ(Expression("ln((10 E)^(2 ln(2))) - 2 ln(2) ln(10 E)").toString(), "0");
EXPECT_EQ(Expression("log(2.3,(E)/(20000.1EE)) + log(2.3,20000.1E)").toString(), "0");
EXPECT_EQ(Expression("log(2, 3) + log(3, 4)").toString(), "log(3, 4) + log(2, 3)");
EXPECT_EQ(Expression("x log(2, 3) + log(2, 5)").toString(), "log(2, 5 3^x)");
Expand Down

0 comments on commit 62d685e

Please sign in to comment.