diff --git a/mathics/builtin/testing_expressions/numerical_properties.py b/mathics/builtin/testing_expressions/numerical_properties.py index 6b6612ee5..4d9a59ca2 100644 --- a/mathics/builtin/testing_expressions/numerical_properties.py +++ b/mathics/builtin/testing_expressions/numerical_properties.py @@ -12,7 +12,7 @@ from mathics.core.convert.python import from_bool, from_python from mathics.core.evaluation import Evaluation from mathics.core.expression import Expression -from mathics.core.number import is_machine_precision, is_numeric +from mathics.core.number import get_int_value, is_machine_precision, is_numeric from mathics.core.symbols import BooleanType, SymbolFalse, SymbolTrue from mathics.core.systemsymbols import SymbolExpandAll, SymbolSimplify from mathics.eval.arithmetic import test_zero_arithmetic_expr @@ -99,7 +99,7 @@ class EvenQ(Test): summary_text = "test whether elements are even numbers" def test(self, n) -> bool: - value = n.int_value + value = get_int_value(n) return value is not None and value % 2 == 0 @@ -408,7 +408,7 @@ class OddQ(Test): summary_text = "test whether elements are odd numbers" def test(self, n) -> bool: - value = n.int_value + value = get_int_value(n) return value is not None and value % 2 != 0 @@ -557,7 +557,7 @@ class PrimeQ(SympyFunction): def eval(self, n, evaluation: Evaluation) -> BooleanType: "PrimeQ[n_]" - n = n.int_value + n = get_int_value(n) if n is None: return SymbolFalse diff --git a/test/builtin/test_testing_expressions.py b/test/builtin/test_testing_expressions.py index 4dd16437f..7c25af60f 100644 --- a/test/builtin/test_testing_expressions.py +++ b/test/builtin/test_testing_expressions.py @@ -134,6 +134,12 @@ def test_equality_inequality(str_expr, msgs, str_expected, fail_msg): ("Positive[Sin[{11, 14}]]", None, "{False, True}", None), ("PrimeQ[1]", None, "False", None), ("PrimeQ[2 ^ 255 - 1]", None, "False", None), + # Non-atomic arguments + ("EvenQ[f[2]]", None, "False", "Non-atomic EvenQ check"), + ("OddQ[f[1]]", None, "False", "Non-atomic OddQ check"), + ("PrimeQ[f[2]]", None, "False", "Non-atomic PrimeQ check"), + ("MatchQ[f[2], _?EvenQ]", None, "False", None), + ("Cases[{2, f[2], 3}, _?OddQ]", None, "{3}", None), ], ) def test_numerical_properties(str_expr, msgs, str_expected, fail_msg):