def main(): # Create test array testArray = [random.randint(1, 100) for _ in range(20)] # measure the elapsed time for the algorithm start = time.time() merged = sort.merge(testArray) end = time.time() # print merge sort results print "Merge Sort: completed in: " + str(end - start) + " seconds" print testArray print str(merged) + '\n' # measure the elapsed time for the quick sort algorithm start = time.time() quickly = sort.quick(testArray) end = time.time() # print quick sort results print "Quick Sort: completed in: " + str(end - start) + " seconds" print testArray print str(quickly) + '\n' start = time.time() heaped = sort.heap(testArray) end = time.time() # print merge sort results print "Heap Sort: completed in: " + str(end - start) + " seconds" print testArray print str(heaped) + '\n'
def test_sort(enabled): if enabled: if SORT_BUBBLE_ENABLED: # Bubble algorithm reset("Bubble Sort") sort.bubble(input) if SORT_INSERT_ENABLED: # Insert algorithm reset("Insertion Sort") sort.insert(input) if SORT_MERGE_ENABLED: # Merge algorithm reset("Merge Sort") sort.merge(input) if SORT_QUICK_ENABLED: # QuickSOrt algorithm reset("Quick Sort") sort.quick(input)
def test_quick(self): self.assertEqual(sort.quick([3, 7, 2, 1, 5, 4], 0, 5), [1, 2, 3, 4, 5, 7]) self.assertEqual(len(sort.quick([3, 4, 2, 6, 6, 1], 0, 5)), 6)
def test_qsort(arr): assert sort.quick(arr) == sorted(arr)
def test_quick(): a = random_array() expected = sorted(a) a = sort.quick(a) s = 'test_quick failed ({})'.format(a) assert str(expected) == str(a), s