|
| 1 | +import unittest |
| 2 | +from sorts.radix_sort import radix_sort |
| 3 | + |
| 4 | + |
| 5 | +# testing the radix_sort function |
| 6 | +class TestRadixSort(unittest.TestCase): |
| 7 | + # Full test |
| 8 | + def test_radix_sort(self): |
| 9 | + self.assertEqual(radix_sort([0, 5, 2, 3, 2]), [0, 2, 2, 3, 5]) |
| 10 | + self.assertEqual(radix_sort([0, 5, 2, 3, 2]), sorted([0, 5, 2, 3, 2])) |
| 11 | + self.assertEqual(radix_sort([]), sorted([])) |
| 12 | + self.assertEqual(radix_sort([-2, -45, -5]), sorted([-2, -45, -5])) |
| 13 | + self.assertEqual(radix_sort([-23, 0, 6, -4, 34]), sorted([-23, 0, 6, -4, 34])) |
| 14 | + self.assertEqual(radix_sort(['d', 'a', 'b', 'e', 'c']), sorted(['d', 'a', 'b', 'e', 'c'])) |
| 15 | + |
| 16 | + def test_radix_sort_random(self): |
| 17 | + import random |
| 18 | + collection = random.sample(range(-50, 50), 100) |
| 19 | + self.assertEqual(radix_sort(collection), sorted(collection)) |
| 20 | + |
| 21 | + def test_radix_sort_string(self): |
| 22 | + import random |
| 23 | + import string |
| 24 | + collection = random.choices(string.ascii_letters + string.digits, k=100) |
| 25 | + self.assertEqual(radix_sort(collection), sorted(collection)) |
| 26 | + |
| 27 | + |
| 28 | +# main |
| 29 | +if __name__ == '__main__': |
| 30 | + unittest.main() |
0 commit comments