diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..1c18e923 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,32 @@ +name: CI workflow + +# We can specify which Github events will trigger a CI build +on: + push: + branches: [main, develop] + pull_request: + branches: + - main +# now define a single job 'build' (but could define more, can be anything other than build) +jobs: + build: + # we can also specify the OS to run tests on + runs-on: ubuntu-latest + steps: + # Next we need to checkout out repository, and set up Python + # A 'name' is just an optional label shown in the log - helpful to clarify progress - and can be anything + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Python 3.9 + uses: actions/setup-python@v3 + with: + python-version: "3.9" + - name: Install Python Dependencies + run: | + python3 -m pip install --upgrade pip + pip3 install -r requirements.txt + + - name: Test with Pytest + run: | + python -m pytest --cov=inflammation.models tests/test_models.py diff --git a/tests/test_models.py b/tests/test_models.py index 292d00c4..ca7fb9b3 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -3,6 +3,7 @@ import numpy as np import numpy.testing as npt import os +import pytest def test_daily_mean_zeros(): @@ -37,3 +38,76 @@ def test_load_from_json(tmpdir): temp_json_file.write('[{"observations":[1, 2, 3]},{"observations":[4, 5, 6]}]') result = load_json(example_path) npt.assert_array_equal(result, [[1, 2, 3], [4, 5, 6]]) + + +def test_daily_max(): + from inflammation.models import daily_max + + test_input = np.array([[4,2,5], + [1,6,2], + [4,1,9]]) + + test_result = np.array([4,6,9]) + + npt.assert_array_equal(daily_max(test_input), test_result) + + +def test_daily_min(): + from inflammation.models import daily_min + test_input = np.array([[4,-2,5], + [1,-6,2], + [-4,-1,9]]) + + test_result = np.array([-4,-6,2]) + + + npt.assert_array_equal(daily_min(test_input), test_result) + + +def test_daily_min_string(): + from inflammation.models import daily_min + with pytest.raises(TypeError): + expected_error = test_daily_min([['Hello', 'there'], ['General', 'Kenobi']]) + + +@pytest.mark.parametrize( + "test, expected", + [ + ([[0,0], [0,0], [0,0]], [0,0]), + ([[1,2], [3,4], [5,6]], [3,4]) + ] +) +def test_daily_mean(test, expected): + """Test mean function works for array of zeroes and positive integers.""" + from inflammation.models import daily_mean + npt.assert_array_equal(daily_mean(np.array(test)), np.array(expected)) + + + +@pytest.mark.parametrize( + "test, expected", + [ + ([ [0, 0, 0], [0, 0, 0], [0, 0, 0] ], [0, 0, 0]), + ([ [4, 2, 5], [1, 6, 2], [4, 1, 9] ], [4, 6, 9]), + ([ [4, -2, 5], [1, -6, 2], [-4, -1, 9] ], [4, -1, 9]), + ] +) +def test_daily_max(test, expected): + from inflammation.models import daily_max + npt.assert_array_equal(daily_max(np.array(test)), np.array(expected)) + + + +@pytest.mark.parametrize( + "test, expected", + [ + ([ [0, 0, 0], [0, 0, 0], [0, 0, 0] ], [0, 0, 0]), + ([ [4, 2, 5], [1, 6, 2], [4, 1, 9] ], [1, 1, 2]), + ([ [4, -2, 5], [1, -6, 2], [-4, -1, 9] ], [-4, -6, 2]) + + ] +) +def test_daily_min(test, expected): + from inflammation.models import daily_min + + npt.assert_array_equal(daily_min(np.array(test)), np.array(expected)) \ No newline at end of file