Skip to content

Commit f0353fa

Browse files
committed
add unit test radix python
1 parent 9b72dd6 commit f0353fa

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

classical_algorithms/python/radix.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def _sort(self, data):
2121
data.extend(bucket)
2222
return data
2323

24+
# TODO: Expand functionality to work with negative numbers
2425

2526
# Ex:
2627
array = [50, 2, 13, 23, 11, 100]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import unittest
2+
from classical_algorithms.python.radix import Radix
3+
4+
5+
class TestRadix(unittest.TestCase):
6+
def test_radix(self):
7+
radix = Radix()
8+
9+
print('None Input')
10+
self.assertRaises(TypeError, radix.sort, None)
11+
12+
print('Empty Input')
13+
self.assertEqual(radix.sort([]), [])
14+
15+
print('One Element')
16+
self.assertEqual(radix.sort([25]), [25])
17+
18+
print('Two or More Elements')
19+
array = [10, 1, 0, 100, 5, 15, 100, 7, 500, 200]
20+
self.assertEqual(sorted(array), radix.sort(array))
21+
22+
# TODO: Include tests for negative numbers
23+
24+
print('Success: test_radix\n')
25+
26+
27+
def main():
28+
TestRadix.test_radix()
29+
30+
31+
if __name__ == '__main__':
32+
main()

0 commit comments

Comments
 (0)