Exemple #1
0
 def test_selection_sort_large(self):
     arr = random.sample(range(500), 500)
     arr_copy = arr[::]
     arr_copy.sort()
     self.assertEqual(
         selection_sort(arr),
         arr_copy
     )
Exemple #2
0
 def test_selection_sort_simple_even(self):
     arr = [4, 3, 2, 1]
     arr_copy = arr[::]
     arr_copy.sort()
     self.assertEqual(
         selection_sort(arr),
         arr_copy
     )
Exemple #3
0
 def test_selection_sort(self):
     self.assertEqual([1, 5, 23, 57, 65, 1232],
                      selection_sort([1, 5, 65, 23, 57, 1232]))
Exemple #4
0
    eot = time.perf_counter()
    print("Total run time for merge sort",eot-sot)
    print(my_list[:10])
#   insertion sort
    my_list = [randint(0, 1000) for i in range(ARRAY_LENGTH)]
    print(my_list[:10])
    sot = time.perf_counter()
    my_list = insertion_sort(my_list)
    print(my_list[:10])
    eot = time.perf_counter()
    print("Total run time for insertion sort",eot-sot)
#   selection sort
    my_list = [randint(0, 1000) for i in range(ARRAY_LENGTH)]
    print(my_list[:10])
    sot = time.perf_counter()
    my_list = selection_sort(my_list)
    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()
Exemple #5
0
 def test_selection_sort(self):
     self.assertTrue(
         is_sorted(selection_sort([1, 3, 2, 5, 65, 23, 57, 1232])))
from algorithms.sort import selection_sort
import random
alist=[random.randint(1,100) for i in range(10)]
print(alist)
sorted_list=selection_sort(alist,simulation=True)
print(sorted_list)
Exemple #7
0
 def test_selection_sort(self):
     self.assertEqual([1, 5, 23, 57, 65, 1232],
                      selection_sort([1, 5, 65, 23, 57, 1232]))
Exemple #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)
Exemple #9
0
def test_selection_sort(unsorted, expected):
    assert sort.selection_sort(unsorted) == expected