Ejemplo n.º 1
0
def main():

    registers_name = read_file_by_name()
    registers_cpf = read_file_by_cpf()

    print("Dados carregados e tratados com sucesso!\n")
    print("O que deseja fazer com o vetor inicial?\n")
    print("1 - Randomizar vetor")
    print("2 - Ordem original do vetor")
    opc = input()
    if (opc == '1'):
        registers_name = random_vector(registers_name)
        registers_cpf = random_vector(registers_cpf)
    print("Qual ordenação deseja fazer?")
    print("1 - Selection Sort")
    print("2 - Insertion Sort")
    print("3 - Bubble Sort")
    opc = input()

    if (opc == '1'):
        print("Ordenar pelo nome ou pelo CPF?")
        print("1 - Nome")
        print("2 - CPF")
        opc = int(input())
        if (opc == 1):
            start = time.time()
            registers_sorted = selection_sort(registers_name)
            end = time.time()
            elapsed_time = end - start
            sucess_menu(elapsed_time, registers_sorted)
        elif (opc == 2):
            start = time.time()
            registers_sorted = selection_sort(registers_cpf)
            end = time.time()
            elapsed_time = end - start
            sucess_menu(elapsed_time, registers_sorted)
        else:
            print("Fim")
            return
    elif (opc == '2'):
        print("Ordenar pelo nome ou pelo CPF?")
        print("1 - Nome")
        print("2 - CPF")
        opc = int(input())
        if (opc == 1):
            start = time.time()
            registers_sorted = insertion_sort(registers_name)
            end = time.time()
            elapsed_time = end - start
            sucess_menu(elapsed_time, registers_sorted)
        elif (opc == 2):
            start = time.time()
            registers_sorted = insertion_sort(registers_cpf)
            end = time.time()
            elapsed_time = end - start
            sucess_menu(elapsed_time, registers_sorted)
        else:
            print("Fim")
            return
    elif (opc == '3'):
        print("Ordenar pelo nome ou pelo CPF?")
        print("1 - Nome")
        print("2 - CPF")
        opc = int(input())
        if (opc == 1):
            start = time.time()
            registers_sorted = bubble(registers_name)
            end = time.time()
            elapsed_time = end - start
            sucess_menu(elapsed_time, registers_sorted)
        elif (opc == 2):
            start = time.time()
            registers_sorted = bubble(registers_cpf)
            end = time.time()
            elapsed_time = end - start
            sucess_menu(elapsed_time, registers_sorted)
        else:
            print("Fim")
            return
Ejemplo n.º 2
0
#run 

import numpy as np

from sorts import bubble, quickSort

x = np.random.rand(10)
print("Unsorted input: ", x)

print("Bubble sort output: ", bubble(x))
print("Quick sort output: ", quicksort(x))
Ejemplo n.º 3
0
def test_bubble_sort():
    test_array = [randint(-10**4, 10**3) for i in range(1, 10**2)]
    result = bubble(test_array)
    test_array.sort()
    assert test_array == result
def test_param_b():
    lst = [2, 1, 2, 8, 5, 0, 6]
    assert sorts.bubble(lst) == sorted(lst)
def test_equal_b(lst):
    assert sorts.bubble(lst) == sorted(lst)
def test_equal_bq(lst):
    assert sorts.bubble(lst) == sorts.qsort(lst)