From 64517031c92592432a7ed4441030426fa51047a5 Mon Sep 17 00:00:00 2001 From: KarlLundengaard <106549720+KarlLundengaard@users.noreply.github.com> Date: Mon, 30 Jun 2025 12:30:08 +0100 Subject: [PATCH] Changed content of the sympy field in the result when input is not latex Changed content of the sympy field in the result when input is not latex --- app/example_tests.py | 36 +++++++++++++++++++++++++----- app/symbolic_comparison_preview.py | 2 +- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/app/example_tests.py b/app/example_tests.py index 656c98e..68b9d9f 100644 --- a/app/example_tests.py +++ b/app/example_tests.py @@ -47,12 +47,36 @@ def test_setting_input_symbols_to_be_assumed_positive_to_avoid_issues_with_fract @pytest.mark.parametrize( "response, is_latex, response_latex", [ - (r"\pm x^{2}+\mp y^{2}", True, r"\left\{x^{2} - y^{2},~- x^{2} + y^{2}\right\}"), - ("plus_minus x**2 + minus_plus y**2", False, r"\left\{x^{2} - y^{2},~- x^{2} + y^{2}\right\}"), - ("- minus_plus x^2 minus_plus y^2", False, r"\left\{- x^{2} + y^{2},~x^{2} - y^{2}\right\}"), - ("- minus_plus x^2 - plus_minus y^2", False, r"\left\{x^{2} - y^{2},~- x^{2} - - y^{2}\right\}"), - ("pm x**2 + mp y**2", False, r"\left\{x^{2} - y^{2},~- x^{2} + y^{2}\right\}"), - ("+- x**2 + -+ y**2", False, r"\left\{x^{2} - y^{2},~- x^{2} + y^{2}\right\}"), + ( + r"\pm x^{2}+\mp y^{2}", + True, + r"\left\{x^{2} - y^{2},~- x^{2} + y^{2}\right\}" + ), + ( + "plus_minus x**2 + minus_plus y**2", + False, + r"\left\{x^{2} - y^{2},~- x^{2} + y^{2}\right\}" + ), + ( + "- minus_plus x^2 minus_plus y^2", + False, + r"\left\{- x^{2} + y^{2},~x^{2} - y^{2}\right\}" + ), + ( + "- minus_plus x^2 - plus_minus y^2", + False, + r"\left\{x^{2} - y^{2},~- x^{2} - - y^{2}\right\}" + ), + ( + "pm x**2 + mp y**2", + False, + r"\left\{x^{2} - y^{2},~- x^{2} + y^{2}\right\}" + ), + ( + "+- x**2 + -+ y**2", + False, + r"\left\{x^{2} - y^{2},~- x^{2} + y^{2}\right\}" + ), ] ) def test_using_plus_minus_symbols(self, response, is_latex, response_latex): diff --git a/app/symbolic_comparison_preview.py b/app/symbolic_comparison_preview.py index 49ffacb..350663e 100644 --- a/app/symbolic_comparison_preview.py +++ b/app/symbolic_comparison_preview.py @@ -98,7 +98,7 @@ def preview_function(response: str, params: Params, join_sympy=True) -> Result: sympy_out = [] for expression in expression_list: latex_out.append(sympy_to_latex(expression, symbols, settings = {"mul_symbol": r" \cdot "})) - sympy_out.append(str(expression)) + sympy_out.append(response) if len(sympy_out) == 1: sympy_out = sympy_out[0]