Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CI

# We can specify which Github events will trigger a CI build
on: push

# now define a single job 'build' (but could define more)
jobs:

build:

# we can also specify the OS to run tests on
runs-on: ubuntu-latest

# a job is a seq of steps
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@v2

- name: Set up Python 3.9
uses: actions/setup-python@v2
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
4 changes: 4 additions & 0 deletions inflammation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ def daily_min(data):
"""Calculate the daily min of a 2d inflammation data array."""
return np.min(data, axis=0)

def patient_normalise(data):
"""Normalise patient data from a 2D inflammation data array."""
max_data = np.max(data, axis=1)
return data / max_data[:, np.newaxis]
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
numpy
pytest
pytest-cov
59 changes: 58 additions & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import numpy.testing as npt
import os

import pytest

def test_daily_mean_zeros():
"""Test that mean function works for an array of zeros."""
Expand Down Expand Up @@ -31,9 +31,66 @@ def test_daily_mean_integers():
npt.assert_array_equal(daily_mean(test_input), test_result)

def test_load_from_json(tmpdir):

from inflammation.models import load_json
example_path = os.path.join(tmpdir, 'example.json')
with open(example_path, 'w') as temp_json_file:
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]])


@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):
"""Test max function works for zeroes, positive integers, mix of positive/negative integers."""
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):
"""Test min function works for zeroes, positive integers, mix of positive/negative integers."""
from inflammation.models import daily_min
npt.assert_array_equal(daily_min(np.array(test)), np.array(expected))

def test_daily_min_string():
"""Test for TypeError when passing strings"""
from inflammation.models import daily_min

with pytest.raises(TypeError):
error_expected = 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",
[
([[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[0.33, 0.67, 1], [0.67, 0.83, 1], [0.78, 0.89, 1]])
])
def test_patient_normalise(test, expected):
"""Test normalisation works for arrays of one and positive integers.
Assumption that test accuracy of two decimal places is sufficient."""
from inflammation.models import patient_normalise
npt.assert_almost_equal(patient_normalise(np.array(test)), np.array(expected), decimal=2)