Files
DeepTutor/tests/services/test_speech_limit_order.py
Rudy Celekli 0a62b3b97c fix(voice): preserve TeX limit meaning in either script order
Read lower and upper bounds independently of their TeX order and consume the optional limits placement command before verbalizing them.

AI-assisted: implementation and regression tests prepared and validated with OpenAI Codex. Maintainer review is pending.
2026-10-30 23:18:20 -04:00

35 lines
1.1 KiB
Python

"""Equivalent TeX limit placements must have the same spoken meaning."""
import pytest
from deeptutor.services.voice.speech_text import verbalize_latex_for_speech
@pytest.mark.parametrize(
("command", "lower", "upper", "body", "expected"),
[
("sum", "i=1", "n", "i", "sum from i = 1 to n i"),
("prod", "j=0", "m", "a_j", "product from j = 0 to m a sub j"),
("int", "a", "b", "f(x) dx", "integral from a to b f(x) dx"),
("oint", "a", "b", "f(z) dz", "contour integral from a to b f(z) dz"),
],
)
@pytest.mark.parametrize(
"directive",
["", r"\limits", r"\nolimits", r"\displaylimits", r"\limits \nolimits \displaylimits"],
)
@pytest.mark.parametrize("upper_first", [False, True])
def test_speak_limits_independently_of_tex_placement(
command: str,
lower: str,
upper: str,
body: str,
expected: str,
directive: str,
upper_first: bool,
) -> None:
bounds = f"^{{{upper}}}_{{{lower}}}" if upper_first else f"_{{{lower}}}^{{{upper}}}"
text = f"$\\{command}{directive}{bounds} {body}$"
assert " ".join(verbalize_latex_for_speech(text).split()) == expected