Skip to content

Commit

Permalink
Updated starting PrEP unit test to include people not specifically te…
Browse files Browse the repository at this point in the history
…sted to start PrEP.
  • Loading branch information
pineapple-cat committed Oct 1, 2024
1 parent d915e7c commit 9d6ef98
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/tests/test_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,68 @@ def test_prep_usage():

pop.data[col.PREP_TYPE] = None
pop.data[col.EVER_PREP] = [True, False] * (N // 2)
pop.data[col.FIRST_ORAL_START_DATE] = None
pop.data[col.FIRST_CAB_START_DATE] = None
pop.data[col.FIRST_LEN_START_DATE] = None
pop.data[col.FIRST_VR_START_DATE] = None
pop.data[col.LAST_PREP_START_DATE] = None
pop.prep.prep_usage(pop)

# only 50% eligible to start prep for the first time
assert sum(pop.data[col.PREP_TYPE].isnull()) == N/2
# check that people who aren't on a specific type of prep don't have start dates
assert all((pop.data[col.PREP_TYPE] != PrEPType.Oral) == (pop.data[col.FIRST_ORAL_START_DATE].isnull()))
assert all((pop.data[col.PREP_TYPE] != PrEPType.Cabotegravir) == (pop.data[col.FIRST_CAB_START_DATE].isnull()))
assert all((pop.data[col.PREP_TYPE] != PrEPType.Lenacapavir) == (pop.data[col.FIRST_LEN_START_DATE].isnull()))
assert all((pop.data[col.PREP_TYPE] != PrEPType.VaginalRing) == (pop.data[col.FIRST_VR_START_DATE].isnull()))
assert all(pop.data[col.PREP_TYPE].notnull() == (pop.data[col.LAST_PREP_START_DATE] == pop.date))

pop.data[col.PREP_TYPE] = None
pop.data[col.EVER_PREP] = False
# introduce different preference ranking distributions
pop.data[col.PREP_ORAL_RANK] = [1, 2, 3, 4] * (N // 4)
pop.data[col.PREP_CAB_RANK] = [2, 1, 2, 3] * (N // 4)
pop.data[col.PREP_LEN_RANK] = [3, 3, 1, 2] * (N // 4)
pop.data[col.PREP_VR_RANK] = [4, 4, 4, 1] * (N // 4)
# all willing to take any prep
pop.data[col.PREP_ORAL_WILLING] = True
pop.data[col.PREP_CAB_WILLING] = True
pop.data[col.PREP_LEN_WILLING] = True
pop.data[col.PREP_VR_WILLING] = True
# not tested explicitly to start prep
pop.data[col.PREP_ORAL_TESTED] = False
pop.data[col.PREP_CAB_TESTED] = False
pop.data[col.PREP_LEN_TESTED] = False
pop.data[col.PREP_VR_TESTED] = False
# 100% chance to start prep
pop.prep.prob_base_prep_start = 1

pop.prep.prep_usage(pop)
# everyone starts their most preferred prep type
assert all((pop.data[col.PREP_TYPE] == PrEPType.Oral) == (pop.data[col.PREP_ORAL_RANK] == 1))
assert all((pop.data[col.PREP_TYPE] == PrEPType.Cabotegravir) == (pop.data[col.PREP_CAB_RANK] == 1))
assert all((pop.data[col.PREP_TYPE] == PrEPType.Lenacapavir) == (pop.data[col.PREP_LEN_RANK] == 1))
assert all((pop.data[col.PREP_TYPE] == PrEPType.VaginalRing) == (pop.data[col.PREP_VR_RANK] == 1))

pop.data[col.PREP_TYPE] = None
pop.data[col.EVER_PREP] = False
# nobody is willing to take oral or cab
pop.data[col.PREP_ORAL_WILLING] = False
pop.data[col.PREP_CAB_WILLING] = False
pop.prep.prep_usage(pop)

# everyone is either on len or vr
assert sum(pop.data[col.PREP_TYPE] == PrEPType.Lenacapavir) == N * 0.75
assert sum(pop.data[col.PREP_TYPE] == PrEPType.VaginalRing) == N * 0.25
# check that people who aren't on a specific type of prep don't have start dates
assert all((pop.data[col.PREP_TYPE] != PrEPType.Lenacapavir) == (pop.data[col.FIRST_LEN_START_DATE].isnull()))
assert all((pop.data[col.PREP_TYPE] != PrEPType.VaginalRing) == (pop.data[col.FIRST_VR_START_DATE].isnull()))
assert all(pop.data[col.LAST_PREP_START_DATE] == pop.date)

pop.data[col.PREP_TYPE] = None
pop.data[col.EVER_PREP] = False
pop.prep.date_prep_intro = [date(2000), date(3000), date(4000), date(6000)]
pop.prep.prep_usage(pop)
# everyone is on len because vr is not yet available
assert all(pop.data[col.PREP_TYPE] == PrEPType.Lenacapavir)
assert all(pop.data[col.FIRST_LEN_START_DATE] == pop.date)

0 comments on commit 9d6ef98

Please sign in to comment.