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: add two integers challenge #54

Merged
merged 14 commits into from
Jan 13, 2025

Conversation

aoyeoku
Copy link

@aoyeoku aoyeoku commented Jan 9, 2025

Add Two Integers Challenge

Challenge Description

Given two integers num1 and num2, return the sum of the two integers.

Examples

  1. Input: num1 = 12, num2 = 5
    Output: 17
    Explanation: num1 is 12, num2 is 5, and their sum is 12 + 5 = 17, so 17 is returned

  2. Input: num1 = -10, num2 = 4
    Output: -6
    Explanation: num1 + num2 = -6, so -6 is returned.

Constraints

  • -100 <= num1, num2 <= 100

Helpful Resources

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

@aoyeoku aoyeoku added the challenge Please name your branch based on the challenge it addresses. label Jan 9, 2025
@aoyeoku aoyeoku self-assigned this Jan 9, 2025
@aoyeoku aoyeoku linked an issue Jan 9, 2025 that may be closed by this pull request
@doctorbanu doctorbanu changed the title 34 challenge add two integers challenge challenge: add two integers challenge Jan 9, 2025
@doctorbanu
Copy link

Hi, Abbiihjah 💫 Can you please edit your description? We should customize the name and about parts, and add your function's behavior. Thank you in advance 😄

@doctorbanu
Copy link

doctorbanu commented Jan 9, 2025

Hi, Abbiihjah 💫 Can you please edit your description? We should customize the name and about parts, and add your function's behavior. Thank you in advance 😄

Here is a example for you. These are from my factorial challenge:

name: Factorial Calculation
about: A function that calculates the factorial of a non-negative integer using recursion
Behavior
This function calculates the factorial of a non-negative integer n using recursion. The factorial of a number is the product of all positive integers less than or equal to that number.

Input: The function accepts a single integer n, where n must be a non-negative integer (i.e., n >= 0).
Output: The function returns the factorial of n, which is the product of all integers from 1 to n. If n is 0, the factorial is defined as 1.
Error Handling: If the input is not an integer or if n is negative, the function raises an AssertionError.
The factorial is calculated recursively, where the base case is when n = 0, returning 1, and the recursive case multiplies n with the factorial of n - 1.

@GeehanAli GeehanAli self-requested a review January 10, 2025 14:26
@misik-eng misik-eng requested review from misik-eng and removed request for misik-eng January 11, 2025 16:52
@aoyeoku aoyeoku requested a review from doctorbanu January 11, 2025 18:42
Copy link

@GeehanAli GeehanAli left a comment

Choose a reason for hiding this comment

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

The function and tests meet the checklist requirements.
The code passes the formatting checks, Ruff linting checks and has no Pylint errors.
The work is well-organized, clearly written, and demonstrates excellent attention to detail.
Please review my comments and make the changes so I can approve the review.
Great work!

@misik-eng misik-eng removed the request for review from doctorbanu January 12, 2025 05:47
Copy link

@GeehanAli GeehanAli left a comment

Choose a reason for hiding this comment

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

All requested changes have been made, and everything looks clear and well-executed. Great work!
I'll proceed to approve the review and close the PR.

@GeehanAli
Copy link

All requested changes have been made, and everything looks clear and well-executed. Great work!
I'll proceed to approve the review and close the PR.

@GeehanAli GeehanAli closed this Jan 13, 2025
@misik-eng misik-eng reopened this Jan 13, 2025
@misik-eng misik-eng merged commit 6946718 into main Jan 13, 2025
15 checks passed
@misik-eng misik-eng deleted the 34-challenge-add-two-integers-challenge branch January 13, 2025 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
challenge Please name your branch based on the challenge it addresses.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

challenge: Add Two Integers
4 participants