def test_merge_sort_bottom_up(): print "\nmerge sort bottom up begin" count = random.randint(100, 1000) for _ in range(count): length = random.randint(5, 30) source = tool.random_list(0, 100, length) target = sort.merge_down_to_up(source) if tool.list_is_ascend(target) is False: print source print target print "" assert (tool.list_is_ascend(target)) print "merge sort bottom up success in {0} times.\n".format(count)
def test_quick_sort_lomuto(): print "\nQuick sort lomuto test begin" count = random.randint(100, 1000) for _ in range(count): length = random.randint(5, 30) source = tool.random_list(0, 100, length) target = sort.quick_sort_lomuto(source) if tool.list_is_ascend(target) is False: print source print target print "" assert (tool.list_is_ascend(target)) print "Quick sort lomuto success in {0} times.\n".format(count)
def test_heap_sort(): print "\nheap sort begin" count = random.randint(100, 1000) for _ in range(count): length = random.randint(5, 30) source = tool.random_list(0, 100, length) target = sort.heap_sort(source) if tool.list_is_descend(target) is False: print source print target print "" assert (tool.list_is_descend(target)) print "heap sort success in {0} times.\n".format(count)
def test_one(): maleftValue = 9999999 length = 100000 array = tool.random_list(0, maleftValue, length, False) array1 = array[:] array2 = array[:] array3 = array[:] array4 = array[:] left = 0 right = len(array) - 1 # print array b1 = time.time() quickSort1(array1, left, right) e1 = time.time() if tool.list_is_ascend(array1) is False: print "\nsort-1 error" else: print "\nsort-1 OK! time = {}".format(e1 - b1) b2 = time.time() quickSort2(array2, left, right) e2 = time.time() if tool.list_is_ascend(array2) is False: print "sort-2 error" else: print "sort-2 OK! time = {}".format(e2 - b2) b3 = time.time() quickSort3(array3, left, right) e3 = time.time() if tool.list_is_ascend(array3) is False: print "sort-3 error: ", array3 else: print "sort-3 OK! time = {}".format(e3 - b3) b4 = time.time() quickSort4(array4, left, right) e4 = time.time() if tool.list_is_ascend(array4) is False: print "sort-4 error: ", array4 else: print "sort-4 OK! time = {}".format(e4 - b4)