Python icon indicating copy to clipboard operation
Python copied to clipboard

Add doctests for sum_of_arithmetic_series function

Open harshgupta257 opened this issue 1 year ago • 0 comments

Describe your change:

I added comprehensive doctests to the sum_of_arithmetic_series function to ensure its reliability and to cover a range of use cases, including:

  1. Basic Functionality:

    • Added tests for typical arithmetic progression (AP) series, verifying the correct sum for series with common examples.
  2. Edge Cases:

    • Included tests for edge cases, such as a series with only one term or a series with zero difference between terms (i.e., where all terms are the same).
  3. Error Handling:

    • Added tests for error cases, where invalid inputs, such as a non-positive number of terms (n <= 0), would raise an error. This verifies that the function properly handles and raises exceptions as expected.

These doctests provide users with clear examples of how the function behaves with different inputs, and they help catch errors during automated testing, improving the function's robustness.

  • [ ] Add an algorithm?
  • [ ] Fix a bug or typo in an existing algorithm?
  • [x] Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • [ ] Documentation change?

Checklist:

  • [x] I have read CONTRIBUTING.md.
  • [x] This pull request is all my own work -- I have not plagiarized.
  • [x] I know that pull requests will not be merged if they fail the automated tests.
  • [x] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • [x] All new Python files are placed inside an existing directory.
  • [x] All filenames are in all lowercase characters with no spaces or dashes.
  • [x] All functions and variable names follow Python naming conventions.
  • [x] All function parameters and return values are annotated with Python type hints.
  • [x] All functions have doctests that pass the automated testing.
  • [ ] All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • [x] If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #9943".

harshgupta257 avatar Oct 25 '24 19:10 harshgupta257