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

Challenge sum of digits #43

Merged
merged 13 commits into from
Jan 12, 2025
Merged

Challenge sum of digits #43

merged 13 commits into from
Jan 12, 2025

Conversation

SEMIRATESFAI
Copy link

@SEMIRATESFAI SEMIRATESFAI commented Jan 5, 2025


name: solution review
about: A template PR for code review with a checklist

Behavior: Write a function that takes a positive integer and returns the sum of its digits.

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
  • The function has correct type annotations
  • The function is not called in the function file

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 the documentation
  • 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

@SEMIRATESFAI SEMIRATESFAI self-assigned this Jan 5, 2025
@likechrisss likechrisss requested review from likechrisss and removed request for likechrisss January 5, 2025 02:58
@MPKenley MPKenley self-requested a review January 5, 2025 20:45
Refined sum_of_digits code and tests: added docstrings, improved test cases, and ensured all linting checks passed.
Refined sum_of_digits code and tests: added docstrings, improved test cases, and ensured all linting checks passed.
Copy link

@MPKenley MPKenley left a comment

Choose a reason for hiding this comment

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

1-input validation: Think about replacing the assert statement used for input validation by an explicite if statement and a valueError. Because assert is not optimize for input validation. It can be disabled in certains environnement

2- Test names: Test names can be more descriptive to reflect the objective of the test. Like test_with_positive_integer instead of test_positive_integer

3- Test method logic: separate logic within test methods into individual methods for clarity and simplicity
This review is just about making the sum_of_digits.py and its test more clear, simple, understandable and meet all the requirements.

solutions/challenge_9/sum_of_digits.py Outdated Show resolved Hide resolved
solutions/tests/challenge_9/test_sum_of_digits.py Outdated Show resolved Hide resolved
solutions/tests/challenge_9/test_sum_of_digits.py Outdated Show resolved Hide resolved
@MPKenley MPKenley added the documentation Improvements or additions to documentation label Jan 11, 2025
adding "with" in the test names provides a bit more context about what inputs are being tested against, making the test scenarios clearer and more descriptive for people to read it
Replace the assert statement with an explicit if statement and raise a ValueError in the sum_of_digits function
Copy link
Author

@SEMIRATESFAI SEMIRATESFAI left a comment

Choose a reason for hiding this comment

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

I have made the requested changes. Could you please review them? If you're satisfied, kindly submit. Thanks so much for your help!

solutions/tests/challenge_9/test_sum_of_digits.py Outdated Show resolved Hide resolved
solutions/challenge_9/sum_of_digits.py Outdated Show resolved Hide resolved
Copy link

@MPKenley MPKenley left a comment

Choose a reason for hiding this comment

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

Good job Semira
I appreciate your hard work and dedication.

But it seems some of your ruff tests don't pass. Check again before merging.

Copy link
Author

@SEMIRATESFAI SEMIRATESFAI left a comment

Choose a reason for hiding this comment

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

Your reviews and suggestions were spot-on! Thanks for your feedback!

solutions/tests/challenge_9/test_sum_of_digits.py Outdated Show resolved Hide resolved
@SEMIRATESFAI SEMIRATESFAI requested a review from MPKenley January 12, 2025 21:49
Copy link

@MPKenley MPKenley left a comment

Choose a reason for hiding this comment

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

Félicitations for the great work Semira

@SEMIRATESFAI
Copy link
Author

Thanks for your review!

@hectordacb hectordacb reopened this Jan 12, 2025
@SEMIRATESFAI SEMIRATESFAI merged commit 05b7158 into main Jan 12, 2025
15 checks passed
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
Projects
Development

Successfully merging this pull request may close these issues.

4 participants