def test_sorts(self): sort_methods = [ insertion_sort.insertion_sort, selection_sort.selection_sort, bubble_sort.bubble_sort, merge_sort.merge_sort, heap_sort.heap_sort, quick_sort.quick_sort, quick_sort2.quick_sort ] size = [1, 2, 10, 1000, 10000] for sort_method in sort_methods: print(sort_method.__name__) start = time.time() for i in size: print("testing size: ", i) a = random_array(i) sort_method(a) self.assertTrue(is_sorted(a)) end = time.time() print("time: %.2f sec" % (end - start))
def test_insertion_sort(self, array): assert not is_sorted(array) insertion_sort.sort(array) assert is_sorted(array)
def test_merge_sort(self, array): assert not is_sorted(array) merge_sort.sort(array) assert is_sorted(array)
def test_quick_sort_iterative(self, array): assert not is_sorted(array) quick_sort.sort(array) assert is_sorted(array)
def test_merge_in_place_a(self): a = [1, 2] b = [] mip.merge_in_place(a, b) assert is_sorted(a)
def test_quick_sort_recursive(self, array): assert not is_sorted(array) quick_sort.sort(array, iterative=False) assert is_sorted(array)
def test_merge_in_place_big(self): a = [1, 3, 5, 8, 10, 14, None, None, None, None, None] b = [2, 4, 6, 9, 11] mip.merge_in_place(a, b) assert is_sorted(a)
def test_merge_in_place_zigzag(self): a = [1, 3, 5, None, None, None] b = [2, 4, 6] mip.merge_in_place(a, b) assert is_sorted(a)
def test_merge_in_place_unique(self): a = [1, 2, 3, None, None, None] b = [4, 5, 6] mip.merge_in_place(a, b) assert is_sorted(a)
def test_merge_in_place_b(self): a = [None, None] b = [1, 2] mip.merge_in_place(a, b) assert is_sorted(a)
def test_bubble_sort(self, array): assert not is_sorted(array) bubble_sort.sort(array) assert is_sorted(array)