mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 00:39:47 +08:00
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.
35 lines
1.1 KiB
Python
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
|