def test_partially_sort_sequence_using_top_down_merge_sort(): assert_equal( MergeSort.top_down_mergesort([2, 1, 7, 4, 5, 6], delimeter=1), [1, 2, 7, 4, 5, 6]) assert_equal( MergeSort.top_down_mergesort([45, 51, 92, 25, 93, 22, 35, 27, 29, 49, 80, 19], delimeter=7), [22, 25, 45, 51, 92, 93, 27, 29, 35, 49, 80, 19])
import random from sort import MergeSort sort = MergeSort() def test_sorting(): ''' Testing sort method. ''' assert sort([]) == [] assert sort([1]) == [1] assert sort([0, 1]) == [0, 1] assert sort([1, 0]) == [0, 1] n = 1000 input = range(n) random.shuffle(input) assert sort(input) == range(n) def test_basic_inversions(): ''' Testing basic cases of inversion counting. ''' assert sort([]) == [] assert sort.inversions == 0, "for empty input" assert sort([1]) == [1]
def test_partially_sort_sequence_using_bottom_up_merge_sort(): sequence = [76, 43, 51, 90, 68, 73, 57, 41, 99, 84] expected = [43, 51, 76, 90, 41, 57, 68, 73, 84, 99] assert_equal(MergeSort.bottom_up_mergesort(sequence, delimeter=7), expected)