diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..207b00ca --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,35 @@ +name: CI workflow + +# We can specify which Github events will trigger a CI build +on: + push: +# 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: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + - windows-latest + - macos-latest + python-version: ["3.12", "3.10"] + 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: ${{ matrix.python-version }} + - 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/.gitignore b/.gitignore index 0e0aa744..6b1841bd 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ *.pyc *.egg-info .pytest_cache +py_venv/ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..8e2977d3 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,16 @@ +contourpy==1.3.0 +coverage==7.6.1 +cycler==0.12.1 +fonttools==4.54.1 +iniconfig==2.0.0 +kiwisolver==1.4.7 +matplotlib==3.9.2 +numpy==2.1.2 +packaging==24.1 +pillow==10.4.0 +pluggy==1.5.0 +pyparsing==3.1.4 +pytest==8.3.3 +pytest-cov==5.0.0 +python-dateutil==2.9.0.post0 +six==1.16.0 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