Files
dotfiles/tools/free-model-calibration/spec_test-code.py
T
ziadarafat bf0170070e tools: version the free-model calibration graders
Both graders, with the reference-implementation note: the first two scoreboards
were grader bugs (a fixture mounting a path that does not exist, and a boundary
case reusing the previous case's fixture), not model failures.
2026-11-28 23:18:01 -07:00

25 lines
803 B
Python

"""Grader for the roman-numeral calibration task. Not to be modified by workers."""
import pytest
from roman import to_roman, from_roman
PAIRS = [(1, "I"), (4, "IV"), (9, "IX"), (14, "XIV"), (40, "XL"), (90, "XC"),
(400, "CD"), (900, "CM"), (1994, "MCMXCIV"), (2024, "MMXXIV"), (3999, "MMMCMXCIX")]
@pytest.mark.parametrize("n,s", PAIRS)
def test_to_roman(n, s):
assert to_roman(n) == s
@pytest.mark.parametrize("n,s", PAIRS)
def test_roundtrip(n, s):
assert from_roman(s) == n
@pytest.mark.parametrize("bad", [0, -1, 4000])
def test_to_roman_out_of_range(bad):
with pytest.raises(ValueError):
to_roman(bad)
@pytest.mark.parametrize("bad", ["", "IIII", "VV", "ABC", "MMMM"])
def test_from_roman_invalid(bad):
with pytest.raises(ValueError):
from_roman(bad)