-
-
Notifications
You must be signed in to change notification settings - Fork 47k
Adding doctests to improve Test Coverage for dynamic_programming/fibonacci.py #12831
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
base: master
Are you sure you want to change the base?
Adding doctests to improve Test Coverage for dynamic_programming/fibonacci.py #12831
Conversation
There was a problem hiding this comment.
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.
Co-authored-by: Bertrand Awenze <156874668+bertrand-awz@users.noreply.github.com>
Co-authored-by: Bertrand Awenze <156874668+bertrand-awz@users.noreply.github.com>
Thanks a lot for pointing it out , my first PR's so don't really know what ruff's trying to say. Appreciate it! |
... | ||
ValueError: Index must be non-negative, got -1 | ||
""" | ||
if n < 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is repeated (98–100), I recommend creating a method that will be called to perform it.
# Extend sequence if needed | ||
if n >= len(self.sequence): | ||
difference = n - len(self.sequence) + 1 | ||
for _ in range(difference): |
There was a problem hiding this comment.
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.
else: | ||
print(f"First {index} Fibonacci numbers: {result}") | ||
if index > 0: | ||
print(f"The {index}th Fibonacci number is: {result[-1]}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Describe your change:
This PR significantly improves the Fibonacci dynamic programming implementation with:
Enhanced Documentation:
Comprehensive Doctests:
Code Improvements:
get_nth()
method for single number retrievalreset()
method for clearing memoized sequenceTest Coverage:
All doctests have been independently verified for correctness and pass when run locally.
Contributes to #9943
Checklist: