Esempio n. 1
0
 def test_is_sorted(self):
     a = int_sort_list[0].copy()
     quick_sort(a)
     self.assertEqual(a, int_sort_list[1])
     b = str_sort_list[0].copy()
     quick_sort(b)
     self.assertEqual(b, str_sort_list[1])
Esempio n. 2
0
def test_quick_sort():
    test_array = [randint(0, 1000000)
                  for i in range(1, 10000)]  # will crash on larger sizes
    test_array.sort()
    quick_sort(test_array, 0, len(test_array) - 1)
    lst_copy = deepcopy(test_array)
    lst_copy.sort()
    assert test_array == lst_copy
Esempio n. 3
0
 def test_quick_sort(self):
     a = [5, 8, 1, 9, 6, 3, 10, 7, 2, 4]
     b = a.copy()
     b.sort()
     quick_sort(a, 0, len(a) - 1)
     self.assertEqual(a, b)
     c = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
     d = c.copy()
     d.sort()
     quick_sort(c, 0, len(c) - 1)
     self.assertEqual(c, d)
Esempio n. 4
0
 def test__quick_sort(self):
     for items in self.generate_cases(self.n_cases):
         ans = sorted(items)
         t1 = time.time_ns()
         res = sorts.quick_sort(items)
         self.ts.append(time.time_ns() - t1)
         self.assertEqual(res, ans)
Esempio n. 5
0
def main():
    test_list = [-2.3, 1, 3, 4.2, 4, 2.4, -5.2, 10.9, 11, 3.9]
    shuffle(test_list)
    print("List to sort: ", test_list)
    sorts.insertion_sort(test_list, 0, len(test_list))
    print("\nSorted list by Insertion Sort: ", test_list)
    shuffle(test_list)
    print("\nNew list to sort: ", test_list)
    sorts.quick_sort(test_list, 0, len(test_list) - 1)
    print("\nSorted list by Quick Sort: ", test_list)
    shuffle(test_list)
    print("\nNew list to sort: ", test_list)
    print("\nSorted list by Tree Sort: ", sorts.tree_sort(test_list))
    shuffle(test_list)
    print("\nNew list to sort: ", test_list)
    sorts.pancake_sort(test_list)
    print("\nSorted list by Pancake Sort: ", test_list)
    print()
Esempio n. 6
0
 def test_quick_sort(self):
     start = timeit.default_timer()       
     Y = sorts.quick_sort(self.random_seq)
     end = timeit.default_timer()
     print("Quick sort took %s sec" % str(end-start))
     self.assertEqual(Y, sorted(self.random_seq))
from random import randint
import logging
from copy import copy

import sorts

if __name__ == '__main__':

    N_list = [50000]
    ROUND = 1

    logging.basicConfig(level=logging.INFO)

    for N in N_list:
        randint_list = [[randint(0, 2 ** 31 - 1)
                         for _ in range(N)] for _ in range(ROUND)]

        for i in range(ROUND):
            bubble_list = copy(randint_list[i])
            insertion_list = copy(randint_list[i])
            selection_list = copy(randint_list[i])
            quick_list = copy(randint_list[i])
            heap_list = copy(randint_list[i])

            sorts.bubble_sort(bubble_list)
            sorts.insertion_sort(insertion_list)
            sorts.selection_sort(selection_list)
            sorts.quick_sort(quick_list)
            sorts.heap_sort(heap_list)
Esempio n. 8
0
def quick_sort(input_file_name: str, output_file_name: str = None):
    numbers = get_numbers_from_file(input_file_name)
    sorted_numbers = sorts.quick_sort(numbers)
    print_numbers_to_file(sorted_numbers, output_file_name)
Esempio n. 9
0
def main(argv):
    data = files.read_lines_of_ints(argv[0])
    n = data[0][0]
    A = data[1]

    print ' '.join(str(item) for item in sorts.quick_sort(A, 0, n - 1))