mirror of
https://bitbucket.org/Mattrixwv/pyclasses.git
synced 2025-12-06 18:33:58 -05:00
Added test for gcd
This commit is contained in:
@@ -205,6 +205,38 @@ def testGetPermutations():
|
|||||||
if(not failed):
|
if(not failed):
|
||||||
print("getPermutations passed all tests")
|
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
|
#This runs all of the tests and times them if this script is implicitly called
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
timer = Stopwatch()
|
timer = Stopwatch()
|
||||||
@@ -255,30 +287,39 @@ if __name__ == "__main__":
|
|||||||
timer.start()
|
timer.start()
|
||||||
testGetPermutations()
|
testGetPermutations()
|
||||||
timer.stop()
|
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:
|
"""Results:
|
||||||
getPrimes passed all tests
|
getPrimes failed the first test
|
||||||
testGetPrimes took 429.000 microseconds to run
|
testGetPrimes took 186.800 microseconds to run
|
||||||
|
|
||||||
getNumPrimes passed all tests
|
getNumPrimes failed the first test
|
||||||
testGetNumPrimes took 324.100 microseconds to run
|
testGetNumPrimes took 60.500 microseconds to run
|
||||||
|
|
||||||
getFactors passed all tests
|
getFactors passed all tests
|
||||||
testGetFactors took 202.700 microseconds to run
|
testGetFactors took 58.300 microseconds to run
|
||||||
|
|
||||||
getDivisors passed all tests
|
getDivisors passed all tests
|
||||||
testGetDivisors took 205.900 microseconds to run
|
testGetDivisors took 55.400 microseconds to run
|
||||||
|
|
||||||
getFib passed all tests
|
getFib passed all tests
|
||||||
testGetFib took 1.738 milliseconds to run
|
testGetFib took 759.200 microseconds to run
|
||||||
|
|
||||||
getAllFib passed all tests
|
getAllFib passed all tests
|
||||||
testGetAllFib took 215.100 microseconds to run
|
testGetAllFib took 96.700 microseconds to run
|
||||||
|
|
||||||
prod passed all tests
|
prod passed all tests
|
||||||
testProd took 207.000 microseconds to run
|
testProd took 78.900 microseconds to run
|
||||||
|
|
||||||
getPermutations passed all tests
|
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
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user