示例#1
0
def test_randoms():
    x = range(100)
    randoms = x[:]
    shuffle(randoms)
    radixsort(randoms)
    y = randoms
    assert x == y
示例#2
0
def test_ordered():
    x = []
    for i in range(1, 10):
        x.append(i)
    radixsort(x)
    z = x
    assert z == x
示例#3
0
def test_reversed():
    x = []
    for i in range(1, 10):
        x.append(i)
    y = []
    for i in reversed(x):
        y.append(i)
    radixsort(y)
    z = y
    assert z == x
示例#4
0
def test_badinput():
    with pytest.raises(TypeError):
        radixsort('bad', 123, [6, 7], ('hi', 2))
示例#5
0
def test_string():
    with pytest.raises(ValueError):
        radixsort('cat')
示例#6
0
def test_various_length():
    x = [1, 200, 600, 1234567, 99999, 7]
    radixsort(x)
    y = x
    expected = [1, 7, 200, 600, 99999, 1234567]
    assert expected == y
示例#7
0
def test_empty():
    x = []
    y = x
    radixsort(x)
    assert x == y
示例#8
0
文件: diff.py 项目: zs1621/pythostudy
A = []
B = []
C = []
jon = []
#ran = 9000000000000000000000000000000000000000000000000000000000000000000
ran = 2 ** 140
length = [1000, 10000, 30000, 50000]
for lent in length:
    for i in range(0,lent):
        num = random.randint(100000,ran)
        A.append(num)
        #B.append(num)
        C.append(num)

    start2 = time.clock()
    radix_sort.radixsort(C)
    radix_time = time.clock() - start2
    print ("tong use time: ", time.clock() - start2)


    start = time.clock()
    merge_sort.sort(A, 0, len(A))
    merge_time = time.clock() - start
    print ("merge sort use: ", time.clock() - start )
    jon.append({"x": lent, "mst": merge_time, "rst": radix_time})

f = open('result.json','w')

f.write(json.dumps(jon))

#start1 = time.clock()