summaryrefslogtreecommitdiff
path: root/tests/test_surface.py
blob: 78c4d5eab71adedb1c4a82790fd45d377f845073 (plain)
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
from __future__ import annotations

import pytest

from gap_pipeline.surface import (
    apply_rename_map,
    create_surface_variant,
    validate_rename_map,
)


def test_math_only_rename_preserves_english_article(item) -> None:
    text = r"Let \(a\) be a randomly chosen value with \(a>0\)."
    renamed = apply_rename_map(text, {"a": "coefalpha"})
    assert renamed == (
        r"Let \(coefalpha\) be a randomly chosen value with \(coefalpha>0\)."
    )


def test_surface_variant_changes_problem_and_solution(item) -> None:
    variant = create_surface_variant(
        item,
        "descriptive_long",
        {"a": "positiveScalar"},
    )
    assert "positiveScalar" in variant.problem
    assert "positiveScalar" in variant.solution
    assert "Let positiveScalar" not in variant.problem


def test_collision_and_nonbijection_are_rejected(item) -> None:
    with pytest.raises(ValueError, match="collides"):
        validate_rename_map(
            {"a": "a"},
            existing_identifiers=["a"],
            scientific_constants=[],
        )
    with pytest.raises(ValueError, match="one-to-one"):
        validate_rename_map(
            {"a": "sharedName", "b": "sharedName"},
            existing_identifiers=["a", "b"],
            scientific_constants=[],
        )