BST236 Coding Blog

Introduction

This repository contains a Python implementation of the Fibonacci sequence calculator with intentionally introduced formatting issues and code style problems. The main purpose of this homework is to help you:

Installation

1. From the terminal, clone the repository:

git clone <your-repo-url>
cd <repo-name>

2. Install dependencies:

pip install -r requirements.txt

Usage

The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1. The function fibonacci(n) in this repository calculates the nth number in the Fibonacci sequence.

You can get the nth number in the Fibonacci sequence by the terminal command python fibonacci.py <n>. For example, running the following command to get the 4th number in the Fibonacci sequence:

python3 fibonacci.py 4
3

Report

I ran the pytest command and got the following results:

collected 3 items

FAILED test_fibonacci.py::test_fibonacci_base_cases - assert 1 == 0
FAILED test_fibonacci.py::test_fibonacci_positive_numbers - assert 4 == 3
FAILED test_fibonacci.py::test_fibonacci_negative_input - Failed: DID NOT RAISE <class 'ValueError'>

The failures were caused by incorrect implementation of the fibonacci function (incorrect update order of variables) and lack of boundary case handling.

Fixes Implemented:

  1. Added input validation to raise a ValueError for negative inputs.
  2. Explicitly handled the base cases n = 0 and n = 1.
  3. Corrected the initialization and update logic of variables a and b.

After these fixes, all tests passed successfully.

Contributions

Yuan Tian: Completing the homework