Skip to content

Insert sort - #21

Open
vbenavente wants to merge 7 commits into
masterfrom
insert_sort
Open

Insert sort#21
vbenavente wants to merge 7 commits into
masterfrom
insert_sort

Conversation

@vbenavente

Copy link
Copy Markdown
Owner

No description provided.

Comment thread src/insert_sort.py Outdated
import timeit


best_case = [x for x in range(0, 1000)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you declare constants in the global scope, follow Python convention by making the variable names ALL_UPPER_CASE

Comment thread src/insert_sort.py Outdated
"""Sort a list by inserting values in order after comparing each value."""
if len(l) <= 1:
return
else:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This else statement is unnecessary, since the if conditional will return out of the function when True. Whenever possible, as in this case, it is preferable to avoid indented blocks so your code looks a little cleaner.

Comment thread src/insert_sort.py Outdated
if len(l) <= 1:
return
else:
for idx in range(1, len(l)):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good insertion sort implementation! Only improvement I would want to see is to make a more meaningful/readable variable name than just "l" for the input list.

Comment thread src/insert_sort.py
l[spot] = cur


if __name__ == '__main__':

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's weird is that this looks correct and your best case/ worse case look like they are what they should be, but I'm getting the same time performance for both cases. Are you getting the same?

Comment thread src/test_insert_sort.py


TEST_LIST = [
[], [8]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good edge cases. You should also make sure to include cases with duplicate values. Not as important for this assignment, more so for future sorts.

Comment thread src/test_insert_sort.py Outdated

def test_best_case():
from insert_sort import best_case
assert type(best_case) is list

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are you actually testing for here?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making sure my best case and worst case variables are actually lists, I've changed it to isinstance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants