def calcularTiempoAlgoritmos(tiemposEjecucion, tamanio,archivo): tiempos=[] #Tiempo RadixSort arreglo = generarArreglo(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 CountingSort aux2 = arreglo.copy() inicio = time() countingSort(aux2, tamanio) final = time() tiempos.append(final-inicio) #Tiempo CombSort aux3 = arreglo.copy() inicio = time() combsort(aux3) final = time() tiempos.append(final-inicio) #Tiempo ShellSort aux4 = arreglo.copy() inicio = time() shellSort(aux4) final = time() tiempos.append(final-inicio) #Tiempo InsertionSort aux5 = arreglo.copy() inicio = time() insertsort(aux5) final = time() tiempos.append(final-inicio) archivo.write("10") for element in tiempos: linea+=","+str(element) archivo.write("\n")
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 test_already_sorted(self): input = [0, 1, 2, 3, 4, 5] output = input[:] shellSort(output) self.assertEqual(output, sorted(input), "Should be [0,1,2,3,4,5]")
def test_backwards_array(self): input = [5, 4, 3, 2, 1] output = input[:] shellSort(output) self.assertEqual(output, sorted(input), "Should be [1, 2, 3, 4, 5]")
def test_unsorted_array(self): input = [1, 5, 63, 3, 54, 1] output = input[:] shellSort(output) self.assertEqual(output, sorted(input), "Should be [1, 1, 3, 5, 54, 63]")
def test_empty_array(self): input = [] output = input[:] shellSort(output) self.assertEqual(output, sorted(input), "Should be []")