Skip to content

Instantly share code, notes, and snippets.

@neosergio
Last active August 19, 2021 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neosergio/dfda06a377c28028d1f9477662471c53 to your computer and use it in GitHub Desktop.
Save neosergio/dfda06a377c28028d1f9477662471c53 to your computer and use it in GitHub Desktop.
Python unit testing exercise

Sum of N numbers

Write a function that can sum up numbers:

  • It should receive a sequence of n numbers.
  • If no argument is provided, return sum of numbers 1..100.
  • Look closely to the type of the function's default argument ...

Proposed solution

def sum_numbers(numbers=None):
    if numbers==None:
        return sum(range(1, 101))
    return sum(numbers)

Unit testing

Write two test at least for:

  • Check output with default args
  • Check output with different values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment