def test_it_sorts_an_unsorted_array_with_duplicates(self): # given an unsorted array A = [9, 5, 0, 2, 3, 15, 35, 9] # and a bubble sort instance C = bucket_sort(QuickSort, A, len(A)) # and check if the array is sorted self.assertEqual(C, sorted(A))
def test_it_sorts_an_unsorted_array_with_duplicates_and_N_is_not_full_length(self): # given an unsorted array A = [9, 5, 0, 2, 3, 15, 35, 9] # and a bubble sort instance C = bucket_sort(BubbleSort, A, int(len(A) / 2)) # and check if the array is sorted self.assertEqual(C, sorted(A))
def test_it_sorts_an_reverse_sorted_array(self): # given a reverse sorted array A = [35, 15, 9, 5, 3, 2, 0] # and a bubble sort instance C = bucket_sort(QuickSort, A, len(A)) # and check if the array is sorted self.assertEqual(C, sorted(A))
def test_it_sorts_an_unsorted_array(self): # given an unsorted array A = [9, 5, 0, 2, 3, 15, 35] # and a bubble sort instance C = bucket_sort(RadixSort, A, len(A)) # and check if the array is sorted self.assertEqual(C, sorted(A))
from FileImporter import FileImporter from FileWriter import FileWriter from os.path import basename if __name__ == '__main__': # begin execution if len(sys.argv) < 3: print("Not enough paramaters") exit(1) bucket_size = int(sys.argv[1]) input_file_name = str(sys.argv[2]) output_file_name = "owens-" + \ os.path.splitext(basename(input_file_name))[ 0] + "-" + str(bucket_size) + ".txt" fw = FileWriter(output_file_name) fi = FileImporter(input_file_name) arr = fi.get_array() start_times = [] end_times = [] for _ in range(3): start_times.append(time.clock()) ret = bucket_sort(QuickSort, arr, bucket_size) end_times.append(time.clock()) quick_sort_time = sum(end_times) - sum(start_times) fw = fw.set_number_buckets(bucket_size).set_sort_size( len(ret)).set_quick_sort_time(quick_sort_time) fw.set_out_array(ret).write()
def test_it_sorts_an_empty_array(self): # given an empty array A = [] C = bucket_sort(QuickSort, A, 10) # and check if the array is sorted self.assertEqual(C, A)
def test_it_sorts_an_empty_array(self): # given an empty array A = [] C = bucket_sort(RadixSort, A, 10) # and check if the array is <sorted></sorted> self.assertEqual(C, A)
def bubble_sort_thread(arr, bucket_size): start_time = time.clock() ret = bucket_sort(BubbleSort, arr, bucket_size) end_time = time.clock() return end_time - start_time
pool = ThreadPool(processes=3) pool_results = [] for i in range(3): print("Starting bucket sort thread " + str(i)) pool_results.append( pool.apply_async(bubble_sort_thread, (arr, bucket_size))) # End Bubble Sort Threads # Quick Sort start_times = [] end_times = [] for i in range(3): print("Starting quick sort " + str(i)) start_times.append(time.clock()) ret = bucket_sort(QuickSort, arr, bucket_size) end_times.append(time.clock()) quick_sort_time = (sum(end_times) - sum(start_times)) / len(end_times) # End Quick Sort # Radix Sort start_times = [] end_times = [] for i in range(3): print("Starting radix sort " + str(i)) start_times.append(time.clock()) ret = bucket_sort(RadixSort, arr, bucket_size) end_times.append(time.clock())
from FileWriter import FileWriter from os.path import basename if __name__ == '__main__': # begin execution if len(sys.argv) < 3: print("Not enough paramaters") exit(1) bucket_size = int(sys.argv[1]) input_file_name = str(sys.argv[2]) output_file_name = "owens-" + \ os.path.splitext(basename(input_file_name))[ 0] + "-" + str(bucket_size) + ".txt" fw = FileWriter(output_file_name) fi = FileImporter(input_file_name) arr = fi.get_array() start_times = [] end_times = [] for _ in range(3): start_times.append(time.clock()) ret = bucket_sort(BubbleSort, arr, bucket_size) end_times.append(time.clock()) bubble_sort_time = sum(end_times) - sum(start_times) fw = fw.set_number_buckets(bucket_size).set_sort_size( len(ret)).set_bubble_sort_time(bubble_sort_time) fw.set_out_array(ret).write()
from FileImporter import FileImporter from FileWriter import FileWriter from os.path import basename if __name__ == '__main__': # begin execution if len(sys.argv) < 3: print("Not enough paramaters") exit(1) bucket_size = int(sys.argv[1]) input_file_name = str(sys.argv[2]) output_file_name = "owens-" + \ os.path.splitext(basename(input_file_name))[ 0] + "-" + str(bucket_size) + ".txt" fw = FileWriter(output_file_name) fi = FileImporter(input_file_name) arr = fi.get_array() start_times = [] end_times = [] for _ in range(3): start_times.append(time.clock()) ret = bucket_sort(RadixSort, arr, bucket_size) end_times.append(time.clock()) radix_sort_time = sum(end_times) - sum(start_times) fw = fw.set_number_buckets(bucket_size).set_sort_size( len(ret)).set_radix_sort_time(radix_sort_time) fw.set_out_array(ret).write()