From 54d67b45639a7cb5f0f387e2a5bf6d8f3af6e40f Mon Sep 17 00:00:00 2001 From: Victor Huang Date: Fri, 19 Aug 2022 20:12:25 -0400 Subject: [PATCH 1/9] 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/9] 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/9] 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/9] 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/9] 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 10b4ef4bb6199b8435f48f304a492959d0358123 Mon Sep 17 00:00:00 2001 From: Alejandro Ruiz Date: Fri, 2 Sep 2022 12:54:12 -0400 Subject: [PATCH 6/9] Add if statement to fix 0 base case --- __pycache__/fib.cpython-310.pyc | Bin 0 -> 633 bytes fib.py | 4 +++- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 __pycache__/fib.cpython-310.pyc diff --git a/__pycache__/fib.cpython-310.pyc b/__pycache__/fib.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..812ab6fd9328a5a3b014c1e9c3dc9b3c2ba4de26 GIT binary patch literal 633 zcmYjN!A=`75Ve;S!m5!_FXiZKBoY%PQZH3iiHaLJ6cAD_k>j20TG`mt;{^rvP^tYH z_@rFRCBMLl@sg|}m8#-*d+P$K<^wlzb=0BZ7=gSjMyDADi%O z?~-*}56|hjnK`SpHo{iR8F-O{1+Rkh=}iGvY zT5(IFz`|8!w%tpNorP4BGL6N!MSez(Cj`GqlSP7U`X-CSr%{;@*}Y@-m)B7eqt7fV zHr`MR+eBSAaa5PD51W;{eA3>X{K)(VdVl#NuMs@TOlh}LrTpP^wFDbbo+)o3Hy|#c zEJ@01OLuruc_l|A%L Date: Fri, 2 Sep 2022 13:00:27 -0400 Subject: [PATCH 7/9] Update fib.py Fix by adding negative base case --- 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) From 0adcd600f2a18ea9008a996232994e527ad39c89 Mon Sep 17 00:00:00 2001 From: Alejandro Ruiz Date: Fri, 2 Sep 2022 13:08:28 -0400 Subject: [PATCH 8/9] . --- fib.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fib.py b/fib.py index 421cfab..a356c74 100644 --- a/fib.py +++ b/fib.py @@ -6,6 +6,8 @@ Negative numbers should return None """ def fibonacci(position): + if (position == 0): + return 0 if(position == 1 or position == 2): return 1 return fibonacci(position - 1) + fibonacci(position - 2) From 626fdc145d1a3b009a11ae7ee73fd83d30235bbb Mon Sep 17 00:00:00 2001 From: Charlyjcmu <60170577+Charlyjcmu@users.noreply.github.com> Date: Fri, 2 Sep 2022 13:10:15 -0400 Subject: [PATCH 9/9] Update fib.py --- fib.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fib.py b/fib.py index 83f26ae..421cfab 100644 --- a/fib.py +++ b/fib.py @@ -6,9 +6,7 @@ Negative numbers should return None """ def fibonacci(position): - if (position == 0): - return 0 - elif(position == 1 or position == 2): + if(position == 1 or position == 2): return 1 return fibonacci(position - 1) + fibonacci(position - 2)