From 67a6f756f22d757b308333b42202a21c5f85fe63 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Fri, 24 Nov 2017 23:04:44 -0800 Subject: [PATCH] Add some math tests for invalid inputs --- muparser-2.2.5/src/muParser.cpp | 2 +- tests/math.err | 7 +++++++ tests/math.in | 6 ++++++ tests/math.out | 3 +++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/muparser-2.2.5/src/muParser.cpp b/muparser-2.2.5/src/muParser.cpp index 6d19b9f25..5e4e7bb25 100644 --- a/muparser-2.2.5/src/muParser.cpp +++ b/muparser-2.2.5/src/muParser.cpp @@ -168,7 +168,7 @@ ValueOrError Parser::Min(const value_type *a_afArg, int a_iArgc) { \param [in] a_iArgc The size of a_afArg */ ValueOrError Parser::Max(const value_type *a_afArg, int a_iArgc) { - if (!a_iArgc) throw exception_type(_T("too few arguments for function min.")); + if (!a_iArgc) throw exception_type(_T("too few arguments for function max.")); value_type fRes = a_afArg[0]; for (int i = 0; i < a_iArgc; ++i) fRes = std::max(fRes, a_afArg[i]); diff --git a/tests/math.err b/tests/math.err index 5a7ab5130..212b31850 100644 --- a/tests/math.err +++ b/tests/math.err @@ -4,3 +4,10 @@ #################### # Validate how variables in an expression are handled + +#################### +# Validate math error reporting +math: Invalid expression: Too few parameters for function "min" at expression position 5 +math: Invalid expression: String value used where a numerical argument is expected. +math: Invalid expression: Too few parameters for function "max" at expression position 5 +math: Invalid expression: Too few parameters for function "sum" at expression position 5 diff --git a/tests/math.in b/tests/math.in index 1e13114d7..8fa48595f 100644 --- a/tests/math.in +++ b/tests/math.in @@ -22,3 +22,9 @@ set x 3 set y 1.5 math "-$x * $y" math -s1 "-$x * $y" + +logmsg Validate math error reporting +not math 'min()' +not math 'min("abc")' +not math 'max()' +not math 'sum()' diff --git a/tests/math.out b/tests/math.out index df8607f71..7ddcac4a0 100644 --- a/tests/math.out +++ b/tests/math.out @@ -22,3 +22,6 @@ 2 -4 -4.5 + +#################### +# Validate math error reporting