Skip to content

Commit a1e9656

Browse files
mvhbgithub-actionspoyea
authored
Hacktoberfest: adding doctest to radix_sort.py file (TheAlgorithms#2779)
* adding doctest to radix_sort.py file * fixup! Format Python code with psf/black push * Update radix_sort.py * Update radix_sort.py * fixup! Format Python code with psf/black push * Update radix_sort.py * line * fix tests Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: John Law <[email protected]>
1 parent e172a8b commit a1e9656

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

sorts/radix_sort.py

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1+
"""
2+
This is a pure Python implementation of the quick sort algorithm
3+
For doctests run following command:
4+
python -m doctest -v radix_sort.py
5+
or
6+
python3 -m doctest -v radix_sort.py
7+
For manual testing run:
8+
python radix_sort.py
9+
"""
110
from __future__ import annotations
211

12+
from typing import List
313

4-
def radix_sort(list_of_ints: list[int]) -> list[int]:
14+
15+
def radix_sort(list_of_ints: List[int]) -> List[int]:
516
"""
6-
radix_sort(range(15)) == sorted(range(15))
17+
Examples:
18+
>>> radix_sort([0, 5, 3, 2, 2])
19+
[0, 2, 2, 3, 5]
20+
21+
>>> radix_sort(list(range(15))) == sorted(range(15))
722
True
8-
radix_sort(reversed(range(15))) == sorted(range(15))
23+
>>> radix_sort(list(range(14,-1,-1))) == sorted(range(15))
924
True
10-
radix_sort([1,100,10,1000]) == sorted([1,100,10,1000])
25+
>>> radix_sort([1,100,10,1000]) == sorted([1,100,10,1000])
1126
True
1227
"""
1328
RADIX = 10
@@ -29,3 +44,9 @@ def radix_sort(list_of_ints: list[int]) -> list[int]:
2944
# move to next
3045
placement *= RADIX
3146
return list_of_ints
47+
48+
49+
if __name__ == "__main__":
50+
import doctest
51+
52+
doctest.testmod()

0 commit comments

Comments
 (0)