Skip to content

feat: add fibonacci function with edge case handling - #14

Open
fletc89-cyber wants to merge 1 commit into
gougousongsong:mainfrom
fletc89-cyber:fix/fibonacci-bounty-976
Open

feat: add fibonacci function with edge case handling#14
fletc89-cyber wants to merge 1 commit into
gougousongsong:mainfrom
fletc89-cyber:fix/fibonacci-bounty-976

Conversation

@fletc89-cyber

Copy link
Copy Markdown

Summary

Implements fibonacci(n) in src/math_utils.py with edge-case handling, addressing issue #1 (bounty-plaza#976).

Changes

  • src/math_utils.py: Added fibonacci(n) function

    • Returns the nth Fibonacci number (0-indexed)
    • fibonacci(0) -> 0, fibonacci(1) -> 1, fibonacci(5) -> 5, fibonacci(10) -> 55
    • Raises ValueError("n must be non-negative") for n < 0
    • Iterative implementation (O(n) time, O(1) space)
  • tests/test_math_utils.py: Added comprehensive tests

    • Base cases (0, 1)
    • Normal cases (2, 3, 5, 10)
    • Negative edge case (raises ValueError with correct message)
    • Large input (fibonacci(20) == 6765)

Test Results

All 8 tests pass:

tests/test_math_utils.py::test_add PASSED
tests/test_math_utils.py::test_multiply PASSED
tests/test_math_utils.py::test_fibonacci_base_cases PASSED
tests/test_math_utils.py::test_fibonacci_normal_cases PASSED
tests/test_math_utils.py::test_fibonacci_negative_edge_case PASSED
tests/test_math_utils.py::test_fibonacci_large_input PASSED
tests/test_string_utils.py::test_reverse_string PASSED
tests/test_string_utils.py::test_to_uppercase PASSED

Bounty Reference

Closes #1


This PR was created by an AI agent (OpenHands) on behalf of fletc89-cyber.

Add fibonacci(n) to src/math_utils.py:
- Returns nth Fibonacci number (0-indexed)
- fibonacci(0)=0, fibonacci(1)=1, fibonacci(5)=5, fibonacci(10)=55
- Raises ValueError('n must be non-negative') for n<0

Add comprehensive tests covering base cases, normal cases,
negative edge case, and large input. All 8 tests pass.

Closes gougousongsong#1

Co-authored-by: openhands <openhands@all-hands.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add fibonacci function with edge case handling

2 participants