Add unit test for yli.turnbull

This commit is contained in:
RunasSudo 2023-04-22 01:09:05 +10:00
parent ae1a4cb5b8
commit aff4287ccc
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

52
tests/test_turnbull.py Normal file
View File

@ -0,0 +1,52 @@
# scipy-yli: Helpful SciPy utilities and recipes
# Copyright © 2022–2023 Lee Yingtong Li (RunasSudo)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from pytest import approx
import pandas as pd
import yli
def test_turnbull_simple():
"""Compare yli.turnbull for simple example"""
df = pd.DataFrame({
'Time_L': [0.5, 1, 3, 5],
'Time_R': [2.5, 2, 4, 6]
})
xpoints, ypoints = yli.survival.calc_survfunc_turnbull(df['Time_L'], df['Time_R'])
assert xpoints[0] == 0
assert ypoints[0] == 1
assert xpoints[1] == approx(1.5)
assert ypoints[1] == 1
assert xpoints[2] == approx(1.5)
assert ypoints[2] == 0.5
assert xpoints[3] == approx(3.5)
assert ypoints[3] == 0.5
assert xpoints[4] == approx(3.5)
assert ypoints[4] == 0.25
assert xpoints[5] == approx(5.5)
assert ypoints[5] == 0.25
assert xpoints[6] == approx(5.5)
assert ypoints[6] == 0