예제 #1
0
 def test_random(self):
     random.seed()
     arr = []
     for i in range(random.randint(100, 1000)):
         arr.append(random.randint(-100000, 100000))
     res = radix_sort.sort(arr)
     self.assertTrue(is_sorted(res))
예제 #2
0
 def test_random_repeating(self):
     random.seed()
     arr = []
     for i in range(random.randint(10, 100)):
         val = random.randint(-100000, 100000)
         for j in range(random.randint(1, 15)):
             arr.append(val)
     res = radix_sort.sort(arr)
     self.assertTrue(is_sorted(res))
예제 #3
0
 def test_trivial(self):
     arr = [42, 23, 16, 15, 8, 4, 17, 13, 11, 7, 5, 3, 2]
     res = radix_sort.sort(arr)
     expected = [2, 3, 4, 5, 7, 8, 11, 13, 15, 16, 17, 23, 42]
     self.assertFalse(not res)
     self.assertEqual(expected, res)
예제 #4
0
 def test_empty(self):
     arr = []
     res = radix_sort.sort(arr)
     expected = []
     self.assertEqual(expected, res)
예제 #5
0
 def test_trivial(self):
     arr = [1, 333, 22]
     res = radix_sort.sort(arr)
     expected = [1, 22, 333]
     self.assertFalse(not res)  # check res not empty
     self.assertEqual(expected, res)
예제 #6
0
import random

# from bubble_sort import sort
# from insert_sort import sort
# from select_sort import sort
# from merge_sort import sort
# from quick_sort import sort, choose_k_nums
# from bucket_sort import sort
# from counting_sort import sort
from radix_sort import sort

ok = True
for i in range(100):
    # datas = [random.randint(1, 100) for _ in range(100)]
    datas = [
        ''.join([str(random.randint(0, 9)) for _ in range(10)])
        for j in range(100)
    ]
    print(f'Before: {datas}')
    if list(sorted(datas)) != sort(datas):
        ok = False

    print(f'After: {sort(datas)}')

print(f'After = Before: {ok}')
예제 #7
0
 def testGeneralCase(self):
     A = [465, 321, 474, 355, 123, 777, 919, 134, 221, 756]
     A = radix_sort.sort(A, 3)
     expected = [123, 134, 221, 321, 355, 465, 474, 756, 777, 919]
     self.assertEqual(A, expected)
예제 #8
0
 def test_with_random_elements(self):
     arr = [random.randint(0, 100000) for i in range(50)]
     result = radix_sort.sort(arr)
     self.assertTrue(self.check_sort(result))
예제 #9
0
 def test_with_one_random_element(self):
     one_element = random.randint(0, 100000)
     arr = [one_element]
     result = radix_sort.sort(arr)
     expected = [one_element]
     self.assertEqual(expected, result)
예제 #10
0
 def test_with_equal_elements(self):
     arr = [3, 3, 2, 2, 1, 1, 1, 0]
     result = radix_sort.sort(arr)
     expected = [0, 1, 1, 1, 2, 2, 3, 3]
     self.assertEqual(expected, result)
예제 #11
0
from sys import stdin
import radix_sort

arr = [int(n) for n in stdin.readline().split()]
for x in radix_sort.sort(arr):
    print(x, end=" ")