コード例 #1
0
ファイル: test_sorts.py プロジェクト: manishpandit/workspace
    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))
コード例 #2
0
 def test_insertion_sort(self, array):
     assert not is_sorted(array)
     insertion_sort.sort(array)
     assert is_sorted(array)
コード例 #3
0
 def test_merge_sort(self, array):
     assert not is_sorted(array)
     merge_sort.sort(array)
     assert is_sorted(array)
コード例 #4
0
 def test_quick_sort_iterative(self, array):
     assert not is_sorted(array)
     quick_sort.sort(array)
     assert is_sorted(array)
コード例 #5
0
 def test_merge_in_place_a(self):
     a = [1, 2]
     b = []
     mip.merge_in_place(a, b)
     assert is_sorted(a)
コード例 #6
0
 def test_quick_sort_recursive(self, array):
     assert not is_sorted(array)
     quick_sort.sort(array, iterative=False)
     assert is_sorted(array)
コード例 #7
0
 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)
コード例 #8
0
 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)
コード例 #9
0
 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)
コード例 #10
0
 def test_merge_in_place_b(self):
     a = [None, None]
     b = [1, 2]
     mip.merge_in_place(a, b)
     assert is_sorted(a)
コード例 #11
0
 def test_bubble_sort(self, array):
     assert not is_sorted(array)
     bubble_sort.sort(array)
     assert is_sorted(array)