From acb8c32dc2cb1f39c6090cc58464ea33d024e279 Mon Sep 17 00:00:00 2001 From: mvhb Date: Sun, 4 Oct 2020 16:12:38 -0300 Subject: [PATCH 1/8] adding doctest to radix_sort.py file --- sorts/radix_sort.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sorts/radix_sort.py b/sorts/radix_sort.py index 7942462ea10d..381edee41e3f 100644 --- a/sorts/radix_sort.py +++ b/sorts/radix_sort.py @@ -1,8 +1,21 @@ from __future__ import annotations - + +""" +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 +""" def radix_sort(list_of_ints: list[int]) -> list[int]: """ + Examples: + >>> radix_sort([0, 5, 3, 2, 2]) + [0, 2, 2, 3, 5] + radix_sort(range(15)) == sorted(range(15)) True radix_sort(reversed(range(15))) == sorted(range(15)) From bb62a31af44dbf58f2acb884d8835ac1858c0d87 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sun, 4 Oct 2020 19:14:43 +0000 Subject: [PATCH 2/8] fixup! Format Python code with psf/black push --- sorts/radix_sort.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sorts/radix_sort.py b/sorts/radix_sort.py index 381edee41e3f..794b5a2ce1be 100644 --- a/sorts/radix_sort.py +++ b/sorts/radix_sort.py @@ -1,5 +1,5 @@ from __future__ import annotations - + """ This is a pure Python implementation of the quick sort algorithm For doctests run following command: @@ -10,12 +10,13 @@ python radix_sort.py """ + def radix_sort(list_of_ints: list[int]) -> list[int]: """ Examples: >>> radix_sort([0, 5, 3, 2, 2]) [0, 2, 2, 3, 5] - + radix_sort(range(15)) == sorted(range(15)) True radix_sort(reversed(range(15))) == sorted(range(15)) From 2d6d1d1a59c21b9e7bd5d6697820610afa9c6718 Mon Sep 17 00:00:00 2001 From: John Law Date: Thu, 29 Oct 2020 08:41:33 +0800 Subject: [PATCH 3/8] Update radix_sort.py --- sorts/radix_sort.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sorts/radix_sort.py b/sorts/radix_sort.py index 794b5a2ce1be..660c26308684 100644 --- a/sorts/radix_sort.py +++ b/sorts/radix_sort.py @@ -1,5 +1,3 @@ -from __future__ import annotations - """ This is a pure Python implementation of the quick sort algorithm For doctests run following command: @@ -9,6 +7,7 @@ For manual testing run: python radix_sort.py """ +from __future__ import annotations def radix_sort(list_of_ints: list[int]) -> list[int]: From 31ecbd243e62f7514b10a5366d5e0445f09962b6 Mon Sep 17 00:00:00 2001 From: John Law Date: Thu, 29 Oct 2020 08:42:26 +0800 Subject: [PATCH 4/8] Update radix_sort.py --- sorts/radix_sort.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sorts/radix_sort.py b/sorts/radix_sort.py index 660c26308684..378b9aca6b56 100644 --- a/sorts/radix_sort.py +++ b/sorts/radix_sort.py @@ -16,11 +16,11 @@ def radix_sort(list_of_ints: list[int]) -> list[int]: >>> radix_sort([0, 5, 3, 2, 2]) [0, 2, 2, 3, 5] - radix_sort(range(15)) == sorted(range(15)) + >>> radix_sort(range(15)) == sorted(range(15)) True - radix_sort(reversed(range(15))) == sorted(range(15)) + >>> radix_sort(reversed(range(15))) == sorted(range(15)) True - radix_sort([1,100,10,1000]) == sorted([1,100,10,1000]) + >>> radix_sort([1,100,10,1000]) == sorted([1,100,10,1000]) True """ RADIX = 10 @@ -42,3 +42,8 @@ def radix_sort(list_of_ints: list[int]) -> list[int]: # move to next placement *= RADIX return list_of_ints + +if __name__ == "__main__": + import doctest + + doctest.testmod() From 402e4c32cb2c3794a1a35ac7b1072c5a45ca1f14 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Thu, 29 Oct 2020 00:43:35 +0000 Subject: [PATCH 5/8] fixup! Format Python code with psf/black push --- sorts/radix_sort.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sorts/radix_sort.py b/sorts/radix_sort.py index 378b9aca6b56..cf66d362246e 100644 --- a/sorts/radix_sort.py +++ b/sorts/radix_sort.py @@ -43,6 +43,7 @@ def radix_sort(list_of_ints: list[int]) -> list[int]: placement *= RADIX return list_of_ints + if __name__ == "__main__": import doctest From 3072e9ef711e35a5dfdf029f6fd0abf3430672d2 Mon Sep 17 00:00:00 2001 From: John Law Date: Thu, 29 Oct 2020 08:51:49 +0800 Subject: [PATCH 6/8] Update radix_sort.py --- sorts/radix_sort.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sorts/radix_sort.py b/sorts/radix_sort.py index cf66d362246e..ed88b12d96b5 100644 --- a/sorts/radix_sort.py +++ b/sorts/radix_sort.py @@ -8,17 +8,18 @@ python radix_sort.py """ 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]: """ Examples: >>> radix_sort([0, 5, 3, 2, 2]) [0, 2, 2, 3, 5] - >>> radix_sort(range(15)) == sorted(range(15)) + >>> radix_sort(list(range(15))) == sorted(list(range(15))) True - >>> radix_sort(reversed(range(15))) == sorted(range(15)) + >>> radix_sort(reversed(list(range(15)))) == sorted(list(range(15))) True >>> radix_sort([1,100,10,1000]) == sorted([1,100,10,1000]) True From 33b90868a8c2a250fb8eb3f188686050ea56e5c7 Mon Sep 17 00:00:00 2001 From: John Law Date: Thu, 29 Oct 2020 08:56:06 +0800 Subject: [PATCH 7/8] line --- sorts/radix_sort.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sorts/radix_sort.py b/sorts/radix_sort.py index ed88b12d96b5..3715f0f3147d 100644 --- a/sorts/radix_sort.py +++ b/sorts/radix_sort.py @@ -8,6 +8,7 @@ python radix_sort.py """ from __future__ import annotations + from typing import List From e0e733874f6bc5be7289c1444e804a35cdb1ee10 Mon Sep 17 00:00:00 2001 From: John Law Date: Thu, 29 Oct 2020 11:04:07 +0800 Subject: [PATCH 8/8] fix tests --- sorts/radix_sort.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sorts/radix_sort.py b/sorts/radix_sort.py index 3715f0f3147d..57dbbaa79076 100644 --- a/sorts/radix_sort.py +++ b/sorts/radix_sort.py @@ -18,9 +18,9 @@ def radix_sort(list_of_ints: List[int]) -> List[int]: >>> radix_sort([0, 5, 3, 2, 2]) [0, 2, 2, 3, 5] - >>> radix_sort(list(range(15))) == sorted(list(range(15))) + >>> radix_sort(list(range(15))) == sorted(range(15)) True - >>> radix_sort(reversed(list(range(15)))) == sorted(list(range(15))) + >>> radix_sort(list(range(14,-1,-1))) == sorted(range(15)) True >>> radix_sort([1,100,10,1000]) == sorted([1,100,10,1000]) True