def main(): unit_test(quicksort, [[]], [], verbose=True) unit_test(quicksort, [[1]], [1], verbose=True) unit_test(quicksort, [[3, 2, 1]], [1, 2, 3], verbose=True) unit_test(quicksort, [[8, 2, 6, 5, 4, 1, 9, 3, 7]], [1, 2, 3, 4, 5, 6, 7, 8, 9], True) unit_test(quicksort, [[1, 1, 1, 1, 1]], [1, 1, 1, 1, 1], True) unit_test(quicksort, [[1, 1, 0, 1, 1]], [0, 1, 1, 1, 1], True) print 'unit_test(quicksort, random.sample(xrange(100),100), range(100))' unit_test(quicksort, [random.sample(xrange(100), 100)], range(100)) print 'unit_test(quicksort, random.sample(xrange(1e3),1e3), range(1e3))' unit_test(quicksort, [random.sample(xrange(1000), 1000)], range(1000)) print 'unit_test(quicksort, random.sample(xrange(1e4),1e4), range(1e4))' unit_test(quicksort, [random.sample(xrange(10000), 10000)], range(10000)) print 'unit_test(quicksort, random.sample(xrange(1e5),1e5), range(1e5))' unit_test(quicksort, [random.sample(xrange(100000), 100000)], range(100000)) array = list(pd.read_csv('../data/10.txt', header=-1)[0]) unit_test(quicksort, [array], range(1, 11), verbose=False) array = list(pd.read_csv('../data/10.txt', header=-1)[0]) unit_test(quicksort, [array, None, None, pivot_selector_end], range(1, 11), verbose=False) array = list(pd.read_csv('../data/10.txt', header=-1)[0]) unit_test(quicksort, [array, None, None, pivot_selector_median], range(1, 11), verbose=False) array = list(pd.read_csv('../data/100.txt', header=-1)[0]) unit_test(quicksort, [array], range(1, 101), verbose=False) array = list(pd.read_csv('../data/100.txt', header=-1)[0]) unit_test(quicksort, [array, None, None, pivot_selector_end], range(1, 101), verbose=False) array = list(pd.read_csv('../data/100.txt', header=-1)[0]) unit_test(quicksort, [array, None, None, pivot_selector_median], range(1, 101), verbose=False) array = list(pd.read_csv('../data/1000.txt', header=-1)[0]) unit_test(quicksort, [array], range(1, 1001), verbose=False) array = list(pd.read_csv('../data/1000.txt', header=-1)[0]) unit_test(quicksort, [array, None, None, pivot_selector_end], range(1, 1001), verbose=False) array = list(pd.read_csv('../data/1000.txt', header=-1)[0]) unit_test(quicksort, [array, None, None, pivot_selector_median], range(1, 1001), verbose=False) for n in xrange(5): unit_test(quicksort, [range(2**n - 1), None, None, pivot_selector_median], range(2**n - 1), verbose=True)
def main(): unit_test(selection, [[], 0], (None, None), verbose=True) unit_test(selection, [[1], 0], (1, 0), verbose=True) unit_test(selection, [[3, 2, 1], 2], (3, 2), verbose=True) unit_test(selection, [[8, 2, 6, 5, 4, 1, 9, 3, 7], 4], (5, 4), True) unit_test(selection, [[1, 1, 1, 1, 1], 2], (1, 2), True) unit_test(selection, [[1, 1, 0, 1, 1], 0], (0, 0), True)
def main(): unit_test(mergesort, [], [], verbose=True) unit_test(mergesort, [3, 2, 1], [1, 2, 3], verbose=True) unit_test(mergesort, [8, 2, 6, 5, 4, 1, 9, 3, 7], [1, 2, 3, 4, 5, 6, 7, 8, 9], True) unit_test(mergesort, [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], True) unit_test(mergesort, [1, 1, 0, 1, 1], [0, 1, 1, 1, 1], True) print "unit_test(mergesort, random.sample(xrange(100),100), range(100))" unit_test(mergesort, random.sample(xrange(100), 100), range(100)) print "unit_test(mergesort, random.sample(xrange(1e3),1e3), range(1e3))" unit_test(mergesort, random.sample(xrange(1000), 1000), range(1000)) print "unit_test(mergesort, random.sample(xrange(1e4),1e4), range(1e4))" unit_test(mergesort, random.sample(xrange(10000), 10000), range(10000)) print "unit_test(mergesort, random.sample(xrange(1e5),1e5), range(1e5))" unit_test(mergesort, random.sample(xrange(100000), 100000), range(100000))
def main(): unit_test(mergesort, [[], True], ([], 0), verbose=True) unit_test(mergesort, [[3, 2, 1], True], ([1, 2, 3], 3), True) unit_test(mergesort, ([8, 2, 6, 5, 4, 1, 9, 3, 7], True), ([1, 2, 3, 4, 5, 6, 7, 8, 9], 19), True) unit_test(mergesort, [[1, 1, 1, 1, 1], True], ([1, 1, 1, 1, 1], 0), True) unit_test(mergesort, [[1, 1, 0, 1, 1], True], ([0, 1, 1, 1, 1], 2), True) unit_test(mergesort, [range(99999, -1, -1), True], (range(100000), 100000 * 99999 / 2), False)