File size: 1,934 Bytes
62831c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Regression cases for math_equiv.equivalent (run: python test_math_equiv.py, or pytest).

The false-positive cases came from the 2026-11-08 judge-vs-rule comparison on fade_ordered's Open samples: before the
fix the grader read "3i" and "$3-6$)." as 3 and "3" as the ratio "3:1"."""
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent))
import math_equiv  # noqa: E402

CASES = [
    # (gold, answer, expected)
    ("3", "3i", False), ("2", "2i", False), ("3", "3x", False),        # a single letter is i or a variable, not a unit
    ("3", "$3-6$).", False), ("3", "3-6", False),                      # a whole expression must equal the gold
    ("2", "2^", False), ("2", r"2 \times", False), ("4", "((2+2)", False),  # dangling operator, unbalanced bracket
    ("3:1", "3", False), ("3", "-3", False), ("3", "3, 4", False), ("5", "5 m", False),
    ("3", "3 dollars", True), ("12", "12 apples.", True), ("5", "5cm", True), ("10", "10%", True),
    ("3", "3)", True), ("4", "4]", True), ("4", "(4)", True), ("4", r"\left(4\right)", True),
    ("3", "x = 3", True), ("3", "3.", True), ("3", "$3$", True), ("3", r"\boxed{3}", True),
    ("3", r"\frac{6}{2}", True), ("3", "6/2", True), ("0.5", r"\frac12", True), ("6", r"2 \times 3", True),
    ("8", "2^3", True), ("8", "2^{3}", True), ("4", r"\sqrt{16}", True), ("3", "3 + 0", True),
    (r"\frac{1}{2}", "1/2", True), ("3:1", "3:1", True), ("(-1,0]", "(-1,0]", True),
    ("1011_2", "1011", True), (r"10^\circ", "10", True),
    ("7", "*  7", True), ("3", "** **3**", True), ("3", "**3**.", True), ("4", "$4,$", True), ("4", "4;", True),
    ("3", "3a", False), ("9", "$9a$", False), ("16", '[["$16^2$,", " $16$"]', False),
]


def test_cases():
    bad = [(g, a, want) for g, a, want in CASES if math_equiv.equivalent(g, a) != want]
    assert not bad, bad


if __name__ == "__main__":
    test_cases()
    print(len(CASES), "cases pass")