Skip to content

Adding doctests to improve Test Coverage for dynamic_programming/fibonacci.py#12831

Closed
Achintya47 wants to merge 6 commits into
TheAlgorithms:masterfrom
Achintya47:Improve-test-coverage-fibonacci,py
Closed

Adding doctests to improve Test Coverage for dynamic_programming/fibonacci.py#12831
Achintya47 wants to merge 6 commits into
TheAlgorithms:masterfrom
Achintya47:Improve-test-coverage-fibonacci,py

Conversation

@Achintya47

Copy link
Copy Markdown

Describe your change:

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

This PR significantly improves the Fibonacci dynamic programming implementation with:

Enhanced Documentation:

  • Added comprehensive docstrings for class and all methods
  • Included algorithm explanation with time/space complexity analysis
  • Added Wikipedia reference for the Fibonacci sequence
  • Improved inline comments and code structure

Comprehensive Doctests:

  • Basic functionality tests for various sequence lengths (0, 1, 2, 5, 10, 15, 20)
  • Edge case coverage (empty sequence, single element, negative indices)
  • Error handling verification with proper exception messages
  • Large number testing for performance validation
  • Memoization verification to ensure efficiency
  • Sequence correctness validation using mathematical properties

Code Improvements:

  • Added input validation with descriptive error messages
  • Implemented get_nth() method for single number retrieval
  • Added reset() method for clearing memoized sequence
  • Enhanced CLI with additional commands (help, reset)
  • Improved error handling and user experience
  • Better variable naming and code organization
  • Fixed potential issues with edge cases

Test Coverage:

  • Tests for all public methods
  • Comprehensive edge case handling
  • Error condition verification
  • Performance and correctness validation
  • Independent verification of all test cases

All doctests have been independently verified for correctness and pass when run locally.

Contributes to #9943

Checklist:

@algorithms-keeper algorithms-keeper Bot added awaiting reviews This PR is ready to be reviewed tests are failing Do not merge until tests pass labels Jul 6, 2025

@bertrand-awz bertrand-awz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested changes to pass the checking ruff.

Comment thread dynamic_programming/fibonacci.py Outdated
Comment thread dynamic_programming/fibonacci.py Outdated
Achintya47 and others added 2 commits July 9, 2025 02:29
Co-authored-by: Bertrand Awenze <156874668+bertrand-awz@users.noreply.github.com>
Co-authored-by: Bertrand Awenze <156874668+bertrand-awz@users.noreply.github.com>
@algorithms-keeper algorithms-keeper Bot removed the tests are failing Do not merge until tests pass label Jul 8, 2025
@Achintya47

Copy link
Copy Markdown
Author

Suggested changes to pass the checking ruff.

Thanks a lot for pointing it out , my first PR's so don't really know what ruff's trying to say. Appreciate it!

@algorithms-keeper algorithms-keeper Bot added tests are failing Do not merge until tests pass and removed tests are failing Do not merge until tests pass labels Jul 8, 2025
@Achintya47 Achintya47 requested a review from bertrand-awz July 10, 2025 20:39
Comment thread dynamic_programming/fibonacci.py
# Extend sequence if needed
if n >= len(self.sequence):
difference = n - len(self.sequence) + 1
for _ in range(difference):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This generation is repeated (lines 107–108), I recommend creating a method to generate the sequence.

Comment thread dynamic_programming/fibonacci.py Outdated
Achintya47 and others added 2 commits July 14, 2025 19:08
Co-authored-by: Bertrand Awenze <156874668+bertrand-awz@users.noreply.github.com>
@algorithms-keeper algorithms-keeper Bot added the tests are failing Do not merge until tests pass label Jul 14, 2025
@cclauss

cclauss commented Oct 14, 2025

Copy link
Copy Markdown
Member

Closing tests_are_failing PRs to prepare for Hacktoberfest

@cclauss cclauss closed this Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed tests are failing Do not merge until tests pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants