def write_to_roman(text, output_filename):
    '''convert the given text numbers into roman and write it into a file'''
    converted = []
    for word in text.split():
        try:
            number = int(word)
        except ValueError:
            converted.append(word)
        else:
            converted.append(to_roman(number))
    if os.path.isfile(output_filename):
        raise IOError("File '{}' already exist".format(output_filename))
    with open(output_filename, 'w') as output_file:
        output_file.write(" ".join(converted))
示例#2
0
 def test_to_roman_known_values(self):
     '''to_roman should give known result with known input'''
     for integer, numeral in self.known_values:
         result = roman7.to_roman(integer)
         self.assertEqual(numeral, result)
示例#3
0
 def test_roundtrip(self):
     '''from_roman(to_roman(n))==n for all n'''
     for integer in range(1, 4000):
         numeral = roman7.to_roman(integer)
         result = roman7.from_roman(numeral)
         self.assertEqual(integer, result)
示例#4
0
 def test_roundtrip(self) :
   '''from_roman(to_roman(n)) == n for all n'''
   for integer in range(1, 4000) :
     numeral = roman7.to_roman(integer)
     result = roman7.from_roman(numeral)
     self.assertEqual(integer, result)
示例#5
0
 def test_to_roman_known_values(self) :
   '''to_roman should give known result with known input'''
   for integer, numeral in self.known_values :
     result = roman7.to_roman(integer)
     self.assertEqual(numeral, result)
示例#6
0
 def test_to_roman_known_values(self):
     '''to_roman dovrebbe dare un risultato noto con un ingresso noto'''
     for integer, numeral in self.known_values:
         result = roman7.to_roman(integer)
         self.assertEqual(numeral, result)
def test_roman_conversion():
    assert to_roman(3) == 'III'
    assert from_roman('IV') == 4