Ejemplo n.º 1
0
	def test_msort(self):
		for i in range(1,100):
			sa = self.assertEqual
			l = self.random_list(random.randint(10,100))
			sl = sorted(l)
			sorting.msort(l, 0, len(l)-1)
			sa(sl, l)
Ejemplo n.º 2
0
def test_msort():
    assert msort([]) == []
    assert msort([1]) == [1]
    assert msort([2,3,1]) == [1,2,3]
    assert (msort([9, 2, 5, 6, 7, 1, 8, 4, 3]) == 
             [1, 2, 3, 4, 5, 6, 7, 8, 9])
    assert msort(['c','b','a','d']) == ['a','b','c','d']
Ejemplo n.º 3
0
 def test_msort(self):
     for i in range(1, 100):
         sa = self.assertEqual
         l = self.random_list(random.randint(10, 100))
         sl = sorted(l)
         sorting.msort(l, 0, len(l) - 1)
         sa(sl, l)
Ejemplo n.º 4
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))
Ejemplo n.º 5
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))
Ejemplo n.º 6
0
 def test4(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.msort(inlist)==outlist) #test 4 fails - list not sorted by merge sort