| """Unit tests for the triple_inhaler_therapy_service function.""" |
| import copd |
| import pandas as pd |
|
|
|
|
| def test_returns_zero_single_therapy_sitt(): |
| """Check output for single inhaler types. Single Inhaler Triple Therapy only.""" |
| input_df = pd.DataFrame({'Id': [1, 2, '3', 1], |
| 'InhalerType': ['LAMA', 'LABA', 'LAMA', 'LABA']}) |
| expected_df = pd.DataFrame({'Id': [1, 2, '3'], |
| 'TripleTherapy': [0, 0, 0]}) |
| output_df = copd.triple_inhaler_therapy_service( |
| df=input_df, id_col='Id', inhaler_col='InhalerType') |
| pd.testing.assert_frame_equal(expected_df, output_df) |
|
|
|
|
| def test_returns_zero_single_therapy_mitt(): |
| """Check output for single inhaler types. Includes Multiple Inhaler Triple Therapy.""" |
| input_df = pd.DataFrame({'Id': [1, 2, '3', 1], |
| 'InhalerType': ['LAMA', 'LABA', 'LAMA', 'LABA']}) |
| expected_df = pd.DataFrame({'Id': [1, 2, '3'], |
| 'TripleTherapy': [0, 0, 0]}) |
| output_df = copd.triple_inhaler_therapy_service( |
| df=input_df, id_col='Id', inhaler_col='InhalerType', include_mitt=True) |
| pd.testing.assert_frame_equal(expected_df, output_df) |
|
|
|
|
| def test_returns_zero_double_therapy_sitt(): |
| """Check output for double inhaler types. Single Inhaler Triple Therapy only.""" |
| input_df = pd.DataFrame({'Id': [1, 2, '3', 1], |
| 'InhalerType': ['LABA-LAMA', 'LABA-ICS', 'LABA-LAMA', |
| 'LABA-ICS']}) |
| expected_df = pd.DataFrame({'Id': [1, 2, '3'], |
| 'TripleTherapy': [0, 0, 0]}) |
| output_df = copd.triple_inhaler_therapy_service( |
| df=input_df, id_col='Id', inhaler_col='InhalerType') |
| pd.testing.assert_frame_equal(expected_df, output_df) |
|
|
|
|
| def test_returns_zero_double_therapy_mitt(): |
| """Check output for double inhaler types. Includes Multiple Inhaler Triple Therapy.""" |
| input_df = pd.DataFrame({'Id': [1, 2, '3', 1], |
| 'InhalerType': ['LABA-LAMA', 'LABA-ICS', 'LABA-LAMA', |
| 'LABA-ICS']}) |
| expected_df = pd.DataFrame({'Id': [1, 2, '3'], |
| 'TripleTherapy': [0, 0, 0]}) |
| output_df = copd.triple_inhaler_therapy_service( |
| df=input_df, id_col='Id', inhaler_col='InhalerType', include_mitt=True) |
| pd.testing.assert_frame_equal(expected_df, output_df) |
|
|
|
|
| def test_returns_one_triple_therapy_sitt(): |
| """Check output for triple inhaler types. Single Inhaler Triple Therapy only.""" |
| input_df = pd.DataFrame({'Id': [1, 2, '3', 1], |
| 'InhalerType': ['LABA-LAMA', 'LAMA +LABA-ICS', |
| 'LABA-LAMA-ICS', 'LAMA +LABA-ICS']}) |
| expected_df = pd.DataFrame({'Id': [1, 2, '3'], |
| 'TripleTherapy': [1, 1, 1]}) |
| output_df = copd.triple_inhaler_therapy_service( |
| df=input_df, id_col='Id', inhaler_col='InhalerType') |
| pd.testing.assert_frame_equal(expected_df, output_df) |
|
|
|
|
| def test_returns_zero_triple_therapy_sitt(): |
| """Check output for triple inhaler types. Single Inhaler Triple Therapy only. |
| |
| Input df includes SITT and also a patient with a valid MITT combination. Should return |
| zero for that patient as SITT only is required. |
| """ |
| input_df = pd.DataFrame({'Id': [1, 2, '3', 1, 4, 4], |
| 'InhalerType': ['LABA-LAMA', 'LAMA +LABA-ICS', |
| 'LABA-LAMA-ICS', 'LAMA +LABA-ICS', 'LAMA', |
| 'LABA-ICS']}) |
| expected_df = pd.DataFrame({'Id': [1, 2, 4, '3'], |
| 'TripleTherapy': [1, 1, 0, 1]}) |
| output_df = copd.triple_inhaler_therapy_service( |
| df=input_df, id_col='Id', inhaler_col='InhalerType') |
| pd.testing.assert_frame_equal(expected_df, output_df) |
|
|
|
|
| def test_returns_one_triple_therapy_mitt(): |
| """Check output for triple inhaler types. Includes Multiple Inhaler Triple Therapy. |
| |
| Input df includes SITT and also a patient with a valid MITT combination. Should return |
| one for all patients. |
| """ |
| input_df = pd.DataFrame({'Id': [1, 2, '3', 1, 4, 4], |
| 'InhalerType': ['LABA-LAMA', 'LAMA +LABA-ICS', |
| 'LABA-LAMA-ICS', 'LAMA +LABA-ICS', 'LAMA', |
| 'LABA-ICS']}) |
| expected_df = pd.DataFrame({'Id': [1, 2, 4, '3'], |
| 'TripleTherapy': [1, 1, 1, 1]}) |
| output_df = copd.triple_inhaler_therapy_service( |
| df=input_df, id_col='Id', inhaler_col='InhalerType', include_mitt=True) |
| pd.testing.assert_frame_equal(expected_df, output_df) |
|
|