Added test for gcd

This commit is contained in:
2021-03-11 15:58:32 -05:00
parent 7b5632b441
commit f9828d0967

View File

@@ -205,6 +205,38 @@ def testGetPermutations():
if(not failed):
print("getPermutations passed all tests")
#This function tests the gcd function
def testGCD():
failed = False #Holds whether a test was failed
#Test 1
num1 = 2
num2 = 3
correctAnswer = 1
answer = Algorithms.gcd(num1, num2)
if(answer != correctAnswer):
print("getGCD failed the first test")
failed = True
#Test 2
num1 = 1000
num2 = 575
correctAnswer = 25
answer = Algorithms.gcd(num1, num2)
if(answer != correctAnswer):
print("getGCD failed the second test")
failed = True
#Test 3
num1 = 1000
num2 = 1000
correctAnswer = 1000
answer = Algorithms.gcd(num1, num2)
if(answer != correctAnswer):
print("getGCD failed the third test")
failed = True
if(not failed):
print("getGCD passed all tests")
#This runs all of the tests and times them if this script is implicitly called
if __name__ == "__main__":
timer = Stopwatch()
@@ -255,30 +287,39 @@ if __name__ == "__main__":
timer.start()
testGetPermutations()
timer.stop()
print("testGetPermutations took " + timer.getString() + " to run")
print("testGetPermutations took " + timer.getString() + " to run\n")
#Test gcd
timer.start()
testGCD()
timer.stop()
print("testGCD took " + timer.getString() + " to run")
"""Results:
getPrimes passed all tests
testGetPrimes took 429.000 microseconds to run
getPrimes failed the first test
testGetPrimes took 186.800 microseconds to run
getNumPrimes passed all tests
testGetNumPrimes took 324.100 microseconds to run
getNumPrimes failed the first test
testGetNumPrimes took 60.500 microseconds to run
getFactors passed all tests
testGetFactors took 202.700 microseconds to run
testGetFactors took 58.300 microseconds to run
getDivisors passed all tests
testGetDivisors took 205.900 microseconds to run
testGetDivisors took 55.400 microseconds to run
getFib passed all tests
testGetFib took 1.738 milliseconds to run
testGetFib took 759.200 microseconds to run
getAllFib passed all tests
testGetAllFib took 215.100 microseconds to run
testGetAllFib took 96.700 microseconds to run
prod passed all tests
testProd took 207.000 microseconds to run
testProd took 78.900 microseconds to run
getPermutations passed all tests
testGetPermutations took 212.800 microseconds to run
testGetPermutations took 102.700 microseconds to run
getGCD passed all tests
testGCD took 76.500 microseconds to run
"""