From 17515f11fde916e3d3a476c0948f768dd831fc71 Mon Sep 17 00:00:00 2001 From: Richard Kreckel Date: Wed, 1 Jan 2025 01:52:12 +0100 Subject: [PATCH] Add regression tests for built-in expression parser... ...involving functions and constants (and their evaluation). And while at it, fix a stray comment from 30c85fbe. --- check/exam_parser.cpp | 34 +++++++++++++++++++++++++++++----- ginac/matrix.cpp | 1 - 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/check/exam_parser.cpp b/check/exam_parser.cpp index 082f3355..715f11cb 100644 --- a/check/exam_parser.cpp +++ b/check/exam_parser.cpp @@ -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; } diff --git a/ginac/matrix.cpp b/ginac/matrix.cpp index a8910787..650c0c25 100644 --- a/ginac/matrix.cpp +++ b/ginac/matrix.cpp @@ -33,7 +33,6 @@ #include "archive.h" #include "utils.h" -//#include #include #include #include -- 2.49.0