1- import calc
21import unittest
2+ import calc
33
4- class TestAdd (unittest .TestCase ):
4+ class TestCalc (unittest .TestCase ):
55 """
66 Test the add function from the calc library
77 """
@@ -10,24 +10,39 @@ def test_add_integers(self):
1010 """
1111 Test that the addition of two integers returns the correct total
1212 """
13- result = calc .add (1 , 2 )
13+ result = calc .add2 (1 , 2 )
1414 self .assertEqual (result , 3 )
1515
1616 def test_add_floats (self ):
1717 """
1818 Test that the addition of two floats returns the correct result
1919 """
20- result = calc .add ( 10.5 , 2 )
20+ result = calc .add2 ( ' 10.5' , 2 )
2121 self .assertEqual (result , 12.5 )
2222
2323 def test_add_strings (self ):
2424 """
25- Test the addition of two strings returns the two string as one
25+ Test the addition of two strings returns the two strings as one
2626 concatenated string
2727 """
28- result = calc .add ('abc' , 'def' )
28+ result = calc .add2 ('abc' , 'def' )
2929 self .assertEqual (result , 'abcdef' )
3030
31+ def test_add_string_and_integer (self ):
32+ """
33+ Test the addition of a string and an integer returns them as one
34+ concatenated string (in which the integer is converted to a string)
35+ """
36+ result = calc .add2 ('abc' , 3 )
37+ self .assertEqual (result , 'abc3' )
38+
39+ def test_add_string_and_number (self ):
40+ """
41+ Test the addition of a string and a float returns them as one
42+ concatenated string (in which the float is converted to a string)
43+ """
44+ result = calc .add2 ('abc' , '5.5' )
45+ self .assertEqual (result , 'abc5.5' )
3146
3247if __name__ == '__main__' :
3348 unittest .main ()
0 commit comments