def testAdd(self): self.assertEqual(11, add(5, 6))
def test_add(self): result = calculations.add(10, 5) self.assertEqual(result, 15)
## IF WE WANT WE CAN ALSO JUST IMPORT THE SPECIFIC FUNCTIONS FROM A FILE ## FOR EXAMPLE from calculations import add print(add(4, 5)) ##EXPECTED OUTPUT 9
def test_add_string(): assert calculations.add('Hello', ' world!') == 'Hello world!' assert type(calculations.add('Hello', ' world!')) is str
def test_add(): assert calculations.add(3, 3) == 6 assert calculations.add(7) == 10 assert calculations.add(9, 9) == 18
import calculations as cal # WE IMPORT THE CALCLATIONS.PY FILE # CAL is the variable name we assigned to the file object #======================================================================================================================================= ## TO USE VARIABLES AND FUNCTIONS OF THE FILE WE FIRST HAVE TO WRITE THE VARIABLE NAME STORING THE FILE OBJECT ## FOLLOWED BY '.' AND THE FUNCTIONS OR THE VARIABLE WHICH WE WANT TO USE #======================================================================================================================================= num = 20 print(f'The value of num is {num}') #this should print 20 print(f'The value of cal.num is {cal.num}') #this should print 10 print(cal.add(4,5)) # WE CALL ADD METHOD OF THE FILE OBJECT print(cal.mul(4,5)) # WE CALL MUL METHOD OF THE FILE OBJECT print(cal.sub(4,5)) # WE CALL SUB METHOD OF THE FILE OBJECT
import calculations as calc print(calc.add(10,30)) print(calc.multiply(10,30))
def test_add2(): assert calculations.add('Hello', 'Du')=='HelloDu'; assert calculations.add(10,10)==200;
def test_add1(): assert calculations.add(1,2)==3; assert calculations.add(3,4)==7;
import calculations a = int(input('enter first number = ')) b = int(input('enter second number = ')) c = calculations.add(a,b) print(c)