-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added symbol replacement for latext formula
- Loading branch information
Showing
4 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import pytest | ||
|
||
from blueprints.codes.latex_formula import latex_replace_symbols | ||
|
||
|
||
# Success tests using pytest | ||
@pytest.mark.parametrize("latex_template, replacements, unique_check, expected", [ | ||
(r"\frac{A}{B}", {'A': 'x', 'B': 'y'}, True, r"\frac{x}{y}"), | ||
(r"\frac{A}{B}", {'A': 'x', 'B': 'y'}, False, r"\frac{x}{y}"), | ||
(r"\frac{A}{B}", {'A': 'x', 'B': 'y'}, False, r"\frac{x}{y}"), | ||
(r"\frac{A}{B}", {'A': 'x', 'B': 'y'}, False, r"\frac{x}{y}"), | ||
( | ||
r"\frac{k_{mod}}{\gamma_{R}}", | ||
{'k_{mod}': '0.9', r'\gamma_{R}': '1.2'}, | ||
False, | ||
r"\frac{0.9}{1.2}", | ||
), | ||
]) | ||
def test_latex_replace_symbols_success(latex_template, replacements, unique_check, expected): | ||
"""Test successful symbol replacements in LaTeX strings.""" | ||
result = latex_replace_symbols(latex_template, replacements, unique_check) | ||
assert result == expected | ||
|
||
# Error tests using pytest | ||
@pytest.mark.parametrize("latex_template, replacements, unique_check, expected_exception", [ | ||
(r"\frac{A}{B}", {'C': 'x'}, True, "Symbol 'C' not found in the template."), | ||
(r"\frac{A}{A}", {'A': 'x'}, True, "Symbol 'A' found multiple times in the template."), | ||
]) | ||
def test_latex_replace_symbols_error( | ||
latex_template, | ||
replacements, | ||
unique_check, | ||
expected_exception | ||
): | ||
"""Test error conditions when replacing symbols in LaTeX strings.""" | ||
with pytest.raises(ValueError, match=expected_exception): | ||
latex_replace_symbols(latex_template, replacements, unique_check) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters