Warning: untested

5 views
Skip to first unread message

Søren Kyale

unread,
May 3, 2013, 1:25:42 AM5/3/13
to uic-mcs...@googlegroups.com
I'm working on project five. I have yet to write my sort algorithms. First, I thought I should have a way to see if they do what they should. This is that test.

# isSorted: list -> boolean
def isSorted(aList):
   for i in xrange(len(aList)-1):
      if aList[i] > aList[i+1]: return False
   return True

this code seems to work for checking if a list is sorted. Please let me know if it fails.

enjoy!

Søren Kyale

unread,
May 3, 2013, 2:43:07 AM5/3/13
to uic-mcs...@googlegroups.com
So far my testing function functions well

# test:none -> none:
# here be tests:
def test():
   isPassing = True
   import numpy, time
   sortMe = list(numpy.random.randint(numpy.random.randint(1000), size=numpy.random.randint(1000)))
   jackHarkness = time.time()
   bubble(sortMe)
   print "bubble time: ", len(sortMe), time.time() - jackHarkness
   jackHarkness, passed = time.time(), isSorted(sortMe)
   print len(sortMe), time.time() - jackHarkness
   isPassing *= passed
   if not passed: print "bubble failed"
   sortMe = list(numpy.random.randint(numpy.random.randint(1000), size=numpy.random.randint(1000)))
   jackHarkness = time.time()
   bubblem(sortMe)
   print "bubblem time: ", len(sortMe), time.time() - jackHarkness
   jackHarkness, passed = time.time(), isSorted(sortMe)
   print len(sortMe), time.time() - jackHarkness
   isPassing *= passed
   if not passed: print "bubblem failed"
   if isPassing:
      print "All tests have passed"

if __name__ == "__main__": test()
Reply all
Reply to author
Forward
0 new messages