Beispiel #1
0
def test_second_instance():
    result = radixsort.radixsort([114, 21, 95, 5, 2, 14, 52, 30, 6, 20], 4)
    expected_result = [[52, 20, 21, 5, 114, 2, 14, 30, 6, 95],
                       [114, 2, 52, 20, 21, 5, 6, 14, 30, 95],
                       [2, 5, 6, 14, 20, 21, 30, 95, 114, 52],
                       [2, 5, 6, 14, 20, 21, 30, 52, 95, 114]]
    assert result == expected_result
def test_radix_sort_verbose():
    """Test with many lists."""
    from radixsort import radixsort
    # test on 100 lists
    for i in range(100):
        # generate random length of list
        list_length = random.randint(0, 100)
        unsorted_list = []
        for x in range(list_length):
            # generate random numbers for random length list
            unsorted_list.append(random.randint(0, 100))

        # test that list is sorted
        assert radixsort(unsorted_list) == sorted(unsorted_list)
Beispiel #3
0
# MergeSort
start = timer()
mergesort()
end = timer()
mergesort_elapsed_time = end - start

# QuickSort
start = timer()
quicksort()
end = timer()
quicksort_elapsed_time = end - start

# RadixSort
start = timer()
radixsort()
end = timer()
radixsort_elapsed_time = end - start

# SelectionSort
start = timer()
selectionsort()
end = timer()
selectionsort_elapsed_time = end - start

# TimSort
start = timer()
timsort()
end = timer()
timsort_elapsed_time = end - start
def test_radix_sort():
    """Test with simple list."""
    from radixsort import radixsort
    nums = [5, 3, 2, 7, 9, 4, 0, 1]
    assert radixsort(nums) == [0, 1, 2, 3, 4, 5, 7, 9]
Beispiel #5
0
def test_first_instance():
    result = radixsort.radixsort([329, 457, 657, 839, 436, 720, 355], 10)
    expected_result = [[720, 355, 436, 457, 657, 329, 839],
                       [720, 329, 436, 839, 355, 457, 657],
                       [329, 355, 436, 457, 657, 720, 839]]
    assert result == expected_result
def test_radixsort(s):
    assert sorted(s) == radixsort.radixsort(s)