class TestSort(unittest.TestCase): def setUp(self) -> None: self.my_lst = [9, 7, 4, 8, 6] self.sort_machine = RadixSort(self.my_lst) def testSort(self): self.assertEqual(self.sort_machine.radix_sort(), [4, 6, 7, 8, 9])
start = timer() InsertionSort().insertionsort(arr) end = timer() print("Tempo di esecuzione: " + str(end - start) + "s") print("\n") # Radix Sort for i in [100, 1000, 10000, 100000]: print("RadixSort su Array di {} elementi Random".format(i)) arr = [random.randint(1, 100) for _ in range(0, i)] start = timer() RadixSort().radixSort(arr) end = timer() print("Tempo di esecuzione: " + str(end - start) + "s") print("\n") # Radix Sort for i in [100, 1000, 10000, 100000]: print("RadixSort su Array di {} elementi array ordinato".format(i)) arr = [0 for _ in range(0, i)] for i in range(1, i): arr[i] = arr[i - 1] + 1 start = timer() RadixSort().radixSort(arr)
def radix_sort(array): start = timeit.default_timer() copied_array = copy.copy(array) RadixSort.sort(array=copied_array) end = timeit.default_timer() return format(end - start, '.5f')
from merge_sort import MergeSort from quick_sort import QuickSort from bubble_sort import BubbleSort from selection_sort import SelectionSort from insertion_sort import InsertionSort from time import time import random options = { 1: ("Bubble Sort", BubbleSort()), 2: ("Selection Sort", SelectionSort()), 3: ("Insertion Sort", InsertionSort()), 4: ("Quick Sort", QuickSort()), 5: ("Merge Sort", MergeSort()), 6: ("Radix Sort", RadixSort()), 7: ("Counting Sort", CountingSort()), 8: ("Heap Sort", HeapSort()) } print("Sorting Options: ") for i in options.keys(): print("Option {} : {}".format(i, options[i][0])) while True: option = int(input("Enter sorting option: ")) sort_alg = options[option][1] start = time() arr = [random.randint(-100000, 100000) for _ in range(10)] print(arr) sort_alg.sort(arr) end = time() print(arr)
def setUp(self) -> None: self.my_lst = [9, 7, 4, 8, 6] self.sort_machine = RadixSort(self.my_lst)
from radix_sort import RadixSort vals = [1, 543, 'qwe', 'dd', 'd', 'hello world', 76, 2, 34, 6, 8, 5, 342, 35, 68, 7543] vals1 = [1, 543, 76, 2, 34, 6, 8, 5, 342, 35, 68, 7543] RadixSort.sort_msd(vals) RadixSort.sort_lsd(vals1) print(vals) print(vals1)
from radix_sort import RadixSort import numpy as np array = np.array([32, 2, 5, 12, 5, 1, 9, 7, 11], dtype=int) radix_obj = RadixSort(array) sorted_array = radix_obj.sorted_array print("\nsorted array is {}\n".format(sorted_array))
def test_radix_sort(self): algo = SortingTestWrapper(RadixSort(), self.n, self.seed) self.assertListEqual(algo.integer_sort(), self.verification.integer_sort())