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.
25 lines
803 B
Python
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)
|