def bubbleSortSpec1(): print('Empty list') A0 = list() A0_result = bubbleSort(A0) assert (not bool(A0_result)), "Empty list should return empty list" print('\n') print('A1 = [5,2,4,6,1,3]') A1 = [5, 2, 4, 6, 1, 3] A1_result = bubbleSort(A1) A1_expected = [1, 2, 3, 4, 5, 6] assert (A1_result == A1_expected), "A1" print('\n') print('A2 = [2,1]') A2 = [2, 1] A2_result = bubbleSort(A2) A2_expected = [1, 2] assert (A2_result == A2_expected), "A2" print('\n') print('A3 = [0,1,2,3,4,5,6,7]') A3 = [0, 1, 2, 3, 4, 5, 6, 7] A3_result = bubbleSort(A3) A3_expected = [0, 1, 2, 3, 4, 5, 6, 7] assert (A3_result == A3_expected), "A3" print('\n') print('A4 = [2]') A4 = [2] A4_result = bubbleSort(A4) A4_expected = [2] assert (A4_result == A4_expected), "A3"
def test(self): case_a = ['k', 'e', 'p', 'w', 'a', 'n'] case_b = [5, 7, 8, 1, 90, 12, 0] bubbleSort(case_a) bubbleSort(case_b) self.assertTrue(['a', 'e', 'k', 'n', 'p', 'w']) self.assertTrue([0, 1, 5, 7, 8, 12, 90])
def StartAlgorithm(): global data scale = speedScale.get() if not data: return if algMenu.get() == 'Quick Sort': quick_sort( data, 0, len(data) - 1, drawData, scale, ) elif algMenu.get() == 'Bubble Sort': bubbleSort(data, drawData, scale) elif algMenu.get() == 'Selection Sort': selectionSort(data, drawData, scale) elif algMenu.get() == 'Merge Sort': mergeSort(data, drawData, scale) elif algMenu.get() == 'Insertion Sort': insertionSort(data, drawData, scale) drawData(data, ['green' for x in range(len(data))])
def StartAlgorithm(): global data if not data: return if algo_menu.get() == 'Quick Sort': quickSort(data, 0, len(data) - 1, drawData, speedscale.get()) elif algo_menu.get() == "Bubble Sort": bubbleSort(data, drawData, speedscale.get())
def sampleMedianSelect(list, left, right, m): if m >= len(list[left:right + 1]): #print("m>len(list)->decreasing m") m = len(list[left:right + 1]) S = random.sample(list[left:right + 1], m) if m <= 20: bubbleSort(S) else: mergeSort(S) return S[ceil(len(S) / 2)]
def startAlgo(): global data if Menu.get()=='Bubble sort': bubbleSort(data,drawData,speed_scale.get()) elif Menu.get()=='Merge sort': mergeSort(data, drawData, speed_scale.get()) elif Menu.get()=='Insertion sort': insertionSort(data, drawData, speed_scale.get()) elif Menu.get()=='Selection sort': selectionSort(data, drawData, speed_scale.get()) elif Menu.get()=='Quick sort': quicksort(data,0,len(data)-1, drawData, speed_scale.get()) drawData(data,['green' for x in range(len(data))])
def calcularTiempoAlgoritmos(arreglo, tamanio,archivo): tiempos=[] #Tiempo RadixSort arreglo = generarArreglo(arreglo,tamanio) inicio = time() ordenadoRadix = radixSort(arreglo.copy(), 10) final = time() tiempos.append(final-inicio) #Tiempo QuickSort aux = arreglo.copy() inicio = time() quickSort(aux) final = time() tiempos.append(final-inicio) # Tiempo bubbleSort aux2 = arreglo.copy() inicio = time() bubbleSort(aux2) final = time() tiempos.append(final-inicio) #Tiempo shellSort aux3 = arreglo.copy() inicio = time() shellSort(aux3) final = time() tiempos.append(final-inicio) #Tiempo heapsort aux4 = arreglo.copy() inicio = time() heapsort(aux4) final = time() tiempos.append(final-inicio) archivo.write(str(tamanio)) for element in tiempos: linea+=","+str(element*1000) #para que quede en milisegundos archivo.write("\n")
def sampleMedianSelect(list, left, right, m): if m >= len(list[left:right + 1]): print( "m>len(list)->decreasing m" ) # il caso in cui m sia più grande dell'array viene gestito portandolo m = len( list[left:right + 1] ) # alla minima grandezza accettabile affinche l'algoritmo funzioni # cosi in un caso pratico in cui verrebbe utilizzato in qualche applicazione S = random.sample( list[left:right + 1], m ) # in cui m è scelto a caso l'algoritmo non si ferma,al massimo rallenta un po' if m <= 20: # oppure potrebbe anche non accadere mai con opportuni controlli a monte bubbleSort( S ) # nella scelta di m da parte dell'utente o dalla funzione chiamante #inserctionSort(S) #selectionSort(S) else: #S.sort() #mergeSort(S) #quickSort(S) heapSort(S) return S[ceil(len(S) / 2)]