Skip to content
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

Fixed error of position=-1 #34

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
35 changes: 35 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python application

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with pytest
run: |
pytest
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# github-recitation
# github-recitation-with-test
This repository is the base repository that students will fork and use for the git / github recitation.

It contains a single python file `fib.py`, which is a toy example that students will modify, write pull requests as a pair during the recitation.
It contains the python files `fib.py` and `test_fib.py`. `fib.py` is the a toy example that students will modify, write pull requests as a pair during the recitation. `test_fib.py` contains the pytest test cases.
17 changes: 5 additions & 12 deletions fib.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@
Negative numbers should return None
"""
def fibonacci(position):
if(position == 1 or position == 2):
if(position < 0):
return None
if(position == 0):
return 0
if (position == 1):
return 1
return fibonacci(position - 1) + fibonacci(position - 2)


# Test cases
print("The 1st Fibonacci number: ", fibonacci(1))
print("The 21st Fibonacci number: ", fibonacci(21))

assert(fibonacci(0) == 0)
print("The 0th Fibonacci number: ", fibonacci(0)) # should return 0

assert(fibonacci(-1) == None)
print("The -1st Fibonacci number: ", fibonacci(-1)) # should return None

print("Code ran successfully!")


15 changes: 15 additions & 0 deletions test_fib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from fib import fibonacci

# Test cases for the fibonacci function

def test_zeroth_fibonacci():
assert(fibonacci(0) == 0)

def test_first_fibonacci():
assert(fibonacci(1) == 1)

def test_21st_fibonacci():
assert(fibonacci(21) == 10946)

def test_negative_fibonacci():
assert(fibonacci(-1) == None)