Esempio n. 1
0
def test_bubble_sort(display: bool=True):
    s = "BUBBLESORT"
    l = list(s)
    sort.bubble_sort(l)
    if l != ['B', 'B', 'B', 'E', 'L', 'O', 'R', 'S', 'U', 'T']:
        raise ValueError
    if display:
        print(l)
Esempio n. 2
0
 def test_bubble_sort(self):
     self.assertEqual([1, 5, 23, 57, 65, 1232],
                      bubble_sort([1, 5, 65, 23, 57, 1232]))
Esempio n. 3
0
    eot = time.perf_counter()
    print("Total run time for selection sort",eot-sot)
    print(my_list[:10])
#   quick sort
    my_list = [randint(0, 1000) for i in range(ARRAY_LENGTH)]
    print(my_list[:10])
    sot = time.perf_counter()
    my_list = quick_sort(my_list)
    eot = time.perf_counter()
    print("Total run time for quick sort",eot-sot)
    print(my_list[:10])
#   bubble sort
    my_list = [randint(0, 1000) for i in range(ARRAY_LENGTH)]
    print(my_list[:10])
    sot = time.perf_counter()
    my_list = bubble_sort(my_list)
    eot = time.perf_counter()
    print("Total run time for bubble sort",eot-sot)
    print(my_list[:10])
#   shell sort
    my_list = [randint(0, 1000) for i in range(ARRAY_LENGTH)]
    print(my_list[:10])
    sot = time.perf_counter()
    my_list = shell_sort(my_list)
    eot = time.perf_counter()
    print("Total run time for shell sort",eot-sot)
    print(my_list[:10])
#   radix sort
    my_list = [randint(0, 1000) for i in range(ARRAY_LENGTH)]
    print(my_list[:10])
    sot = time.perf_counter()
Esempio n. 4
0
 def test_bubble_sort(self):
     self.assertTrue(is_sorted(bubble_sort([1, 3, 2, 5, 65, 23, 57, 1232])))
Esempio n. 5
0
 def test_bubble_sort_simple_even(self):
     arr = [4, 3, 2, 1]
     arr_copy = arr[::]
     arr_copy.sort()
     self.assertEqual(bubble_sort(arr), arr_copy)
Esempio n. 6
0
        test_list.append(value)
    test_number = test_list[random.randrange(len(test_list))]

    print()
    print("List Length: ", list_length)
    print("test_number: ", test_number)

    # Testing on the unsorted list for sequential.
    start_sequential = time.time()
    sequential_search(test_list, test_number)
    end_sequential = time.time()
    time_sequential = end_sequential - start_sequential

    print("Time for sequential sort (unsorted): ", time_sequential)

    test_list = bubble_sort(test_list)

    start_sequential = time.time()
    sequential_search(test_list, test_number)
    end_sequential = time.time()
    time_sequential = end_sequential - start_sequential

    start_binary = time.time()
    binary_search(test_list, test_number)
    end_binary = time.time()
    time_binary = end_binary - start_binary

    print("Time for sequential sort (sorted): ", time_sequential)
    print("Time for binary sort: ", time_binary)

    list_length = list_length * 10
Esempio n. 7
0
 def test_bubble_sort_large(self):
     arr = random.sample(range(500), 500)
     arr_copy = arr[::]
     arr_copy.sort()
     self.assertEqual(bubble_sort(arr), arr_copy)
Esempio n. 8
0
# Design and Analysis of Data Structures and Algorithms

import random
from algorithms.sort import bubble_sort, selection_sort, insertion_sort, merge_sort, quick_sort

numbers = random.sample(range(100, 999), 25)

print("Unsorted List")
print(numbers)

print("Bubble Sort")
bs = bubble_sort(numbers)
print(bs)

print("Selection Sort")
ss = selection_sort(numbers)
print(ss)

print("Insertion Sort")
ins = insertion_sort(numbers)
print(ins)

print("Merge Sort")
ms = merge_sort(numbers)
print(ms)

print("Quick Sort")
qs = quick_sort(numbers)
print(qs)
Esempio n. 9
0
 def test_bubble_sort(self):
     self.assertEqual([1, 5, 23, 57, 65, 1232],
                      bubble_sort([1, 5, 65, 23, 57, 1232]))
Esempio n. 10
0
def step_impl(context):
    array = []
    context.result = sort.bubble_sort(array)
Esempio n. 11
0
def step_impl(context):
    array = [-45, 56.7, 8532, -8542.53, 54523321]
    context.result = sort.bubble_sort(array)
Esempio n. 12
0
def step_impl(context):
    array = [3, 23, 7, 1, 95, 58, 36]
    context.result = sort.bubble_sort(array)
Esempio n. 13
0
from algorithms.sort import bubble_sort
import random

alist = [random.randint(1, 10) for i in range(100)]
print(alist)
sorted_list = bubble_sort(alist)
print(sorted_list)
Esempio n. 14
0
def test_bubble_sort(unsorted, expected):
    assert sort.bubble_sort(unsorted) == expected