| 1 |
import pytest |
| 2 |
|
| 3 |
from roman_numerals import ( |
| 4 |
InvalidRomanNumeralError, |
| 5 |
RomanNumeral, |
| 6 |
) |
| 7 |
|
| 8 |
from tests.utils import TEST_NUMERALS_LOWER, TEST_NUMERALS_UPPER |
| 9 |
|
| 10 |
|
| 11 |
@pytest.mark.parametrize(('n', 'roman_str'), enumerate(TEST_NUMERALS_UPPER, start=1)) |
| 12 |
def test_uppercase(n: int, roman_str: str) -> None: |
| 13 |
expected = RomanNumeral(n) |
| 14 |
parsed = RomanNumeral.from_string(roman_str) |
| 15 |
assert expected == parsed |
| 16 |
|
| 17 |
|
| 18 |
@pytest.mark.parametrize(('n', 'roman_str'), enumerate(TEST_NUMERALS_LOWER, start=1)) |
| 19 |
def test_lowercase(n: int, roman_str: str) -> None: |
| 20 |
expected = RomanNumeral(n) |
| 21 |
parsed = RomanNumeral.from_string(roman_str) |
| 22 |
assert expected == parsed |
| 23 |
|
| 24 |
|
| 25 |
def test_special() -> None: |
| 26 |
parsed = RomanNumeral.from_string('MDLXXXIII') |
| 27 |
assert RomanNumeral(1583) == parsed |
| 28 |
|
| 29 |
parsed = RomanNumeral.from_string('mdlxxxiii') |
| 30 |
assert RomanNumeral(1583) == parsed |
| 31 |
|
| 32 |
parsed = RomanNumeral.from_string('MCMLXXXIV') |
| 33 |
assert RomanNumeral(1984) == parsed |
| 34 |
|
| 35 |
parsed = RomanNumeral.from_string('mcmlxxxiv') |
| 36 |
assert RomanNumeral(1984) == parsed |
| 37 |
|
| 38 |
parsed = RomanNumeral.from_string('MM') |
| 39 |
assert RomanNumeral(2000) == parsed |
| 40 |
|
| 41 |
parsed = RomanNumeral.from_string('mm') |
| 42 |
assert RomanNumeral(2000) == parsed |
| 43 |
|
| 44 |
parsed = RomanNumeral.from_string('MMMCMXCIX') |
| 45 |
assert RomanNumeral(3_999) == parsed |
| 46 |
|
| 47 |
parsed = RomanNumeral.from_string('mmmcmxcix') |
| 48 |
assert RomanNumeral(3_999) == parsed |
| 49 |
|
| 50 |
|
| 51 |
def test_invalid() -> None: |
| 52 |
with pytest.raises(InvalidRomanNumeralError) as ctx: |
| 53 |
RomanNumeral.from_string('Not a Roman numeral!') |
| 54 |
msg = str(ctx.value) |
| 55 |
assert msg == 'Invalid Roman numeral: Not a Roman numeral!' |
| 56 |
|
| 57 |
|
| 58 |
def test_mixed_case() -> None: |
| 59 |
with pytest.raises(InvalidRomanNumeralError) as ctx: |
| 60 |
RomanNumeral.from_string('McMlXxXiV') |
| 61 |
msg = str(ctx.value) |
| 62 |
assert msg == 'Invalid Roman numeral: McMlXxXiV' |