Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Create intro_sort.py #3877
Create intro_sort.py #3877
Conversation
|
Please add doctests and typehints |
black intro_sort.py
|
@mateuszz0000 I added doctests and typehints. Can you check my code? |
|
Could you please add tests for different examples.
|
|
@NumberPiOso added more test |
|
@mateuszz0000 @shellhub Can you review my code? |
|
@cclauss excuse me sir, can you reivew this code? |
|
All functions should have tests. Maybe create one or more global test_arrays and test all functions against those common datasets. |
added doctest, modified code
| def insertion_sort(array: list, start: int, end: int) -> list: | ||
| """ | ||
| >>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] | ||
| >>> insertion_sort(array, 0, len(array)) | ||
| [1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56, 79] | ||
| """ | ||
| for i in range(start, end): |
cclauss
Nov 24, 2020
Member
Let's also enable the caller to simply do insertion_sort(my_array) and get back the expected result.
| def insertion_sort(array: list, start: int, end: int) -> list: | |
| """ | |
| >>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] | |
| >>> insertion_sort(array, 0, len(array)) | |
| [1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56, 79] | |
| """ | |
| for i in range(start, end): | |
| def insertion_sort(array: list, start: int = 0, end: int = 0) -> list: | |
| """ | |
| >>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] | |
| >>> insertion_sort(array, 0, len(array)) | |
| [1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56, 79] | |
| """ | |
| end = end or len(array) | |
| for i in range(start, end): |
cclauss
Nov 24, 2020
•
Member
What happens if:
- start is a negative number
- if end is larger than len(array)
- start > end?
|
This is looking really cool.. One last thing to try before we land it. Thanks for your hard work! |
|
Thanks much for your hard work here... I am going to accept and merge this but I still have reservations about What happens if:
If you wanted to address these issues in a future pull request then I would be happy to review. |
Describe your change:
added introsort algorithm implementation to sorts
Checklist:
Fixes: #{$ISSUE_NO}.