From 738f533f0b5bed68ef77539a6f1638df8db7c1c5 Mon Sep 17 00:00:00 2001 From: Marcus Messer Date: Sat, 24 Oct 2026 13:27:40 +0100 Subject: [PATCH] Added a preview test for big-operator task symbols Ports the preview test from #261: with infsum written as \sum_{n=1}^{\infty}, infsum((-1)^n/n^2) previews with the summand inside the sum, not as a product with the sum inside the fraction. The fix is in lambda-feedback-packages#11. Co-Authored-By: Claude Opus 5.5 --- app/tests/symbolic_preview_test.py | 42 ++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/app/tests/symbolic_preview_test.py b/app/tests/symbolic_preview_test.py index bdde208..cbc2791 100644 --- a/app/tests/symbolic_preview_test.py +++ b/app/tests/symbolic_preview_test.py @@ -362,3 +362,45 @@ def test_curly_brace_multiple_answers_still_works(self, strict_syntax): result = preview_function("{1, 2}", params) assert result["preview"]["latex"] == "\\left\\{1,~2\\right\\}" assert result["preview"]["sympy"] == "{1, 2}" + + @pytest.mark.parametrize( + "response, latex, sympy", [ + # summation() with explicit bounds, rendered by SymPy + ( + "summation((4/n**2)(-1)**n cos(nx), (n, 1, oo))", + r"\sum_{n=1}^{\infty} \frac{4 \cdot \left(-1\right)^{n} \cdot \cos{\left(n \cdot x \right)}}{n^{2}}", + "summation((4/n**2)(-1)**n cos(nx), (n, 1, oo))", + ), + # infsum is a task symbol written as a big operator: its argument goes inside the sum + ( + "infsum((-1)^n / n^2)", + r"\sum_{n=1}^{\infty} \frac{\left(-1\right)^{n}}{n^{2}}", + "infsum((-1)^n / n^2)", + ), + ( + "infsum((4/n^2)*(-1)^n*cos(nx))", + r"\sum_{n=1}^{\infty} \frac{4 \cdot \left(-1\right)^{n} \cdot \cos{\left(n \cdot x \right)}}{n^{2}}", + "infsum((4/n^2)*(-1)^n* cos(nx))", + ), + ( + "((pi^2)/(3))+infsum((4/n^2)*(-1)^n*cos(nx))", + r"\frac{\pi^{2}}{3} + \sum_{n=1}^{\infty} \frac{4 \cdot \left(-1\right)^{n} \cdot \cos{\left(n \cdot x \right)}}{n^{2}}", + "(( pi^2)/(3))+infsum((4/n^2)*(-1)^n* cos(nx))", + ), + ] + ) + def test_sum_preview(self, response, latex, sympy): + # From #261: infsum((-1)^n/n^2) was the product infsum*(...), so the sum was printed inside the fraction. + params = { + "is_latex": False, + "strict_syntax": False, + "elementary_functions": True, + "symbols": { + "infsum": {"aliases": [], "latex": "\\sum_{n=1}^{\\infty}"}, + "pi": {"aliases": [], "latex": "\\pi"}, + }, + } + + result = preview_function(response, params) + assert result["preview"]["latex"] == latex + assert result["preview"]["sympy"] == sympy