From 3871e8def789da9aa81faf4de4f4bd33a46f26cb Mon Sep 17 00:00:00 2001 From: Shaheen G Date: Wed, 8 Dec 2021 12:37:23 -0500 Subject: [PATCH 1/6] add unit tests --- test_mean.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test_mean.py diff --git a/test_mean.py b/test_mean.py new file mode 100644 index 0000000..27ad1fb --- /dev/null +++ b/test_mean.py @@ -0,0 +1,34 @@ +from mean import * + +def test_ints(): + num_list = [1,2,3,4,5] + obs = mean(num_list) + exp = 3 + assert obs == exp + +def test_zero(): + num_list=[0,2,4,6] + obs = mean(num_list) + exp = 3 + assert obs == exp + +def test_double(): + # This one will fail in Python 2 + num_list=[1,2,3,4] + obs = mean(num_list) + exp = 2.5 + assert obs == exp + +def test_long(): + big = 100000000 + obs = mean(range(1,big)) + exp = big/2.0 + assert obs == exp + +def test_complex(): + # given that complex numbers are an unordered field + # the arithmetic mean of complex numbers is meaningless + num_list = [2 + 3j, 3 + 4j, -32 - 2j] + obs = mean(num_list) + exp = NotImplemented + assert obs == exp From 0634ddd2844c8a0be0f4f6db414ebd1231d47de1 Mon Sep 17 00:00:00 2001 From: Shaheen G Date: Wed, 8 Dec 2021 13:01:29 -0500 Subject: [PATCH 2/6] adding comments --- test_mean.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test_mean.py b/test_mean.py index 27ad1fb..2ded775 100644 --- a/test_mean.py +++ b/test_mean.py @@ -1,11 +1,13 @@ from mean import * +# tests the mean of integers def test_ints(): num_list = [1,2,3,4,5] obs = mean(num_list) exp = 3 assert obs == exp +# tests the zeros! def test_zero(): num_list=[0,2,4,6] obs = mean(num_list) From f2b7b28ab5def2b7f14e8951304f7c4a4dd532a9 Mon Sep 17 00:00:00 2001 From: Shaheen G Date: Wed, 8 Dec 2021 13:22:18 -0500 Subject: [PATCH 3/6] added GitHub actions --- .github/workflows/github-actions.yml | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/github-actions.yml diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml new file mode 100644 index 0000000..990a31b --- /dev/null +++ b/.github/workflows/github-actions.yml @@ -0,0 +1,29 @@ +# copy this file to .github/workflows/github-actions.yml in this repository +name: learn-github-actions +on: [push] +jobs: + test-my-python-code: + # select the os-image these jobs should run on + runs-on: ubuntu-latest + + # define the Python versions that should be used + strategy: + matrix: + python-version: [2.7, 3.8] + + steps: + # step to check out the repository + - uses: actions/checkout@v2 + + # step to create the Python environment + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + # step to install the dependencies + - name: Install dependencies + run: "pip install -r requirements.txt" + + # step to run tests + - run: pytest -v From 8aff598b3442fa5d755c44562226587a2dea0861 Mon Sep 17 00:00:00 2001 From: Shaheen G Date: Wed, 8 Dec 2021 13:27:38 -0500 Subject: [PATCH 4/6] add python requirments --- .github/workflows/requirements.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .github/workflows/requirements.txt diff --git a/.github/workflows/requirements.txt b/.github/workflows/requirements.txt new file mode 100644 index 0000000..bfe3f43 --- /dev/null +++ b/.github/workflows/requirements.txt @@ -0,0 +1,3 @@ +numpy>=1.0 +pytest + From 56377e559af3dd2f7315de97ec17a28f3ecce332 Mon Sep 17 00:00:00 2001 From: Shaheen G Date: Wed, 8 Dec 2021 13:29:15 -0500 Subject: [PATCH 5/6] proper location of requirment.txt file --- .github/workflows/requirements.txt => requirements.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/requirements.txt => requirements.txt (100%) diff --git a/.github/workflows/requirements.txt b/requirements.txt similarity index 100% rename from .github/workflows/requirements.txt rename to requirements.txt From 944aad599b0e76e75aa741defcfbb05fd771fe0a Mon Sep 17 00:00:00 2001 From: Shaheen G Date: Wed, 8 Dec 2021 13:46:48 -0500 Subject: [PATCH 6/6] fixed python v2 test fail --- test_mean.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test_mean.py b/test_mean.py index 2ded775..ce49c67 100644 --- a/test_mean.py +++ b/test_mean.py @@ -16,7 +16,8 @@ def test_zero(): def test_double(): # This one will fail in Python 2 - num_list=[1,2,3,4] + # This is now fixed + num_list=[1.0,2.0,3.0,4.0] obs = mean(num_list) exp = 2.5 assert obs == exp