]> www.ginac.de Git - ginac.git/commitdiff
Add regression tests for built-in expression parser...
authorRichard Kreckel <kreckel@ginac.de>
Wed, 1 Jan 2025 00:52:12 +0000 (01:52 +0100)
committerRichard Kreckel <kreckel@ginac.de>
Wed, 1 Jan 2025 00:54:56 +0000 (01:54 +0100)
...involving functions and constants (and their evaluation).
And while at it, fix a stray comment from 30c85fbe.

check/exam_parser.cpp
ginac/matrix.cpp

index 082f33558118ea6d274516bd036c67147811310e..715f11cb0ed7e1897ecda20486ea378c512411b6 100644 (file)
@@ -196,9 +196,34 @@ static int check7(ostream& err_str)
                +check_eq(err_str, reader, "100++--+1+10", "111");
 }
 
+// Tests involving functions and constants (including their evaluation)
+static int check8(ostream& err_str)
+{
+       parser reader;
+       return
+               +check_eq(err_str, reader, "sqrt(x)+sqrt(x)", "2*sqrt(x)")
+               +check_eq(err_str, reader, "sqrt(x)-sqrt(x)", "0")
+               +check_eq(err_str, reader, "sqrt(x)+sqrt(y)", "sqrt(x)+sqrt(y)")
+               +check_eq(err_str, reader, "sqrt(x)^2", "x")
+               +check_eq(err_str, reader, "sqrt(x^2)", "sqrt(x^2)")
+               +check_eq(err_str, reader, "pow(x^2,2)", "pow(x,4)")
+               +check_eq(err_str, reader, "pow(x^(1/2),2)", "x")
+               +check_eq(err_str, reader, "pow(z^1/2,2)", "(z^2)/4")
+               +check_eq(err_str, reader, "log(x)+log(x)", "2*log(x)")
+               +check_eq(err_str, reader, "log(x)-log(x)", "0")
+               +check_eq(err_str, reader, "exp(log(x))", "x")
+               +check_eq(err_str, reader, "log(exp(x))", "log(exp(x))")
+               +check_eq(err_str, reader, "sin(asin(x))", "x")
+               +check_eq(err_str, reader, "asin(sin(x))", "asin(sin(x))")
+               +check_eq(err_str, reader, "cos(acos(x))", "x")
+               +check_eq(err_str, reader, "cos(acos(asin(sin(tan(atan(x))))))", "asin(sin(x))")
+               +check_eq(err_str, reader, "cos(Pi)+sin(Pi/2)", "0")
+               +check_eq(err_str, reader, "Pi-I-2+Euler", "Euler+Pi-I-2");
+}
+
 int main(int argc, char** argv)
 {
-       cout << "examining old parser bugs" << flush;
+       cout << "examining parser" << flush;
        ostringstream err_str;
        int errors = 0;
        errors += check1(err_str);  cout << '.' << flush;
@@ -208,11 +233,10 @@ int main(int argc, char** argv)
        errors += check5(err_str);  cout << '.' << flush;
        errors += check6(err_str);  cout << '.' << flush;
        errors += check7(err_str);  cout << '.' << flush;
+       errors += check8(err_str);  cout << '.' << flush;
        if (errors) {
-               cout << "Yes, unfortunately:" << endl;
-               cout << err_str.str();
-       } else {
-               cout << "Not found. ";
+               clog << "Yes, unfortunately: " << endl;
+               clog << err_str.str();
        }
        return errors;
 }
index a89107871387bd5cb9defe5eebcb4a4828d05b1f..650c0c253945a708f7e817ae58bc102f615e3907 100644 (file)
@@ -33,7 +33,6 @@
 #include "archive.h"
 #include "utils.h"
 
-//#include <algorithm>
 #include <map>
 #include <sstream>
 #include <stdexcept>