def test_sort_sorted_list_of_integers(self): """Test that when selection sort is passed a sorted list of integers that the list remains sorted. """ selection_sort(self.sorted_list_of_integers) self.assertEqual(self.sorted_list_of_integers, [-7, -2, -1, 0, 1, 4, 10])
def test_sort_unsorted_list_of_integers(self): """Test that when selection sort is passed an unsorted list of integers that the list is properly sorted. """ selection_sort(self.unsorted_list_of_integers) self.assertEqual(self.unsorted_list_of_integers, self.sorted_list_of_integers)
def test_selection_sort_is_unstable(self): """Test that if two elements in a list have the same key, that their relative ordering is still preserved after the list is sorted. """ selection_sort(self.unsorted_list_of_products) self.assertEqual(self.unsorted_list_of_products, self.sorted_list_of_products_unstable)
def draw_chart(sort_type, original_data, frame_interval): fig = plt.figure(1, figsize=(16, 9)) data_set = [Data(d) for d in original_data] axs = fig.add_subplot(111) plt.subplots_adjust(left=0.01, bottom=0.01, right=0.99, top=0.95) if sort_type == 1: frames = selection_sort(data_set) elif sort_type == 2: frames = bubble_sort(data_set) elif sort_type == 3: frames = insertion_sort(data_set) elif sort_type == 4: frames = merge_sort(data_set) elif sort_type == 5: frames = quick_sort(data_set) else: raise IndexError def animate(frame_no): # if fi % 2 != 0 and frame_interval < 10 and fi != len(frames)-1: # return bars = [] if len(frames) > frame_no: axs.cla() axs.set_title(s_type[sort_type]) axs.set_xticks([]) axs.set_yticks([]) bars += axs.bar(list(range(Data.length)), [d.value for d in frames[frame_no]], 1, color=[d.color for d in frames[frame_no]]).get_children() frame_no += 1 return bars anim = animation.FuncAnimation(fig, animate, frames=len(frames), interval=frame_interval, repeat=False) return plt, anim
def test_selection_sort(self): for test, assertion in self.test_cases: with self.subTest(): self.assertEqual(selection_sort(test), assertion)
def test_selection_sort(): nums = [10, 30, 5, 1, 100, 20, 6, 50] assert selection_sort(nums) == [1, 5, 6, 10, 20, 30, 50, 100]
def test_selection_sort(self): self.assertEqual(selection_sort.selection_sort(self.array), self.sorted_array)
from timeit import default_timer as timer import csv_reader from sorting.merge_sort import * from sorting.selection_sort import selection_sort import copy from datetime import timedelta import info_printer if __name__ == '__main__': list_of_pools = csv_reader.read_csv_file('pool.csv') start_time = timer() sorted_list = merge_sort_by_visitors(copy.deepcopy(list_of_pools)) elapsed_time = timedelta(seconds=timer() - start_time) print('-------------------- MERGE SORT --------------------') info_printer.print_algorithm_info(elapsed_time, 'MERGE') print('---------------------- RESULT ----------------------') info_printer.print_list(sorted_list) print('\n') start_time = timer() sorted_list = selection_sort(copy.deepcopy(list_of_pools)) elapsed_time = timedelta(seconds=timer() - start_time) print('------------------ SELECTION SORT ------------------') info_printer.print_algorithm_info(elapsed_time, 'SELECTION') print('---------------------- RESULT ----------------------') info_printer.print_list(sorted_list) print('\n')
def test_merge_sort_asc(self): expected: List[int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] selection_sort.selection_sort(arr) self.assertEqual(expected, arr)
def test_merge_sort_empty(self): arr_one: List[int] = [] selection_sort.selection_sort(arr_one) self.assertEqual([], arr_one)
def test_merge_sort_one(self): arr_one: List[int] = [10] selection_sort.selection_sort(arr_one) self.assertEqual([10], arr_one)
def test_merge_sort_desc(self): expected: List[int] = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] selection_sort.selection_sort(arr, True) self.assertEqual(expected, arr)
def test_sort(): xs = list(np.random.randint(0, 1000, size=[1000])) assert selection_sort(xs) is None assert xs == sorted(xs)
def test_sort_empty_list(self): """Test that when selection sort is passed an empty list, that nothing happens.""" selection_sort(self.empty_list) self.assertEqual(self.empty_list, [])