diff options
| author | zitian-gao <zitian.gao@outlook.com> | 2025-05-27 16:45:31 +0800 |
|---|---|---|
| committer | zitian-gao <zitian.gao@outlook.com> | 2025-05-27 16:45:31 +0800 |
| commit | 7c792461c8e4e4f1f8734fed143630c74e76b27f (patch) | |
| tree | cf6341ff9f2727424751da7a11a3bea6c39015bb /Qwen2.5-Eval/evaluation/latex2sympy/tests/atom_expr_test.py | |
| parent | 16815c8c5ec263c4bd1a0af60030c1c0efa1421e (diff) | |
init eval
Diffstat (limited to 'Qwen2.5-Eval/evaluation/latex2sympy/tests/atom_expr_test.py')
| -rwxr-xr-x | Qwen2.5-Eval/evaluation/latex2sympy/tests/atom_expr_test.py | 58 |
1 files changed, 58 insertions, 0 deletions
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))) |
