mirror of
https://bitbucket.org/Mattrixwv/pyclasses.git
synced 2025-12-06 18:33:58 -05:00
Added a function that gets all permutations of a
string
This commit is contained in:
@@ -189,6 +189,22 @@ def testProd():
|
||||
if(not failed):
|
||||
print("prod passed all tests")
|
||||
|
||||
#This function tests the getPermutations function
|
||||
def testGetPermutations():
|
||||
failed = False #Holds whether a test was failed
|
||||
|
||||
#Test 1
|
||||
permString = "012"
|
||||
correctAnswer = ["012", "021", "102", "120", "201", "210"]
|
||||
answer = Algorithms.getPermutations(permString)
|
||||
if(answer != correctAnswer):
|
||||
print("getPermutations failed the first test")
|
||||
failed = True
|
||||
|
||||
#If the false was not triggered it must have passed all tests
|
||||
if(not failed):
|
||||
print("getPermutations passed all tests")
|
||||
|
||||
#This runs all of the tests and times them if this script is implicitly called
|
||||
if __name__ == "__main__":
|
||||
timer = Stopwatch()
|
||||
@@ -233,27 +249,36 @@ if __name__ == "__main__":
|
||||
timer.start()
|
||||
testProd()
|
||||
timer.stop()
|
||||
print("testProd took " + timer.getString() + " to run")
|
||||
print("testProd took " + timer.getString() + " to run\n")
|
||||
|
||||
#Test getPermutations
|
||||
timer.start()
|
||||
testGetPermutations()
|
||||
timer.stop()
|
||||
print("testGetPermutations took " + timer.getString() + " to run")
|
||||
|
||||
"""Results:
|
||||
getPrimes passed all tests
|
||||
testGetPrimes took 130.448 microseconds to run
|
||||
testGetPrimes took 429.000 microseconds to run
|
||||
|
||||
getNumPrimes passed all tests
|
||||
testGetNumPrimes took 112.202 microseconds to run
|
||||
testGetNumPrimes took 324.100 microseconds to run
|
||||
|
||||
getFactors passed all tests
|
||||
testGetFactors took 41.105 microseconds to run
|
||||
testGetFactors took 202.700 microseconds to run
|
||||
|
||||
getDivisors passed all tests
|
||||
testGetDivisors took 15.416 microseconds to run
|
||||
testGetDivisors took 205.900 microseconds to run
|
||||
|
||||
getFib passed all tests
|
||||
testGetFib took 3.185 milliseconds to run
|
||||
testGetFib took 1.738 milliseconds to run
|
||||
|
||||
getAllFib passed all tests
|
||||
testGetAllFib took 25.959 microseconds to run
|
||||
testGetAllFib took 215.100 microseconds to run
|
||||
|
||||
prod passed all tests
|
||||
testProd took 9.553 microseconds to run
|
||||
testProd took 207.000 microseconds to run
|
||||
|
||||
getPermutations passed all tests
|
||||
testGetPermutations took 212.800 microseconds to run
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user