def testmergesort(self): print('main') A = [random.randint(-100,100) for c in range(100000)] print('before sort',A) MergeSort.sort(A) print('after sort', A) for i in range(len(A)-1): if A[i] > A[i+1]: self.fail('Error in Merge Sort')
def run_merge_sort(): ll = np.random.randint(-10, 10, 10) #[7, 6, 5, 4, 3, 2, 1] print(ll) _is = MergeSort(ll) res = _is.sort() print("MergeSort") print() print(f"before: {ll}") print(f"after: {res}") print()
def test_merge_sort(self) -> None: elements: List[int] = [] #random.seed(a=1) elements = [random.randrange(0, 101) for _ in range(100)] #elements = [96, 90, 85, 78, 81, 97, 14, 29, 73, 84] print('Elements are :{}'.format(elements)) ms = MergeSort(elements) sorted_elements = ms.sort() print('Elements after sorting are : {}'.format(elements)) elements.sort() self.assertEqual(elements, sorted_elements)
def main(): original = [325432, 989, 547510, 3, -93, 189019, 5042, 123, 597, 42, 7506, 184, 184, 2409, 45, 824, 4, -2650, 9, 662, 3928, -170, 45358, 395, 842, 7697, 110, 14, 99, 221] numbers = original[:] ms = MergeSort(numbers) output = ms.sort() if is_sorted(output): print("** SUCCESS! **") else: print("Uh oh - not in order.") if contain_same_ints(original, numbers): print("** Contain the same elements! **") else: print("Uh oh - something is missing.") print(output)
def main(): original = [ 325432, 989, 547510, 3, -93, 189019, 5042, 123, 597, 42, 7506, 184, 184, 2409, 45, 824, 4, -2650, 9, 662, 3928, -170, 45358, 395, 842, 7697, 110, 14, 99, 221 ] numbers = original[:] ms = MergeSort(numbers) output = ms.sort() if is_sorted(output): print("** SUCCESS! **") else: print("Uh oh - not in order.") if contain_same_ints(original, numbers): print("** Contain the same elements! **") else: print("Uh oh - something is missing.") print(output)
# repetition for different orders of array size for i in range(1,n): l = 10**i # order of array size arr = [int(random.random()*100) for j in range(l)] # create an array of random numbers with incremental order alist = [0]*len(arr) # initialize an empty array of same size times[i-1][0] = l # add the order as the first column in the matrix # a loop to go through all the sorting algorithms for g in range(1, 6): start = time.clock() # get a CPU clock tick if g == 1: temp = SelectionSort.sort(dup(alist, arr)) elif g == 2: temp = InsertionSort.sort(dup(alist, arr)) elif g == 3: temp = MergeSort.sort(dup(alist, arr)) elif g == 4: temp = QuickSort.sort(dup(alist, arr)) elif g == 5: temp = CountSort.sort(dup(alist, arr)) end = time.clock() - start # get a CPU clock tick and estimate algorithm r setin(i, end, g) endit = time.clock() - begin # estimate overal calculation time print ('Total time Elapsed:', endit, 'seconds.') # show the benchmark matrix for i in range(0, n-1): print (times[i])
def merge_sort(array): start = timeit.default_timer() copied_array = copy.copy(array) MergeSort.sort(array=copied_array) end = timeit.default_timer() return format(end - start, '.5f')