58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
"""Test script for converter functionality."""
|
|
|
|
from app.services.converter import Converter
|
|
|
|
|
|
def test_latex_only_conversion():
|
|
"""Test conversion of LaTeX-only content."""
|
|
converter = Converter()
|
|
|
|
# Test case 1: Display math with $$...$$
|
|
latex_input = "$$E = mc^2$$"
|
|
result = converter.convert_to_formats(latex_input)
|
|
|
|
print("Test 1: Display math ($$...$$)")
|
|
print(f"Input: {latex_input}")
|
|
print(f"LaTeX: {result.latex}")
|
|
print(f"MathML: {result.mathml[:100]}...")
|
|
print(f"MML: {result.mml[:100]}...")
|
|
print(f"OMML: {result.omml[:100] if result.omml else 'Empty'}...")
|
|
print()
|
|
|
|
# Test case 2: Inline math with $...$
|
|
latex_input2 = "$\\frac{a}{b}$"
|
|
result2 = converter.convert_to_formats(latex_input2)
|
|
|
|
print("Test 2: Inline math ($...$)")
|
|
print(f"Input: {latex_input2}")
|
|
print(f"LaTeX: {result2.latex}")
|
|
print(f"MathML: {result2.mathml[:100]}...")
|
|
print()
|
|
|
|
# Test case 3: Complex formula
|
|
latex_input3 = "$$\\int_{0}^{\\infty} e^{-x^2} dx = \\frac{\\sqrt{\\pi}}{2}$$"
|
|
result3 = converter.convert_to_formats(latex_input3)
|
|
|
|
print("Test 3: Complex formula")
|
|
print(f"Input: {latex_input3}")
|
|
print(f"LaTeX: {result3.latex}")
|
|
print(f"MathML: {result3.mathml[:150]}...")
|
|
print(f"OMML length: {len(result3.omml)}")
|
|
print()
|
|
|
|
# Test case 4: Regular markdown (not LaTeX-only)
|
|
markdown_input = "# Hello\n\nThis is a test with math: $x = 2$"
|
|
result4 = converter.convert_to_formats(markdown_input)
|
|
|
|
print("Test 4: Regular markdown")
|
|
print(f"Input: {markdown_input}")
|
|
print(f"LaTeX: {result4.latex[:100]}...")
|
|
print(f"MathML: {result4.mathml[:100]}...")
|
|
print(f"MML: {result4.mml}")
|
|
print(f"OMML: {result4.omml}")
|
|
print()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_latex_only_conversion()
|