Ejemplo n.º 1
0
 def test_two_negative_number(self):
     expected = -7
     actual = example1.add(-3, -4)
     self.assertEqual(
         expected, actual,
         'when you subract two egative numbers, the result should be negative'
     )
Ejemplo n.º 2
0
 def test_two_positive_number(self):
     expected = 7
     actual = example1.add(3, 4)
     self.assertEqual(actual, expected)
Ejemplo n.º 3
0
 def test_one_negative_one_positive_number(self):
     expected = 1
     actual = example1.add(-3, 4)
     self.assertEqual(actual, expected)
Ejemplo n.º 4
0
 def test_add(self):  #test_whatyouaretesting. This is important
     #result = ex.add(10,5)
     self.assertEqual(ex.add(10, 5), 15)
     self.assertEqual(ex.add(10, -15), -5)
Ejemplo n.º 5
0
     >>> example1.add([1],[2])
     [1, 2]
     >>> example1.add([1],2)
     Traceback (most recent call last):
     TypeError: can only concatenate list (not "int") to list
     """
     return a+b

if __name__ == "__main__":
    print '**running standard doctest'
    import doctest,example1
    doctest.testmod(example1)


#To put additional doctests somewhere else and make them a unittest
#testcase, put your tests in a different file like test1.txt. Note ---
#no quoting needed

 >>> import example1
 >>> example1.add('a','b')
'ab'

#then add a few likes of code to the end of example1.py to run the unittest
if __name__ == "__main__":
    print '**running standard doctest'
    import doctest,example1
    doctest.testmod(example1)
    print '**running unittest doctest'
    suite = doctest.DocFileSuite('test1.txt')
    unittest.TextTestRunner().run(suite)