def test_basics():
    numbers = [(1, 'I'), (3, 'III'), (4, 'IV'), (27, 'XXVII'), (44, 'XLIV'),
               (93, 'XCIII'), (141, 'CXLI'), (402, 'CDII'), (575, 'DLXXV'),
               (1024, 'MXXIV'), (3000, 'MMM')]

    for num in numbers:
        assert (num[0] == convert(num[1]))

    for num in numbers:
        assert (num[1] == convert(num[0]))
def test_it_work_with_other_numbers():
    assert convert(
        1776
    ) == 'MDCCLXXVI'  # Date written on the book held by the Statue of Liberty
    assert convert(
        1954
    ) == 'MCMLIV'  # As in the trailer for the movie The Last Time I Saw Paris
    assert convert(
        1990
    ) == 'MCMXC'  # Used as the title of musical project Enigma's debut album MCMXC a.D., named after the year of its release.
    assert convert(
        2014
    ) == 'MMXIV'  # The year of the games of the XXII (22nd) Olympic Winter Games (in Sochi)
    assert convert(2017) == 'MMXVII'
    assert convert(2018) == 'MMXVIII'
    assert convert(717) == 'DCCXVII'
    assert convert(777) == 'DCCLXXVII'
    assert convert(888) == 'DCCCLXXXVIII'
    assert convert(36) == 'XXXVI'
def test_it_fails_when_input_type_is_not_an_int_number():
    with pytest.raises(ValueError):
        convert({})

    with pytest.raises(ValueError):
        convert(1.0)

    with pytest.raises(ValueError):
        convert('random string')
def test_it_works_and_converts_basic_roman_numerals():
    """Given table of basic literals, test if converting works correctly
    | Symbol |  I  |  V  |  X   |   L   |   C   |   D   |   M   |
    |--------|-----|-----|------|-------|-------|-------|-------|
    | Value  |  1  |  5  |  10  |   50  |  100  |  500  | 1000  |
    """
    assert convert(1) == 'I'
    assert convert(5) == 'V'
    assert convert(10) == 'X'
    assert convert(50) == 'L'
    assert convert(100) == 'C'
    assert convert(500) == 'D'
    assert convert(1000) == 'M'
def test_it_fails_on_zero_or_negative_number():
    with pytest.raises(ValueError):
        convert(0)

    with pytest.raises(ValueError):
        convert(-1)
Example #6
0
def test_outside_range(unsupported_value):
    with pytest.raises(NotImplementedError):
        roman_numerals.convert(unsupported_value)
Example #7
0
def test_score(value, numerals):
    assert roman_numerals.convert(value) == numerals
Example #8
0
chars = '0123456789 '
dtable = CharacterTable(chars)

seq_samples = []
seq_labels = []
used = []
repetitions = 0
generated = 0
print('Generating data...')
while len(seq_samples) < DATASET_SIZE:
    number = random.randint(1, 2000)
    # skip if already in the dataset
    if number in used: continue
    used.append(number)
    # roman input
    roman = cnv.convert(number)
    roman += ' ' * (INPUT - len(roman))

    # arabic output
    arabic = str(number)
    arabic += ' ' * (OUTPUT - len(arabic))

    seq_samples.append(roman)
    seq_labels.append(arabic)
print('Total roman numbers:', len(seq_samples))

# one-hot encoding of all romans and arabic numbers
print('Vectorization...')
x = np.zeros((DATASET_SIZE, INPUT, len(romans)), dtype=np.bool)
y = np.zeros((DATASET_SIZE, OUTPUT, len(chars)), dtype=np.bool)
for i, sentence in enumerate(seq_samples):