mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-30 16:31:08 +00:00
Hacktoberfest: adding doctest to radix_sort.py file (#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 <johnlaw.po@gmail.com>
This commit is contained in:
parent
e172a8b08b
commit
a1e9656eca
|
@ -1,13 +1,28 @@
|
||||||
|
"""
|
||||||
|
This is a pure Python implementation of the quick sort algorithm
|
||||||
|
For doctests run following command:
|
||||||
|
python -m doctest -v radix_sort.py
|
||||||
|
or
|
||||||
|
python3 -m doctest -v radix_sort.py
|
||||||
|
For manual testing run:
|
||||||
|
python radix_sort.py
|
||||||
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import List
|
||||||
|
|
||||||
def radix_sort(list_of_ints: list[int]) -> list[int]:
|
|
||||||
|
def radix_sort(list_of_ints: List[int]) -> List[int]:
|
||||||
"""
|
"""
|
||||||
radix_sort(range(15)) == sorted(range(15))
|
Examples:
|
||||||
|
>>> radix_sort([0, 5, 3, 2, 2])
|
||||||
|
[0, 2, 2, 3, 5]
|
||||||
|
|
||||||
|
>>> radix_sort(list(range(15))) == sorted(range(15))
|
||||||
True
|
True
|
||||||
radix_sort(reversed(range(15))) == sorted(range(15))
|
>>> radix_sort(list(range(14,-1,-1))) == sorted(range(15))
|
||||||
True
|
True
|
||||||
radix_sort([1,100,10,1000]) == sorted([1,100,10,1000])
|
>>> radix_sort([1,100,10,1000]) == sorted([1,100,10,1000])
|
||||||
True
|
True
|
||||||
"""
|
"""
|
||||||
RADIX = 10
|
RADIX = 10
|
||||||
|
@ -29,3 +44,9 @@ def radix_sort(list_of_ints: list[int]) -> list[int]:
|
||||||
# move to next
|
# move to next
|
||||||
placement *= RADIX
|
placement *= RADIX
|
||||||
return list_of_ints
|
return list_of_ints
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import doctest
|
||||||
|
|
||||||
|
doctest.testmod()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user