Beispiel #1
0
 def test_round_trip(self):
     '''should return valid roman numeral from integer, and then back to integer'''
     # for number, numeral in self.known_values:
     for integer in range(1, 4000):
         roman = roman1.to_roman(integer)
         round_trip_number = roman1.from_roman(roman)
         self.assertEqual(integer, round_trip_number)
Beispiel #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:
        #call to_roman func; defines its argument as integer
        result = roman1.to_roman(integer)
        #check if conversion is correct; no output if correct
        self.assertEqual(numeral, result)
    def test_to_roman_known_values(self):
        """ to_roman should give known result with known input """

        for integer, numeral in self.known_values:
            result = roman1.to_roman(integer)

            # сравнивает 2 значения и выводит ошибки при несовпадении
            self.assertEqual(numeral, result)
    def test_from_roman_known_values(self):
        '''from_roman(to_roman(n)) == n for all n'''
        # self.assertEqual(roman1.from_roman('MMMMCMXCIX'), 4999)
        for integer in range(1, 5000):
            numeral = roman1.to_roman(integer)

            result = roman1.from_roman(numeral)
            self.assertEqual(integer, result)
Beispiel #5
0
 def test_to_roman_known_values(self):
     # 对于每一个测试用例, unittest 模块会打印出测试方法的 docstring ,并且说明该测试失败还是成功。
     # 失败时必然打印docstring, 成功时需使用“-v”命令行参数来查看。
     '''to_roman 方法传回的值与用例的数据不相等时,则测试不通过'''
     # 测试的用例,一般是所有明显的边界用例。
     known_values = ( (1, 'I'), (2, 'II'), (3, 'III'), (4, 'IV'),
         (5, 'V'), (6, 'VI'), (7, 'VII'), (8, 'VIII'),
         (9, 'IX'), (10, 'X'), (50, 'L'), (100, 'C'),
         (500, 'D'), (1000, 'M'), (31, 'XXXI'), (148, 'CXLVIII'),
         (3888, 'MMMDCCCLXXXVIII'), (3940, 'MMMCMXL'), (3999, 'MMMCMXCIX') )
     for integer, numeral in known_values:
         result = roman1.to_roman(integer) # 这里调用真实的方法。如果该方法抛出了异常,则测试被视为失败。
         self.assertEqual(numeral, result) # 检查两个值是否相等。如果两个值不一致,则抛出异常,并且测试失败。
         self.assertNotEqual(0, result, '这两个值不应该相等') # 检查两个值是否不相等。
         self.assertTrue(5 > 0, '5 > 0 都出错,不是吧')
         self.assertFalse(5 < 0)
     # 对于每一个失败的测试用例, unittest 模块会打印出详细的跟踪信息。
     # 如果所有返回值均与已知的期望值一致,则 self.assertEqual 不会抛出任何异常,于是此次测试最终会正常退出,这就意味着 to_roman() 通过此次测试。
     assert 5 > 0 # 为了更灵活的判断,可使用 assert
Beispiel #6
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 = roman1.to_roman(integer)
         self.assertEqual(result, numeral)
Beispiel #7
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 = roman1.to_roman(integer)
         self.assertEqual(numeral, result)
Beispiel #8
0
 def test_roundtrip(self):
     '''from_roman(to_roman(n)==n for all n'''
     for integer in range(1, 5000):
         numeral = roman1.to_roman(integer)
         result = roman1.from_roman(numeral)
         self.assertEqual(integer, result)
Beispiel #9
0
 def test_to_roman_known_values(self):
     for integer, numeral in self.known_values:
         result = roman1.to_roman(integer)
         self.assertEqual(numeral, result)
Beispiel #10
0
 def test_to_roman_known_values(self):
     '''to_roman should return valid numeral with a valid input'''
     for number, numeral in self.known_values:
         result = roman1.to_roman(number)
         self.assertEqual(numeral, result)
Beispiel #11
0
 def test_to_roman_known_values(self):           #3
     '''to_roman에 알려진 숫자를 넣으주면 그에 맞는 로마 숫자를 반환해야 합니다'''
     for integer, numeral in self.known_values:
         result = roman1.to_roman(integer)       #4
         self.assertEqual(numeral, result)       #5
Beispiel #12
0
 def test_round_trip(self):
     """from_roman(to_roman(n)) should equals to n"""
     for integer in range(1,5000):
         result = roman1.from_roman(roman1.to_roman(integer))
         self.assertEqual(result,integer)
Beispiel #13
0
 def test_roundtrip(self):
     ''' from_roman(to_roman(n)) == n for n = (1...3999) '''
     for num in range(1, 4000):
         numeral = roman1.to_roman(num)
         result = roman1.from_roman(numeral)
         self.assertEqual(result, num)
 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 = roman1.to_roman(integer)
         self.assertEqual(numeral, result)
Beispiel #15
0
 def test_Roundtrip(self):
     for integer in range(1, 4000):
         numeral = roman1.to_roman(integer)
         result = roman1.from_roman(numeral)
         self.assertEqual(integer, result)
 def test_to_roman_known_values(self):
     '''to_roman powinna dac znany rezultat dla znanych symboli wyjsciowych'''
     for integer, numeral in self.known_values:
         result = roman1.to_roman(integer)
         self.assertEqual(numeral, result)
Beispiel #17
0
 def test_to_roman_known_values(self):
     """to_roman should give known result with known input"""
     for integer, numeral in self.know_values:
         result = roman1.to_roman(integer)
         self.assertEqual(numeral, result)
Beispiel #18
0
 def test_roundtrip(self):
     for integer in range(1, 4000):
         numeral = roman1.to_roman(integer)
         result = roman1.from_roman(numeral)
         self.assertEqual(integer, result)
Beispiel #19
0
 def test_roundtrip(self):
     '''from_roman(to_roman(n))==n fpr all n'''
     for integer in range(1, 4000):
         numeral = roman1.to_roman(integer)
         result = roman1.from_roman(numeral)
         self.assertEqual(integer, result)
Beispiel #20
0
def test_to_roman_known_values(self):
    for integer, numeral in self.know_values:
        result = roman1.to_roman(integer)
        self.assertEqual(numeral, result)