def main(): '''Main program''' # get the WordData list data = get_data() # Sort the list of WordData objects by highest percent using your Bubble Sort # function. Sort the list in place (don't create a new list). Print the first 50 # WordData objects in the list. print() print('BY PERCENT:') bubble_sort(data, 2, descending=True) for wd in data[:50]: print(wd) # Sort the list of WordData objects by highest count using your Insertion Sort # function. Sort the list in place (don't create a new list). Print the first 50 # WordData objects in the list. print() print('BY COUNT:') insertion_sort(data, 1, descending=True) for wd in data[:50]: print(wd) # Sort the list of WordData objects by alpha order (a-z) using your Selection Sort # function. Sort the list in place (don't create a new list). Print the first 50 # WordData objects in the list. print() print('BY WORD:') selection_sort(data, 0) for wd in data[:50]: print(wd)
def test_bubble_sort_ascending(self): from sorters import bubble_sort idx = 1 bubble_sort(self.data, idx) for a, b in self.iterPairs(): self.assertLessEqual(a[idx], b[idx], msg='previous {} should be less than current {} at index {}'.format(a, b, idx))
def test_bubble_sort_ascending(self): from sorters import bubble_sort idx = 1 bubble_sort(self.data, idx) self.debugPrint() # remove this line - only used while creating the test for a, b in self.iterPairs(): print('{} < {}'.format(a, b)) # remove this line - only used while creating the test self.assertLessEqual(a[idx], b[idx], msg='previous {} should be less than current {} at index {}'.format(a, b, idx))
def test_bubble_sort_percentage(self): from sorters import bubble_sort idx = 2 bubble_sort(self.data, idx, True) for a, b in self.iterPairs(): self.assertGreaterEqual( a[idx], b[idx], msg='previous {} should be greater than current {} at index {}' .format(a, b, idx))
def test_bubble_selection(self): from sorters import bubble_sort, selection_sort idxes = [0, 1, 2] for idx in idxes: data_copy1, data_copy2 = self.data[:], self.data[:] bubble_sort(data_copy1, idx) selection_sort(data_copy2, idx) for i in range(len(data_copy1)): self.assertEqual(data_copy1[i][idx], data_copy2[i][idx])
def test_bubble_sort_descending(self): from sorters import bubble_sort idxes = [0, 1, 2] for idx in idxes: bubble_sort(self.data, idx, True) for a, b in self.iterPairs(): self.assertGreaterEqual( a[idx], b[idx], msg='previous {} should be less than current {} at index {}' .format(a, b, idx))
def sort(): if request.method == 'POST': if request.form.get("sort_selection") == "Bubble Sort": unsorted = prepare_input(request.form.get("Numbers")) sorted_list = bubble_sort(unsorted) return render_template("sorting.html", sorted = sorted_list) return render_template("sorting.html")