From 54d67b45639a7cb5f0f387e2a5bf6d8f3af6e40f Mon Sep 17 00:00:00 2001 From: Victor Huang Date: Fri, 19 Aug 2022 20:12:25 -0400 Subject: [PATCH 1/7] separate into separate test file --- fib.py | 11 ----------- test_fib.py | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 test_fib.py diff --git a/fib.py b/fib.py index 50722c2..421cfab 100644 --- a/fib.py +++ b/fib.py @@ -11,16 +11,5 @@ def fibonacci(position): 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..528516d --- /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) == 6765) + +def test_negative_fibonacci(): + assert(fibonacci(-1) == None) From 1a15eca1057e85be6b544a9784203bb2a3422fef Mon Sep 17 00:00:00 2001 From: Victor Huang Date: Fri, 19 Aug 2022 20:13:42 -0400 Subject: [PATCH 2/7] Create python-app.yml --- .github/workflows/python-app.yml | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..a783943 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,33 @@ +# 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" ] + +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 From 34385c62e127261e914d6b4909a71061bd7fbb0f Mon Sep 17 00:00:00 2001 From: Victor Huang Date: Fri, 19 Aug 2022 20:32:07 -0400 Subject: [PATCH 3/7] Add workflow dispatch --- .github/workflows/python-app.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index a783943..1ae5c03 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -8,6 +8,8 @@ on: branches: [ "main" ] pull_request: branches: [ "main" ] + workflow_dispatch: + branches: [ "main" ] permissions: contents: read From 79d1f7ac1f032e32ef1f22a9b6fef3dbb65c248e Mon Sep 17 00:00:00 2001 From: Victor Huang Date: Fri, 19 Aug 2022 20:46:19 -0400 Subject: [PATCH 4/7] Update 21st fib to correct value --- test_fib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_fib.py b/test_fib.py index 528516d..4754405 100644 --- a/test_fib.py +++ b/test_fib.py @@ -9,7 +9,7 @@ def test_first_fibonacci(): assert(fibonacci(1) == 1) def test_21st_fibonacci(): - assert(fibonacci(21) == 6765) + assert(fibonacci(21) == 10946) def test_negative_fibonacci(): assert(fibonacci(-1) == None) From 3f1ddb0e10594acab386f2b30cdfa5dc67c833ae Mon Sep 17 00:00:00 2001 From: Victor Huang Date: Fri, 19 Aug 2022 20:50:43 -0400 Subject: [PATCH 5/7] Update readme to include test_fib --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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. From 74471eb19fb0ed8c91a6bbb09d6f2ecf3723ef57 Mon Sep 17 00:00:00 2001 From: Ria Jotsinghani Date: Wed, 31 Aug 2022 14:00:03 -0400 Subject: [PATCH 6/7] Fixed failing Fibonacci(0) test case --- fib.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fib.py b/fib.py index 421cfab..a6a954c 100644 --- a/fib.py +++ b/fib.py @@ -6,7 +6,9 @@ Negative numbers should return None """ def fibonacci(position): - if(position == 1 or position == 2): + if(position == 0): + return 0 + if (position == 1): return 1 return fibonacci(position - 1) + fibonacci(position - 2) From 75b60b8f39726587f37f651c3536a407b4d37879 Mon Sep 17 00:00:00 2001 From: lzx0406 <92296865+lzx0406@users.noreply.github.com> Date: Wed, 31 Aug 2022 14:00:43 -0400 Subject: [PATCH 7/7] Fix fib 0 error --- fib.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fib.py b/fib.py index 421cfab..4d41752 100644 --- a/fib.py +++ b/fib.py @@ -6,6 +6,8 @@ Negative numbers should return None """ def fibonacci(position): + if(position < 0): + return None if(position == 1 or position == 2): return 1 return fibonacci(position - 1) + fibonacci(position - 2)