@@ -113,6 +113,8 @@ Let us now add a new test in `tests/test_models.py`
113113to check that the normalisation function is correct for some test data.
114114
115115~~~
116+ from inflammation.models import patient_normalise
117+
116118@pytest.mark.parametrize(
117119 "test, expected",
118120 [
@@ -121,7 +123,7 @@ to check that the normalisation function is correct for some test data.
121123def test_patient_normalise(test, expected):
122124 """Test normalisation works for arrays of one and positive integers.
123125 Test with a relative and absolute tolerance of 0.01."""
124- from inflammation.models import patient_normalise
126+
125127 result = patient_normalise(np.array(test))
126128 npt.assert_allclose(result, np.array(expected), rtol=1e-2, atol=1e-2)
127129~~~
@@ -135,14 +137,15 @@ and are only concerned with a certain degree of precision,
135137like the test case above.
136138
137139> ## Relative and absolute tolerance
138- > ** Relative tolerance** in unit testing means that the acceptable difference between the expected and actual results
139- > depends on the size of the expected result itself. So, if your expected result is 100,
140+ >
141+ > ** Relative tolerance** in unit testing means that the acceptable difference between the expected and actual results
142+ > depends on the size of the expected result itself. So, if your expected result is 100,
140143> a relative tolerance of 0.1 (or 10%) means the actual result can be anywhere from 90 to 110 and still be considered correct.
141- >
142- > ** Absolute tolerance** , on the other hand,
143- > sets a fixed allowable difference regardless of the magnitude of the expected result.
144- > For example, if you set an absolute tolerance of 5,
145- > it means the actual result can be within 5 units of the expected result,
144+ >
145+ > ** Absolute tolerance** , on the other hand,
146+ > sets a fixed allowable difference regardless of the magnitude of the expected result.
147+ > For example, if you set an absolute tolerance of 5,
148+ > it means the actual result can be within 5 units of the expected result,
146149> regardless of whether the expected result is 10 or 1000.
147150 {: .callout}
148151
@@ -467,9 +470,12 @@ def patient_normalise(data):
467470> and add them to the parametrised tests.
468471> After you have finished remember to commit your changes.
469472>
470- >
473+ >
471474> > ## Possible Solution
475+ > >
472476> > ~~~
477+ > > from inflammation.models import patient_normalise
478+ > >
473479> > @pytest.mark.parametrize(
474480> > "test, expected",
475481> > [
@@ -500,7 +506,7 @@ def patient_normalise(data):
500506> > ])
501507> > def test_patient_normalise(test, expected):
502508> > """Test normalisation works for arrays of one and positive integers."""
503- > > from inflammation.models import patient_normalise
509+ > >
504510> > result = patient_normalise(np.array(test))
505511> > npt.assert_allclose(result, np.array(expected), rtol=1e-2, atol=1e-2)
506512> > ...
@@ -563,6 +569,8 @@ and is used to indicate that the function received an argument of the right type
563569but of an inappropriate value.
564570
565571~~~
572+ from inflammation.models import patient_normalise
573+
566574@pytest .mark.parametrize(
567575 "test, expected, expect_raises",
568576 [
@@ -581,7 +589,6 @@ but of an inappropriate value.
581589 ] )
582590def test_patient_normalise(test, expected, expect_raises):
583591 """Test normalisation works for arrays of one and positive integers."""
584- from inflammation.models import patient_normalise
585592
586593 if expect_raises is not None:
587594 with pytest.raises(expect_raises):
@@ -639,6 +646,7 @@ Be sure to commit your changes so far and push them to GitHub.
639646> > In `test/test_models.py`:
640647> >
641648> > ~~~
649+ > > from inflammation.models import patient_normalise
642650> > ...
643651> > @pytest.mark.parametrize(
644652> > "test, expected, expect_raises",
@@ -662,7 +670,6 @@ Be sure to commit your changes so far and push them to GitHub.
662670> > ])
663671> > def test_patient_normalise(test, expected, expect_raises):
664672> > """Test normalisation works for arrays of one and positive integers."""
665- > > from inflammation.models import patient_normalise
666673> > if isinstance(test, list):
667674> > test = np.array(test)
668675> > if expect_raises is not None:
0 commit comments