def test_insertion_sort(display: bool=True): s = "INSERTIONSORT" l = list(s) sort.insertion_sort(l) if l != ['E', 'I', 'I', 'N', 'N', 'O', 'O', 'R', 'R', 'S', 'S', 'T', 'T']: raise ValueError if display: print(l)
def test_insertion_sort_simple_even(self): arr = [4, 3, 2, 1] arr_copy = arr[::] arr_copy.sort() self.assertEqual( insertion_sort(arr), arr_copy )
def test_insertion_sort_large(self): arr = random.sample(range(500), 500) arr_copy = arr[::] arr_copy.sort() self.assertEqual( insertion_sort(arr), arr_copy )
def test_insertion_sort(self): self.assertEqual([1, 5, 23, 57, 65, 1232], insertion_sort([1, 5, 65, 23, 57, 1232]))
from random import randint ARRAY_LENGTH = 10000 if __name__ == "__main__": # merge sort my_list = [randint(0, 1000) for i in range(ARRAY_LENGTH)] print(my_list[:10]) sot = time.perf_counter() my_list = merge_sort(my_list) eot = time.perf_counter() print("Total run time for merge sort",eot-sot) print(my_list[:10]) # insertion sort my_list = [randint(0, 1000) for i in range(ARRAY_LENGTH)] print(my_list[:10]) sot = time.perf_counter() my_list = insertion_sort(my_list) print(my_list[:10]) eot = time.perf_counter() print("Total run time for insertion sort",eot-sot) # selection sort my_list = [randint(0, 1000) for i in range(ARRAY_LENGTH)] print(my_list[:10]) sot = time.perf_counter() my_list = selection_sort(my_list) eot = time.perf_counter() print("Total run time for selection sort",eot-sot) print(my_list[:10]) # quick sort my_list = [randint(0, 1000) for i in range(ARRAY_LENGTH)] print(my_list[:10]) sot = time.perf_counter()
from algorithms.sort import insertion_sort import random alist=[random.randint(1,100) for i in range(100)] print(alist) sorted_list=insertion_sort(alist) print(sorted_list)
def test_insertion_sort(self): self.assertEqual([1, 5, 23, 57, 65, 1232], insertion_sort([1, 5, 65, 23, 57, 1232]))
# Design and Analysis of Data Structures and Algorithms import random from algorithms.sort import bubble_sort, selection_sort, insertion_sort, merge_sort, quick_sort numbers = random.sample(range(100, 999), 25) print("Unsorted List") print(numbers) print("Bubble Sort") bs = bubble_sort(numbers) print(bs) print("Selection Sort") ss = selection_sort(numbers) print(ss) print("Insertion Sort") ins = insertion_sort(numbers) print(ins) print("Merge Sort") ms = merge_sort(numbers) print(ms) print("Quick Sort") qs = quick_sort(numbers) print(qs)
def test_insertion_sort(unsorted, expected): assert sort.insertion_sort(unsorted) == expected