示例#1
0
    def test_inputs_out_of_scope_raise_exceptions(self):
        for bad_input in (2, None, 'Z', 'L', 'C', 'D', 'M'):
            with self.assertRaises(ValueError) as m:
                add('I', bad_input)
                if not hasattr(m, 'exception'):
                    self.fail('%s as augend did not raise exception' % bad_input)

            with self.assertRaises(ValueError) as m:
                add(bad_input, 'I')
                if not hasattr(m, 'exception'):
                    self.fail('%s as addend did not raise exception' % bad_input)
示例#2
0
 def test_IX_and_X(self):
     self.assertEqual(add('V', 'V'), 'X')
     self.assertEqual(add('V', 'IV'), 'IX')
     self.assertEqual(add('VIII', 'I'), 'IX')
     self.assertEqual(add('IX', 'I'), 'X')
     self.assertEqual(add('X', 'I'), 'XI')
     self.assertEqual(add('I', 'X'), 'XI')
     self.assertEqual(add('X', 'V'), 'XV')
     self.assertEqual(add('V', 'X'), 'XV')
     self.assertEqual(add('X', 'X'), 'XX')
示例#3
0
from rome import add

assert add('I', 'I') == 'II'


"""
with no file named rome.py, at all:

user0@ii:~/Desktop/git/TDD/TDD-Python/01 TDD Roman Numeral Chapter 1/01$ python test.py
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from rome import add
ImportError: No module named rome
"""
示例#4
0
 def test_adding_Is(self):
     self.assertEqual(add('I', 'I'), 'II')
     self.assertEqual(add('I', 'II'), 'III')
示例#5
0
 def test_IV_and_V(self):
     self.assertEqual(add('II', 'II'), 'IV')
     self.assertEqual(add('III', 'II'), 'V')
     self.assertEqual(add('IV', 'I'), 'V')
     self.assertEqual(add('V', 'I'), 'VI')
     self.assertEqual(add('I', 'V'), 'VI')
示例#6
0
 def test_add_Is(self):
     result = add('I', 'I')
     # assert result == 'II', 'add did not return II, it returned %s' % result
     self.assertEqual(add('I', 'I'), 'II',
                      'assert fail, it returned %s' % result)