Exemple #1
0
def test_quicksort_str_all_same():
    arr = [
        'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test',
        'test', 'test'
    ]
    qsort.quicksort(arr, 0, len(arr) - 1)
    assert arr == [
        'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test',
        'test', 'test'
    ]
    def _testFile(self, filename, expected_low, expected_high, expected_median):

        choosePivotFunctions = (qsort.choosePivotLow, qsort.choosePivotHigh, qsort.choosePivotMedian)
        expected_values = expected_low, expected_high, expected_median

        with open(filename) as file:
            strings = file.read().split("\n")
            l_base = [int(x) for x in strings if len(x)]

        for function, expected_value in zip(choosePivotFunctions, expected_values):
            l = l_base[:]
            actual_value = qsort.quicksort(l, 0, len(l) - 1, function)
            self.assertEqual(
                expected_value,
                actual_value,
                "Wrong value, expected %d, got %d (%s)" % (expected_value, actual_value, function.__name__),
            )
Exemple #3
0
def test_quicksort_str_sorted_arr():
    arr = ['a', 'b', 'c', 'd', 'e']
    qsort.quicksort(arr, 0, len(arr) - 1)
    assert arr == ['a', 'b', 'c', 'd', 'e']
Exemple #4
0
def test_quicksort_str_only_two():
    arr = ['ab', 'bc']
    qsort.quicksort(arr, 0, len(arr) - 1)
    assert arr == ['ab', 'bc']
Exemple #5
0
def test_quicksort_str_only_one():
    arr = ['test']
    qsort.quicksort(arr, 0, len(arr) - 1)
    assert arr == ['test']
Exemple #6
0
def test_quicksort_num_sorted_arr():
    arr = [1, 2, 3, 4, 5]
    qsort.quicksort(arr, 0, len(arr) - 1)
    assert arr == [1, 2, 3, 4, 5]
Exemple #7
0
def test_quicksort_num_inverse_arr():
    arr = [5, 4, 3, 2, 1]
    qsort.quicksort(arr, 0, len(arr) - 1)
    assert arr == [1, 2, 3, 4, 5]
Exemple #8
0
def test_quicksort_num_only_two():
    arr = [1, 2]
    qsort.quicksort(arr, 0, len(arr) - 1)
    assert arr == [1, 2]
Exemple #9
0
def test_quicksort_num_all_same():
    arr = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
    qsort.quicksort(arr, 0, len(arr) - 1)
    assert arr == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
Exemple #10
0
def test_quicksort_empty_arr():
    with pytest.raises(qsort.EmptyArrayError):
        qsort.quicksort([], 0, 0)
Exemple #11
0
__author__ = 'konrad'
import pyximport; pyximport.install()
from Quicksort.original_qsort import quicksort as qsortpy
from qsort import quicksort
from time import monotonic as time

import numpy as np

list1 = np.random.rand(1000)
list2 = np.random.rand(1000)
start = time()
qsortpy(list1, 0, 999)
sec_py = (time()-start)
start2=time()
quicksort(list2, 0, 999)
sec_cyth = (time()-start2)
print('funkcja w czystym pythonie:\t', sec_py, 's')
print('funkcja w cythonie:\t\t\t', sec_cyth, 's')
print('uzyskane przyspieszenie:\t', sec_py/sec_cyth, 'razy')
Exemple #12
0
import time
from listgen import listGen
from qsort import quicksort
from selsort import *

n = 100000

newlist = listGen(n)
print
start = time.clock()
selectionSort(newlist)
timeTotal = time.clock() - start
print "Selection sort took %f seconds to run." % (timeTotal)
print
newlist = listGen(n)
start = time.clock()
quicksort(newlist)
timeTotal = time.clock() - start
print "Quicksort took %f seconds to run." % (timeTotal)
Exemple #13
0
 def __call__(self):
     qsort.quicksort(self.lst)
     tools.assert_equals(self.lst, self.sorted_lst)
Exemple #14
0
def check_sorted(lst):
    sorted_lst = sorted(lst)
    lst = lst[:] # do not modify lists
    qsort.quicksort(lst)
    tools.assert_equals(lst, sorted_lst)