From fc6d57ffb8d5ddb5820fcc00b5491a585c259ebc Mon Sep 17 00:00:00 2001 From: Yuren Hao Date: Thu, 4 Sep 2025 22:16:22 -0500 Subject: Initial commit --- .../evaluation/latex2sympy/tests/atom_expr_test.py | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 Qwen2.5-Eval/evaluation/latex2sympy/tests/atom_expr_test.py (limited to 'Qwen2.5-Eval/evaluation/latex2sympy/tests/atom_expr_test.py') diff --git a/Qwen2.5-Eval/evaluation/latex2sympy/tests/atom_expr_test.py b/Qwen2.5-Eval/evaluation/latex2sympy/tests/atom_expr_test.py new file mode 100755 index 0000000..23b69b4 --- /dev/null +++ b/Qwen2.5-Eval/evaluation/latex2sympy/tests/atom_expr_test.py @@ -0,0 +1,58 @@ +from .context import assert_equal +import pytest +from sympy import Symbol, Integer, Pow + +# label, text, symbol_text +symbols = [ + ('letter', 'x', 'x'), + ('greek letter', '\\lambda', 'lambda'), + ('greek letter w/ space', '\\alpha ', 'alpha'), + ('accented letter', '\\overline{x}', 'xbar') +] + +subscripts = [ + ('2'), + ('{23}'), + ('i'), + ('{ij}'), + ('{i,j}'), + ('{good}'), + ('{x^2}') +] + +examples = [] +for symbol in symbols: + for subscript in subscripts: + examples.append(tuple(list(symbol) + [subscript])) + + +@pytest.mark.parametrize('label, text, symbol_text, subscript', examples) +def test_with_supexpr(label, text, symbol_text, subscript): + assert_equal(text + '^2', Pow(Symbol(symbol_text, real=True), Integer(2))) + + +@pytest.mark.parametrize('label, text, symbol_text, subscript', examples) +def test_with_subexpr(label, text, symbol_text, subscript): + assert_equal(text + '_' + subscript, Symbol(symbol_text + '_' + subscript, real=True)) + + +@pytest.mark.parametrize('label, text, symbol_text, subscript', examples) +def test_with_subexpr_before_supexpr(label, text, symbol_text, subscript): + assert_equal(text + '_' + subscript + '^2', Pow(Symbol(symbol_text + '_' + subscript, real=True), Integer(2))) + + +@pytest.mark.parametrize('label, text, symbol_text, subscript', examples) +def test_with_subexpr_before_supexpr_with_braces(label, text, symbol_text, subscript): + wrapped_subscript = subscript if '{' in subscript else '{' + subscript + '}' + assert_equal(text + '_' + wrapped_subscript + '^{2}', Pow(Symbol(symbol_text + '_' + subscript, real=True), Integer(2))) + + +@pytest.mark.parametrize('label, text, symbol_text, subscript', examples) +def test_with_supexpr_before_subexpr(label, text, symbol_text, subscript): + assert_equal(text + '^2_' + subscript, Pow(Symbol(symbol_text + '_' + subscript, real=True), Integer(2))) + + +@pytest.mark.parametrize('label, text, symbol_text, subscript', examples) +def test_with_supexpr_before_subexpr_with_braces(label, text, symbol_text, subscript): + wrapped_subscript = subscript if '{' in subscript else '{' + subscript + '}' + assert_equal(text + '^{2}_' + wrapped_subscript, Pow(Symbol(symbol_text + '_' + subscript, real=True), Integer(2))) -- cgit v1.2.3