From b5eeb1c378633ce05f88434870726ce05e5e73eb Mon Sep 17 00:00:00 2001 From: Juan Mauricio Matera Date: Sat, 3 Aug 2024 18:10:36 -0300 Subject: [PATCH] fix comparisons (issue #797) (#975) This PR fixes #797, it is, handles comparisons involving one side with a numeric expression and the other one with an expression involving strings. --- CHANGES.rst | 3 ++- mathics/eval/testing_expressions.py | 4 ++++ test/builtin/test_comparison.py | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 9c2a59f91..c233ec27a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -47,7 +47,8 @@ Bugs * ``Switch[]`` involving ``Infinity`` Issue #956 * ``Outer[]`` on ``SparseArray`` Issue #939 * ``ArrayQ[]`` detects ``SparseArray`` PR #947 - +* Numeric comparisons against expressions involving ``String``s (Issue #797). + Package updates +++++++++++++++ diff --git a/mathics/eval/testing_expressions.py b/mathics/eval/testing_expressions.py index 503e20a60..c37bb0f6e 100644 --- a/mathics/eval/testing_expressions.py +++ b/mathics/eval/testing_expressions.py @@ -20,7 +20,11 @@ def do_cmp(x1, x2) -> Optional[int]: return None s1 = x1.to_sympy() + if s1 is None: + return None s2 = x2.to_sympy() + if s2 is None: + return None # Use internal comparisons only for Real which is uses # WL's interpretation of equal (which allows for slop diff --git a/test/builtin/test_comparison.py b/test/builtin/test_comparison.py index 386b3123d..a2fc847c6 100644 --- a/test/builtin/test_comparison.py +++ b/test/builtin/test_comparison.py @@ -78,6 +78,14 @@ ("g[a]3', "Wo[x] > 3", "isue #797"), + ('Wo["x"]<3', "Wo[x] < 3", "isue #797"), + ('Wo["x"]==3', "Wo[x] == 3", "isue #797"), + ('3>Wo["x"]', "3 > Wo[x]", "isue #797"), + ('30', "Wo[f[x], 2] > 0", "isue #797"), + # # chained compare ("a != a != b", "False", "Strange MMA behavior"), ("a != b != a", "a != b != a", "incomparable values should be unchanged"),