Beispiel #1
0
def profile(lists):
    for alist in lists:
        length = len(alist)
        start = time.time()
        something = sorting.bsort(alist)
        finish = time.time()
        btime = finish - start
        start = time.time()
        something = sorting.ssort(alist)
        finish = time.time()
        stime = finish - start
        start = time.time()
        something = sorting.msort(alist)
        finish = time.time()
        mtime = finish - start
        print("""The time taken to sort a list of length {0} is 
        {1} using the bubble sort algorithm, 
        {2} using the Selection sort algorithm, 
        and {3} using the merge sort algorithm""".format(length, btime, stime, mtime))
Beispiel #2
0
list200 = makelist(200)
list400 = makelist(400)
list800 = makelist(800)
list1600 = makelist(1600)
lists = [list100, list200, list400, list800, list1600]

for alist in lists:
    length = len(alist)
    
    start = time.time()
    anything = sorting.bsort(alist)
    finish = time.time()
    btime = finish - start
    
    start = time.time()
    anything = sorting.ssort(alist)
    finish = time.time()
    stime = finish - start
    
    start = time.time()
    anything = sorting.msort(alist)
    finish = time.time()
    mtime = finish - start
    
    print ('''The list of length {0} took:
    {1} seconds to sort using a bubble sort,
    {2} seconds to sort usihng a Selection sort,
    and {3} seconds to sort using a Merge Sort
    
    '''.format(length, btime, stime, mtime))
Beispiel #3
0
 def test3(self):
     '''Test 2 checks that the bubble sort can sort a list of 4 items reversed.
     '''
     inlist = [4,3,2,1]
     outlist = [1,2,3,4]
     assert (sorting.ssort(inlist)==outlist) #test 3 fails - list not sorted by Selection sort
Beispiel #4
0
 def test3(self):
     '''given a list, sort items into sorted and unsorted elements using current minimum'''
     inlist = [4,8,23,15,94,178]
     assert (sorting.ssort(inlist)==outlist) #test 3 fails - list not sorted by selection sort