diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..1ae5c03 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -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 diff --git a/README.md b/README.md index c851af8..0b2484f 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/__pycache__/fib.cpython-310.pyc b/__pycache__/fib.cpython-310.pyc new file mode 100644 index 0000000..812ab6f Binary files /dev/null and b/__pycache__/fib.cpython-310.pyc differ diff --git a/fib.py b/fib.py index 50722c2..f2dab25 100644 --- a/fib.py +++ b/fib.py @@ -6,21 +6,14 @@ Negative numbers should return None """ def fibonacci(position): + if (position == 0): + return 0 + if(position < 0): + return None if(position == 1 or position == 2): 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!") diff --git a/test_fib.py b/test_fib.py new file mode 100644 index 0000000..4754405 --- /dev/null +++ b/test_fib.py @@ -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)