--------------------------------------------------------------------------- \brief Evaluate a test expression. \return 1 in case of a failure, 0 otherwise. */
| 1416 | \return 1 in case of a failure, 0 otherwise. |
| 1417 | */ |
| 1418 | int ParserTester::EqnTestLocalized(const string_type& a_str, double a_fRes, bool /*a_fPass*/) |
| 1419 | { |
| 1420 | ParserTester::c_iCount++; |
| 1421 | |
| 1422 | try |
| 1423 | { |
| 1424 | Parser p; |
| 1425 | value_type var[2] = { 1, 2 }; |
| 1426 | |
| 1427 | // variable |
| 1428 | p.SetDecSep(','); |
| 1429 | p.SetArgSep(';'); |
| 1430 | p.SetThousandsSep('.'); |
| 1431 | |
| 1432 | p.DefineVar(_T("a"), &var[0]); |
| 1433 | p.DefineVar(_T("b"), &var[1]); |
| 1434 | p.SetExpr(a_str); |
| 1435 | |
| 1436 | auto result = p.Eval(); |
| 1437 | |
| 1438 | if (fabs(result - a_fRes) > 0.0000000001) |
| 1439 | throw std::runtime_error("incorrect result (first pass)"); |
| 1440 | } |
| 1441 | catch (Parser::exception_type& e) |
| 1442 | { |
| 1443 | mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (") << e.GetMsg() << _T(")"); |
| 1444 | return 1; |
| 1445 | } |
| 1446 | catch (std::exception& e) |
| 1447 | { |
| 1448 | mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (") << e.what() << _T(")"); |
| 1449 | return 1; // always return a failure since this exception is not expected |
| 1450 | } |
| 1451 | catch (...) |
| 1452 | { |
| 1453 | mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (unexpected exception)"); |
| 1454 | return 1; // exceptions other than ParserException are not allowed |
| 1455 | } |
| 1456 | |
| 1457 | return 0; |
| 1458 | } |
| 1459 | |
| 1460 | //--------------------------------------------------------------------------- |
| 1461 | /** \brief Evaluate a tet expression. |