From 3f94e7d88e43a9d7c7319c13f3a1cafc15fd6b8a Mon Sep 17 00:00:00 2001 From: Domenico Testa Date: Fri, 6 Feb 2026 02:21:22 +0100 Subject: [PATCH] fix: function recursive argument evaluation --- src/plotter/parser.py | 2 +- tests/test_parser.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/plotter/parser.py b/src/plotter/parser.py index 1a0ef1d..15de21a 100644 --- a/src/plotter/parser.py +++ b/src/plotter/parser.py @@ -176,7 +176,7 @@ class FunctionExpression(Expression): func = self._funcs.get(self.function) if not func: raise ValueError(f"Unknown function {self.function}") - return func(x) + return func(self.argument.eval(x)) @dataclass diff --git a/tests/test_parser.py b/tests/test_parser.py index 8913053..b99e3b4 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -255,7 +255,7 @@ def _neg(operand): ), ], ) -def test_unary_minus(expression, expected): +def test_unary_minus_parse(expression, expected): assert parse(expression) == expected @@ -271,7 +271,12 @@ def test_unary_minus(expression, expected): ("(-2)^2", 0, 4), # (-2)^2 = 4 ("pi", 0, math.pi), ("e", 0, math.e), + ("abs(-100)", 0, 100), + ("abs(pi)", 0, math.pi), + ("abs(x)", 0, 0), + ("abs(x)", -1.0, 1.0), + ("abs(cos(x))", 0, 1.0), ], ) -def test_unary_minus_eval(expression, x, expected): +def test_eval(expression, x, expected): assert parse(expression).eval(x) == expected