Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move zeroes (Resolves #68) #96

Merged
merged 12 commits into from
Jan 13, 2025
Merged

Move zeroes (Resolves #68) #96

merged 12 commits into from
Jan 13, 2025

Conversation

mudassra-taskeen
Copy link

@mudassra-taskeen mudassra-taskeen commented Jan 12, 2025


Name: Review solution of move_zeroes
About: A template PR for code review of move_zeroes with a checklist

A function that moves all the zeros in a given integer array to the end, while keeping the relative order of the non-zero elements unchanged. The operation must be performed in-place, without using additional space for a copy of the array.

Behavior

Input:

  • An integer array (nums), which can contain:

    • Non-negative integers, including zeroes
    • The array length can vary

Output:

  • A modified array where:

    • All zeroes are moved to the end, while maintaining the relative order of the non-zero elements
    • The operation is done in-place without creating a copy of the array

Files

  • The file name describes the function's behavior
  • There is a module docstring in the function file
  • The test file's name matches the function file name -
    /tests/test_file_name.py
  • There is a module docstring in the tests file

Unit Tests

  • The test class has a helpful name in PascalCase
  • The test class has a docstring
  • Every unit test has
    • A helpful name
    • A clear docstring
    • Only one assertion
    • There is no logic in the unit test
  • All tests pass
  • There are tests for defensive assertions
  • There are tests for boundary cases

Function Docstring

  • The function's behavior is described
  • The function's arguments are described:
    • Type
    • Purpose
    • Other assumptions (eg. if it's a number, what's the expected range?)
  • The return value is described
    • Type
    • Other assumptions are documented
  • The defensive assertions are documented using Raises:
    • Each assumption about an argument is checked with an assertion
    • Each assertion checks for only one assumption about the argument
  • Include 3 or more (passing!) doctests

The Function

  • The function's name describes it's behavior
  • The function's name matches the file name
    • It's ok to have extra helper functions if necessary, like with mergesort
  • The function has correct type annotations
  • The function is not called at the top level of the function file
    • Recursive solutions can call the function from inside the function body

Strategy

Do's

  • Variable names help to understand the strategy
  • Any comments are clear and describe the strategy
  • Lines of code are spaced to help show different stages of the strategy

Don'ts

  • The function's strategy is not described in any docstrings or tests
  • Comments explain the strategy, not the implementation
  • The function does not have more comments than code
    • If it does, consider finding a new strategy or a simpler implementation

Implementation

  • The code passes the formatting checks
  • The code passes all Ruff linting checks
  • The code has no (reasonable) Pylint errors
    • In code review, you can decide when fixing a Pylint error is helpful and
      when it's too restricting.
  • Variables are named with snake_case
  • Variable names are clear and helpful
  • The code follows the strategy as simply as possible
  • The implementation is as simple as possible given the strategy
  • There are no commented lines of code
  • There are no print statements anywhere
  • The code includes defensive assertions
  • Defensive assertions include as little logic as possible

@mudassra-taskeen mudassra-taskeen added documentation Improvements or additions to documentation require-review Pull requests that needs to be reviewd. labels Jan 12, 2025
@mudassra-taskeen mudassra-taskeen self-assigned this Jan 12, 2025
@mudassra-taskeen mudassra-taskeen linked an issue Jan 12, 2025 that may be closed by this pull request
@jola-ds jola-ds self-requested a review January 12, 2025 04:54
@jola-ds
Copy link

jola-ds commented Jan 12, 2025

Hello, Mudassra. Good job, I will review your code.
It looks like py formmatting failed. It’s a problam with your second solution find_single _numbers.py. Could you resolve this? It also looks like you have 4 files in this PR. Maybe there’s a mix up with your branches? You also have both of your solutions in the same branch.

@mudassra-taskeen
Copy link
Author

Hey Jola, Thanks for letting me know. I have removed those additional files from move_zeroes branch. Now you can review my code.

Copy link

@jola-ds jola-ds left a comment

Choose a reason for hiding this comment

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

Well done, teammate!

  • The test suite is great, I would suggest adding more specific descriptions for some tests to make them even clearer.

  • The function is well implemented as well. However, I'd like to have a conversation about the return value to make sure we're on the same page about the expected behaviour.

  • It also looks like the function docstring could use an additional doctest, as the checklist specifies that we should have 3 or more passing doctests.

  • Lastly, I think the assertion error message needs an update for clarity.

I understood your points and implemented them in my files. You can see those modifications, and let me know if I should alter anything else.

@fatima-malik99 fatima-malik99 self-requested a review January 13, 2025 04:53
Copy link

@fatima-malik99 fatima-malik99 left a comment

Choose a reason for hiding this comment

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

Hey, I've seen your code. Good job Mudassara. You did a great job. Going to merge it

@jola-ds jola-ds merged commit 4e2a68a into main Jan 13, 2025
10 checks passed
@jola-ds jola-ds deleted the move_zeroes branch January 13, 2025 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation require-review Pull requests that needs to be reviewd.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move Zeroes to End of Array
3 participants