def main(): unsorted = [random.randint(-999, 9999) for i in range(0, 25)] print("unsorted list:", unsorted) bubble_sort.sort(unsorted) merge_sort.sort(unsorted) insertion_sort.sort(unsorted) quick_sort.sort(unsorted)
def run_tests(): print("\nBubble Sort tests") # setup numbers = [4, 1, 6, 2, 7, 9, 4, 3] sorted_numbers = [1, 2, 3, 4, 4, 6, 7, 9] # multiple_iterations test.are_equal("one iteration", bubble_sort.multiple_iterations(numbers, 1), [1, 4, 2, 6, 7, 4, 3, 9]) test.are_equal("two iterations", bubble_sort.multiple_iterations(numbers, 2), [1, 2, 4, 6, 4, 3, 7, 9]) test.are_equal("three iterations", bubble_sort.multiple_iterations(numbers, 3), [1, 2, 4, 4, 3, 6, 7, 9]) test.are_equal("four iterations", bubble_sort.multiple_iterations(numbers, 4), [1, 2, 4, 3, 4, 6, 7, 9]) test.are_equal("five iterations", bubble_sort.multiple_iterations(numbers, 5), sorted_numbers) # bubble_sort test.are_equal("bubble sort", bubble_sort.sort(numbers), sorted_numbers)
def run_tests(): print("\nBubble Sort tests") # setup numbers = [4, 1, 6, 2, 7, 9, 4, 3] sorted_numbers = [1, 2, 3, 4, 4, 6, 7, 9] # multiple_iterations test.are_equal("one iteration", bubble_sort.multiple_iterations(numbers, 1), [1, 4, 2, 6, 7, 4, 3, 9]) test.are_equal("two iterations", bubble_sort.multiple_iterations(numbers, 2), [1, 2, 4, 6, 4, 3, 7, 9]) test.are_equal("three iterations", bubble_sort.multiple_iterations(numbers, 3), [1, 2, 4, 4, 3, 6, 7, 9]) test.are_equal("four iterations", bubble_sort.multiple_iterations(numbers, 4), [1, 2, 4, 3, 4, 6, 7, 9]) test.are_equal("five iterations", bubble_sort.multiple_iterations(numbers, 5), sorted_numbers) # bubble_sort test.are_equal("bubble sort", bubble_sort.sort(numbers), sorted_numbers)
def test_bubble_sort(self): self.assertListEqual(bubble_sort.sort([34, 12, -7, 101, 28]), [-7, 12, 28, 34, 101]) self.assertListEqual(bubble_sort.sort([4, 3, 2, 1]), [1, 2, 3, 4])
def test_bubble_sort(): list_of_items = [54, 26, 93, 17, 77, 31, 44, 55, 20] print(list_of_items) bubble_sort.sort(list_of_items) print(list_of_items)
def test_bubble_sort(array_size): values = np.array( [int(array_size * random.random()) for _ in range(array_size)], dtype=np.int32) bubble_sort.sort(values)
def test_a_large_array_is_sorted_lowest_to_highest(self): assert sort(shuffle([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
def test_sort_returns_an_array_that_is_sorted_lowest_to_highest(self): assert sort([2, 1]) == [1, 2]
def test_bubble(self): for arr in self.test_arr: bubble_sort.sort(arr) self.assertEqual(arr, sorted(arr))
import lcm_iterative import lcm_recursive import lexicographic_order import merge_sort import palindrome import pattern_search import perfect_number import prime_factorisation import prime_number import quick_sort import selection_sort import sieve_of_eratosthenes import transposition_cipher """ SORTING """ bubble_sort.sort(array=[3, 2, 11, -1, 0]) array = [0.48, 0.27, 0.12, 0.21, 0.43, 0.25] bucket_sort.sort(array, max_value=max(array)) insertion_sort.sort(array=[3, 2, 11, -1, 0]) merge_sort.sort(array=[3, 2, 11, -1, 0]) array = [3, 2, 11, -1, 0] quick_sort.sort(array, left=0, right=len(array) - 1) selection_sort.sort(array=[3, 2, 11, -1, 0]) lexicographic_order.order(words=['aab', 'aaa', 'aa', 'aaa']) """ SEARCHING """
def test_bubblesort_should_sort_lists_correctly(self): for k, v in self.i_o: self.assertEqual(bubble_sort.sort(k), v)
import random as r import bubble_sort as bubble import shaker_sort as shaker import odd_even_sort as odd_even ar = [1, 2, 3, 4, 5, 6, 7, 8, 9] r.shuffle(ar) print("-------bubble_sort-------") print(bubble.sort(ar.copy())) print("-------shaker_sort--------") print(shaker.show_sorting(ar.copy())) print("------odd-even_sort-------") print(odd_even.show_sorting(ar.copy()))
def test_bubblesort_should_handle_edge_cases(self): for k,v in self.i_o: self.assertEqual(bubble_sort.sort(k), v)
def order(words): return bubble_sort.sort(words)
def test_bubblesort_should_sort_lists_correctly(self): for k,v in self.i_o: self.assertEqual(bubble_sort.sort(k), v)
def test_array_sort_results_are_in_order(self): array_to_sort = [11, 2, 4, 9, 5, 3, 1, 6, 8, 10, 7] sorted_array = bubble_sort.sort(array_to_sort) expected_array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] self.assertEqual(expected_array, sorted_array)
def test_sort(self): array = [4, 6, 2, 1, 8, 0, 4, 2, 4] expected = [0, 1, 2, 2, 4, 4, 4, 6, 8] self.assertEqual(sort(array), expected)
def test_bubble(self): for array in self.test_array: self.assertEqual(bubble_sort.sort(array), sorted(array))
def test_an_allready_sorted_array_returns_the_same_array(self): assert sort([1, 2]) == [1, 2]
def test_bubble_sort(): items = [7,3,2,6,1,5,9,0,4] assert_equal(sort(items), sorted(items)) assert_equal(sort(range(10)), sorted(range(10))) assert_equal(sort([]), [])
def test_a_more_complicated_array_is_sorted_lowest_to_highest(self): assert sort([4, 2, 3, 1]) == [1, 2, 3, 4]
def test_bubblesort_should_handle_edge_cases(self): for k, v in self.i_o: self.assertEqual(bubble_sort.sort(k), v)
def main(): array = [5, 4, 3, 2, 1] bubble_sort.sort(array) print array