Skip to content

Commit

Permalink
Add parameterisation mean, min, max test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-maris committed Sep 20, 2023
1 parent 8795206 commit 1d6f0ae
Showing 1 changed file with 53 additions and 58 deletions.
111 changes: 53 additions & 58 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,77 @@

import numpy as np
import numpy.testing as npt
import pytest

@pytest.mark.parametrize(
"test, expected",
[
([ [0, 0], [0, 0], [0, 0] ], [0, 0]),
([ [1, 2], [3, 4], [5, 6] ], [3, 4]),
([[-1, 2, 3], [4, -5, 6], [7, 8, -9] ], [3.33333333, 1.66666667, 0.])
]
)

def test_daily_mean_zeros():
def test_daily_mean(test, expected):
"""Test that mean function works for an array of zeros."""
from inflammation.models import daily_mean

test_input = np.array([[0, 0],
[0, 0],
[0, 0]])
test_result = np.array([0, 0])

# Need to use Numpy testing functions to compare arrays
npt.assert_array_equal(daily_mean(test_input), test_result)


def test_daily_mean_integers():
"""Test that mean function works for an array of positive integers."""
from inflammation.models import daily_mean

test_input = np.array([[1, 2],
[3, 4],
[5, 6]])
test_result = np.array([3, 4])

# Need to use Numpy testing functions to compare arrays
npt.assert_array_equal(daily_mean(test_input), test_result)

def test_daily_mean_pos_and_neg_integers():
"""Test that mean function works for an array of positive and negative integers."""
from inflammation.models import daily_mean

test_input = np.array([[-1, 2, 3],
[4, -5, 6],
[7, 8, -9]])
test_result = np.array([3.33333333, 1.66666667, 0.])
npt.assert_array_almost_equal(daily_mean(np.array(test)), np.array(expected))

@pytest.mark.parametrize(
"test, expected",
[
([ [0, 0], [0, 0], [0, 0] ], [0, 0]),
([ [1, 2], [3, 4], [5, 6] ], [5, 6]),
([[-1, 2, 3], [4, -5, 6], [7, 8, -9] ], [7, 8, 6])
]
)

def test_daily_max(test, expected):
"""Test that max function works for an array of zeros."""
from inflammation.models import daily_max

# Need to use Numpy testing functions to compare arrays
npt.assert_array_almost_equal(daily_mean(test_input), test_result)
npt.assert_array_equal(daily_max(np.array(test)), np.array(expected))

def test_daily_max_zeros():
"""Test that max function works for an array of zeros."""
from inflammation.models import daily_max
# def test_daily_max_zeros():
# """Test that max function works for an array of zeros."""
# from inflammation.models import daily_max

test_input = np.array([[0, 0],
[0, 0],
[0, 0]])
test_result = np.array([0, 0])
# test_input = np.array([[0, 0],
# [0, 0],
# [0, 0]])
# test_result = np.array([0, 0])

# Need to use Numpy testing functions to compare arrays
npt.assert_array_equal(daily_max(test_input), test_result)
# # Need to use Numpy testing functions to compare arrays
# npt.assert_array_equal(daily_max(test_input), test_result)



def test_daily_max_integers():
"""Test that max function works for an array of positive integers."""
from inflammation.models import daily_max
# def test_daily_max_integers():
# """Test that max function works for an array of positive integers."""
# from inflammation.models import daily_max

test_input = np.array([[1, 2],
[3, 4],
[5, 6]])
test_result = np.array([5, 6])
# test_input = np.array([[1, 2],
# [3, 4],
# [5, 6]])
# test_result = np.array([5, 6])

# Need to use Numpy testing functions to compare arrays
npt.assert_array_equal(daily_max(test_input), test_result)
# # Need to use Numpy testing functions to compare arrays
# npt.assert_array_equal(daily_max(test_input), test_result)

def test_daily_max_floats():
"""Test that max function works for an array of positive floats."""
from inflammation.models import daily_max
# def test_daily_max_floats():
# """Test that max function works for an array of positive floats."""
# from inflammation.models import daily_max

test_input = np.array([[1.1, 2.2],
[3.3, 4.4],
[5.5, 6.6]])
test_result = np.array([5.5, 6.6])
# test_input = np.array([[1.1, 2.2],
# [3.3, 4.4],
# [5.5, 6.6]])
# test_result = np.array([5.5, 6.6])

# Need to use Numpy testing functions to compare arrays
npt.assert_array_equal(daily_max(test_input), test_result)
# # Need to use Numpy testing functions to compare arrays
# npt.assert_array_equal(daily_max(test_input), test_result)

def test_daily_min_zeros():
"""Test that min function works for an array of zeros."""
Expand Down Expand Up @@ -129,7 +124,7 @@ def test_daily_min_pos_and_neg_integers():
npt.assert_array_equal(daily_min(test_input), test_result)

...
import pytest

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

0 comments on commit 1d6f0ae

Please sign in to comment.