Spaces:
Sleeping
Sleeping
File size: 3,132 Bytes
910e364 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | #!/usr/bin/env python3
"""
Test script to verify specific content from user's example
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from app import convert_math_to_html
def test_user_content():
"""Test the specific content patterns from the user's example"""
print("🧪 Testing specific content patterns from user's example...")
# Test cases based on the user's actual content
test_cases = [
# From the user's content
r"\text{Speed} = \frac{\text{Distance}}{\text{Time}}",
r"m = d × v",
r"d = density (5 g/cm³)",
r"v = volume (10 cm³)",
r"m = \_\_\_ × \_\_\_ = \_\_\_ \text{ g}",
r"2H2 + O2 → \_\H2O",
r"2H2 + O2 → \boxed{\_\_}H2O",
r"W = F × d",
r"F = force (50 N)",
r"d = distance (10 m)",
r"W = \_\_\_ × \_\_\_ = \_\_\_ \text{ J}",
r"m = 5 × 10 = 50 \text{ g}",
r"2H2 + O2 → 2H2O",
r"\text{Speed} = \frac{120}{2} = 60 \text{ km/h}",
r"W = 50 × 10 = 500 \text{ J}"
]
for i, test_case in enumerate(test_cases, 1):
print(f"\n{i}. Input: {test_case}")
result = convert_math_to_html(test_case)
print(f" Output: {result}")
print(f" Length: {len(result)} chars")
# Check if LaTeX commands were converted
if '\\text{' in result:
print(" ⚠️ Still contains \\text{} commands")
if '\\frac{' in result:
print(" ⚠️ Still contains \\frac{} commands")
if '\\_' in result:
print(" ⚠️ Still contains \\_ commands")
def test_complex_content():
"""Test a complex example that matches the user's content"""
print("\n🎯 Testing complex content example...")
complex_content = """
A scientist measures the mass (m) of a substance using the formula:
m = d × v
where: - d = density (5 g/cm³) - v = volume (10 cm³)
**Find the mass (m).** **Solution:**
m = \_\_\_ × \_\_\_ = \_\_\_ \\text{ g}
Balance the chemical equation using algebra:
2H2 + O2 → \\_\\H2O
**Fill in the blank:**
2H2 + O2 → \\boxed{\\_\\_}H2O
A car travels **120 km** in **2 hours**. Use the formula:
\\text{Speed} = \\frac{\\text{Distance}}{\\text{Time}}
**Calculate the speed.**
\\text{Speed} =
\\_\\_\\_
\\_\\_\\_
= \\_\\_\\_ \\text{ km/h}
The work done (W) is calculated by:
W = F × d
where: - F = force (50 N) - d = distance (10 m)
**Find the work done.**
W = \\_\\_\\_ × \\_\\_\\_ = \\_\\_\\_ \\text{ J}
"""
print("Original content:")
print(complex_content)
print("\nConverted content:")
converted = convert_math_to_html(complex_content)
print(converted)
# Save to file
with open("test_complex_output.html", "w", encoding="utf-8") as f:
f.write(converted)
print("\n💾 Complex content saved to test_complex_output.html")
if __name__ == "__main__":
test_user_content()
test_complex_content()
print("\n✅ Testing completed!")
|