示例#1
0
def test_insertion_sort_correct_sorts_a_random_list_of_strings():
    array = ["bird", "cat", "dog", "fish", "octopus", "snake"]
    expected = ["bird", "cat", "dog", "fish", "octopus", "snake"]
    random.shuffle(array)
    result = insertion_sort(array, sort_in_ascending)
    assert result == expected
示例#2
0
def test_insertion_sort_correct_sorts_a_list_of_numbers_descending():
    array = [5, 6, 4, 3, 8, 7]
    result = insertion_sort(array, sort_in_descending)
    assert result == [8, 7, 6, 5, 4, 3]
示例#3
0
def test_insertion_sort_correct_sorts_array_of_strings():
    array = ["cat", "dog", "bird", "fish", "snake"]
    result = insertion_sort(array, sort_in_ascending)
    assert result == ["bird", "cat", "dog", "fish", "snake"]
示例#4
0
def test_insertion_sort_correct_sorts_a_random_list_of_numbers():
    array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    expected = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    random.shuffle(array)
    result = insertion_sort(array, sort_in_ascending)
    assert result == expected
示例#5
0
def test_insertion_sort_correct_sorts_a_list_of_numbers():
    array = [5, 6, 4, 3, 8, 7]
    result = insertion_sort(array, sort_in_ascending)
    assert result == [3, 4, 5, 6, 7, 8]
示例#6
0
def test_insertion_correct_sort_sorts_a_short_list_of_numbers():
    array = [5, 3, 7]
    result = insertion_sort(array, sort_in_ascending)
    assert result == [3, 5, 7]
示例#7
0
def test_insertion_sort_has_right_number_of_comparisons():
    track = {'comparisons': 0, "copies": 0}
    array = parse_txt_file(lotsa_numbers)
    insertion_sort(array, sort_ascending_while_tracking, track)
    assert track['comparisons'] == 23958117
    assert track['copies'] == 23968128