本文整理汇总了Python中radix_sort.radix_sort函数的典型用法代码示例。如果您正苦于以下问题:Python radix_sort函数的具体用法?Python radix_sort怎么用?Python radix_sort使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了radix_sort函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_stable
def test_stable():
"""Test identical items in list retain stable position on sort."""
from radix_sort import radix_sort
check_list = [1, 0, 2, 3, 2]
two_a = check_list[2]
two_b = check_list[4]
radix_sort(check_list)
assert check_list[2] is two_a
assert check_list[3] is two_b
示例2: test_radix_sort
def test_radix_sort(build_list):
x, y = build_list
assert radix_sort(x) == y
import random
for i in xrange(100):
x = [random.randint(10,100) for i in xrange(20)]
y = radix_sort(x)
z = quick_sort(x)
assert y == z
示例3: test_stable_random
def test_stable_random(seq):
"""Test stability property on random lists."""
from radix_sort import radix_sort
seq = list(seq)
index_a, index_b = sorted(random.sample(range(len(seq)), 2))
val_a, val_b = 0, 0
seq[index_a], seq[index_b] = val_a, val_b
radix_sort(seq)
assert seq[0] is val_a
assert seq[1] is val_b
示例4: test_of_small_array
def test_of_small_array(self):
a = [
'4PGC938',
'2IYE230',
'3CIO720',
'2RLA629',]
radix_sort(a)
self.assertEqual(
a,
['2IYE230', '2RLA629', '3CIO720', '4PGC938',])
示例5: test_stable_random_2
def test_stable_random_2(seq):
"""Test that stability fails when sorting to end of list."""
from radix_sort import radix_sort
if len(seq) < 3:
return
seq = list(seq)
index_a, index_b = sorted(random.sample(range(len(seq)), 2))
val_a, val_b = 1000, 1000
seq[index_a], seq[index_b] = val_a, val_b
radix_sort(seq)
assert seq[-1] is val_a
assert seq[-2] is val_b
示例6: test_stable_random_3
def test_stable_random_3(seq):
"""Test stability property on random lists with random duplicate values."""
from radix_sort import radix_sort
if len(seq) < 2:
return
seq = list(seq)
index_a = random.randrange(len(seq) - 1)
index_b = random.randrange(index_a + 1, len(seq))
val_a = seq[index_a]
val_b = int(val_a)
seq[index_b] = val_b
radix_sort(seq)
index_a = seq.index(val_a)
assert seq[index_a + 1] is val_b
示例7: test_single_negative
def test_single_negative(self):
arr = [-1]
res = radix_sort(arr)
expected = [-1]
self.assertFalse(not res)
self.assertEqual(expected, res)
self.assertEqual(len(arr), len(res))
示例8: testRadix
def testRadix(self):
result = copy(self.original)
before = time.time()
result = radix_sort(result)
after = time.time()
print("Radix Sort, size: %d time: %f" % (self.list_length, after-before))
#print "Original List is: ", self.original
#print "Result of Radix Sort is: ", result
self.assertEqual(self.sorted_list, result, "Radix Sort Failed")
示例9: test_multiple_negative
def test_multiple_negative(self):
arr = [random.randint(-1000000, -1) for i in range(100000)]
res = radix_sort(arr)
self.assertTrue(self.check_sorted(res))
self.assertEqual(len(arr), len(res))
示例10: test_long_array
def test_long_array(self):
arr = [random.randint(0, 1000000) for i in range(200000)]
res = radix_sort(arr)
self.assertTrue(self.check_sorted(res))
self.assertEqual(len(arr), len(res))
示例11: test_radix_sort_on_unordered_list
def test_radix_sort_on_unordered_list():
assert radix_sort([4, 1, 9, 200, 15]) == [1, 4, 9, 15, 200]
示例12: test_trivial_3
def test_trivial_3(self):
arr = [0]
res = radix_sort(arr)
expected = [0]
self.assertFalse(not res)
self.assertEqual(expected, res)
示例13: test_different_length_ints
def test_different_length_ints(self):
arr = [random.randint(0, 1000000) for i in range(1000)]
res = radix_sort(arr)
self.assertTrue(self.check_sorted(res))
self.assertEqual(len(arr), len(res))
示例14: test_radix_sort_on_ordered_list
def test_radix_sort_on_ordered_list():
assert radix_sort([1, 2, 2, 3, 4]) == [1, 2, 2, 3, 4]
示例15: test_trivial_2
def test_trivial_2(self):
arr = [123456789]
res = radix_sort(arr)
expected = [123456789]
self.assertFalse(not res)
self.assertEqual(expected, res)