当前位置: 首页>>代码示例>>Python>>正文


Python radix_sort.radix_sort函数代码示例

本文整理汇总了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
开发者ID:scotist,项目名称:data-structures,代码行数:9,代码来源:test_radix_sort.py

示例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
开发者ID:corinnelhh,项目名称:data-structures,代码行数:10,代码来源:test_sort.py

示例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
开发者ID:scotist,项目名称:data-structures,代码行数:10,代码来源:test_radix_sort.py

示例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',])
开发者ID:ShadowGiraffe,项目名称:algorithms,代码行数:10,代码来源:unit_test_radix_sort.py

示例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
开发者ID:scotist,项目名称:data-structures,代码行数:12,代码来源:test_radix_sort.py

示例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
开发者ID:scotist,项目名称:data-structures,代码行数:14,代码来源:test_radix_sort.py

示例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))
开发者ID:yurtaevnikita,项目名称:a3200-2015-algs,代码行数:7,代码来源:test_sorting.py

示例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")
开发者ID:vincentzhang,项目名称:coding-practice,代码行数:9,代码来源:test_sorting.py

示例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))
开发者ID:yurtaevnikita,项目名称:a3200-2015-algs,代码行数:5,代码来源:test_sorting.py

示例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))
开发者ID:yurtaevnikita,项目名称:a3200-2015-algs,代码行数:5,代码来源:test_sorting.py

示例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]
开发者ID:joelstanner,项目名称:data-structures-part2,代码行数:2,代码来源:test_radix_sort.py

示例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)
开发者ID:yurtaevnikita,项目名称:a3200-2015-algs,代码行数:6,代码来源:test_sorting.py

示例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))
开发者ID:yurtaevnikita,项目名称:a3200-2015-algs,代码行数:5,代码来源:test_sorting.py

示例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]
开发者ID:joelstanner,项目名称:data-structures-part2,代码行数:2,代码来源:test_radix_sort.py

示例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)
开发者ID:yurtaevnikita,项目名称:a3200-2015-algs,代码行数:6,代码来源:test_sorting.py


注:本文中的radix_sort.radix_sort函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。