def test_bubble_sort_sorts_parsed_text_file_with_odd_event_comparator(): parsed_text = parse_txt_file(text) bubble_sort(parsed_text, odd_even_comparator) first_ten = parsed_text[:10] last_ten = parsed_text[-10:] assert first_ten == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] assert last_ten == [9982, 9984, 9986, 9988, 9990, 9992, 9994, 9996, 9998, 10000]
def test_selection_sort_sorts_parsed_text_file_with_odd_event_comparator(): parsed_text = parse_txt_file(text) selection_sort(parsed_text, sort_in_ascending) first_ten = parsed_text[:10] last_ten = parsed_text[-10:] assert first_ten == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] assert last_ten == [9991, 9992, 9993, 9994, 9995, 9996, 9997, 9998, 9999, 10000]
def test_bubble_sort_has_right_number_of_comparisons(): track = {'comparisons': 0, "copies": 0} array = parse_txt_file(lotsa_numbers) bubble_sort(array, sort_ascending_while_tracking, track) assert track['comparisons'] == 49988559 assert track['copies'] == 71844390
def test_merge_sort_has_right_number_of_comparisons(): track = {'comparisons': 0, "copies": 0} array = parse_txt_file(text) selection_sort(array, sort_ascending_while_tracking, track) assert track['comparisons'] == 49995000 assert track['copies'] == 29964
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