コード例 #1
0
ファイル: test_qsort.py プロジェクト: WMcKibbin/quicksort
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'
    ]
コード例 #2
0
    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__),
            )
コード例 #3
0
ファイル: test_qsort.py プロジェクト: WMcKibbin/quicksort
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']
コード例 #4
0
ファイル: test_qsort.py プロジェクト: WMcKibbin/quicksort
def test_quicksort_str_only_two():
    arr = ['ab', 'bc']
    qsort.quicksort(arr, 0, len(arr) - 1)
    assert arr == ['ab', 'bc']
コード例 #5
0
ファイル: test_qsort.py プロジェクト: WMcKibbin/quicksort
def test_quicksort_str_only_one():
    arr = ['test']
    qsort.quicksort(arr, 0, len(arr) - 1)
    assert arr == ['test']
コード例 #6
0
ファイル: test_qsort.py プロジェクト: WMcKibbin/quicksort
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]
コード例 #7
0
ファイル: test_qsort.py プロジェクト: WMcKibbin/quicksort
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]
コード例 #8
0
ファイル: test_qsort.py プロジェクト: WMcKibbin/quicksort
def test_quicksort_num_only_two():
    arr = [1, 2]
    qsort.quicksort(arr, 0, len(arr) - 1)
    assert arr == [1, 2]
コード例 #9
0
ファイル: test_qsort.py プロジェクト: WMcKibbin/quicksort
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]
コード例 #10
0
ファイル: test_qsort.py プロジェクト: WMcKibbin/quicksort
def test_quicksort_empty_arr():
    with pytest.raises(qsort.EmptyArrayError):
        qsort.quicksort([], 0, 0)
コード例 #11
0
ファイル: zadanie1.py プロジェクト: KKobuszewski/pwzn
__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')
コード例 #12
0
ファイル: sorttest.py プロジェクト: GFSCompSci/cs2
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)
コード例 #13
0
 def __call__(self):
     qsort.quicksort(self.lst)
     tools.assert_equals(self.lst, self.sorted_lst)
コード例 #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)