+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;
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;
}