def test_subtract_days(self): """ Test that the subtraction of two datetime objects returns the correct result """ result = mymath.subtract(datetime.date.today(), datetime.timedelta(days=90)) self.assertEqual(result, datetime.date.today() - datetime.timedelta(days=90))
#!/usr/bin/python import sys sys.path.append('/home/za/dev/github/py101') import mymath print mymath.add(10,5) print mymath.multiply(10,5) print mymath.subtract(10,5) print mymath.division(10,5)
def test_subtract_integers(self): """ Test that subtracting integers returns the correct result """ result = mymath.subtract(10, 8) self.assertEqual(result, 2)
def addsub(a, b): return mymath.subtract(mymath.add(a, b), b) == a
import mymath def addsub(a, b): return mymath.subtract(mymath.add(a, b), b) == a def comparepower(a, b): return mymath.power(a, b) == mymath.intPower(a, b) def incdec(a): return increment(decrement(a)) == a assert mymath.add(3, 4) == 7 assert mymath.subtract(3, 4) == -1 assert mymath.power(4, 3) == 48 assert mymath.intPower(5, 3) == 125 assert mymath.increment(5) == 6 assert mymath.decrement(5) == 4 assert addsub(4, 2) == True assert addsub(4324, 25345) == True assert comparePower(3, 2) == True assert comparePower(123, 5) == True assert incdec(4) == True assert incdec(234) == True
# -------------------- ''' When we import a module the file we imported its name is called namespace. See the example below ''' # -------------------- # Import # -------------------- ## Import entire module import mymath # mymath is a filename and namespace print ( mymath.sum(10, 2) ) # using mymath namespace we can call its function print ( mymath.subtract(10, 2) ) ## Import specific functions from mymath import subtract print ( subtract(2, 1) ) ## Import all functions from mymath import * print ( sum(2, 5) ) print ( subtract(29, 1) ) ## Import class from modules
import mymath #Enter two numbers x = int(input("Enter 1st number: ")) y = int(input("Enter 2nd number: ")) print() # Call the add function resAdd = mymath.add(x, y) print("Sum =", resAdd) #Call the subtract function resSub = mymath.subtract(x, y) print("Difference =", resSub) #Call the multiply function resMul = mymath.multiply(x, y) print("Product =", resMul) #Call the divide function resDiv = mymath.divide(x, y) print("Division =", resDiv) print() #Call the isPrime function resPri = mymath.isPrime(x) if resPri == True: print(x, "is Prime") else: print(x, "is not Prime")
import mymath print(mymath.sum(10, 2)) print(mymath.subtract(10, 2))
def test_subtract_integers(self): result = mymath.subtract(10, 8) self.assertEqual(result, 2)
def test_subtract(): assert mymath.subtract(3, 2) == 1
import mymath if __name__ == "__main__": assert mymath.add(1, 2) == 3 assert mymath.subtract(2, 1) == 1 assert mymath.multiply(2, 3) == 6 assert mymath.divide(4, 2) == 2
def test_subtract_integers(): """ Test that the addition of two integers returns the correct total """ result = mymath.subtract(1, 2) assert result == -1
def test_subtract_floats(): """ Test that the addition of two floats returns the correct result """ result = mymath.subtract(10.5, 2) assert result == 8.5