def test_merge_2(self): data = [ 51, 91, 98, 78, 15, 30, 41, 7, 98, 63, 58, 61, 91, 56, 86, 98, 45, 84, 1, 9 ] expected = [ 1, 7, 9, 15, 30, 41, 45, 51, 56, 58, 61, 63, 78, 84, 86, 91, 91, 98, 98, 98 ] self.assertEqual(expected, merge_sort(data))
def test_sort(): """test sorting algorithms""" test_cases = ( ([0], [0]), ([2, 1], [1, 2]), ([1, 5, 65, 23, 57, 1232], [1, 5, 23, 57, 65, 1232]), ) for args, expected in test_cases: assert insertion_sort(args) == expected assert insertion_sort_optimized(args) == expected assert selection_sort(args) == expected assert merge_sort(args) == expected
def test_merge_sort(arr, expected): merge_sort(arr) assert arr == expected
def test_merge(self): data = [4, 2, 5, 6, 1, 7, 3, 15, 12, 9, 8, 20, 16] expected = [1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 15, 16, 20] self.assertEqual(expected, merge_sort(data))
def test_merge_3(self): data = [25, 42, 40, 24, 1, 49, 14, 13, 28, 24, 32, 46, 0, 50, 10] expected = [0, 1, 10, 13, 14, 24, 24, 25, 28, 32, 40, 42, 46, 49, 50] self.assertEqual(expected, merge_sort(data))