|
| 1 | +import pytest |
| 2 | + |
| 3 | +from medimetry import Gender |
| 4 | +from medimetry.renal import ckd_epi |
| 5 | + |
| 6 | + |
| 7 | +def assert_in_range(result, expected): |
| 8 | + """Helper for asserting that a result is within a certain range of 0.1.""" |
| 9 | + assert abs(result - expected) < 0.1 |
| 10 | + |
| 11 | + |
| 12 | +def test_ckd_epi_male_normal_creatinine(): |
| 13 | + """Test CKD-EPI formula for male patient with normal creatinine levels.""" |
| 14 | + # 50-year-old male, creatinine 1.0 mg/dl |
| 15 | + result = ckd_epi(creatinine=1.0, age=50, gender=Gender.MALE) |
| 16 | + expected = 91.6 |
| 17 | + assert_in_range(result, expected) |
| 18 | + |
| 19 | + |
| 20 | +def test_ckd_epi_male_elevated_creatinine(): |
| 21 | + result = ckd_epi(creatinine=2.0, age=50, gender=Gender.MALE) |
| 22 | + expected = 40.0 |
| 23 | + assert_in_range(result, expected) |
| 24 | + |
| 25 | + |
| 26 | +def test_ckd_epi_female_normal_creatinine(): |
| 27 | + """Test CKD-EPI formula for female patient with normal creatinine levels.""" |
| 28 | + # 50-year-old female, creatinine 0.8 mg/dl |
| 29 | + result = ckd_epi(creatinine=0.8, age=50, gender=Gender.FEMALE) |
| 30 | + expected = 89.7 |
| 31 | + assert_in_range(result, expected) |
| 32 | + |
| 33 | + |
| 34 | +def test_ckd_epi_female_elevated_creatinine(): |
| 35 | + """Test CKD-EPI formula for female patient with elevated creatinine levels.""" |
| 36 | + # 60-year-old female, creatinine 2.5 mg/dl |
| 37 | + result = ckd_epi(creatinine=2.5, age=60, gender=Gender.FEMALE) |
| 38 | + expected = 21.4 |
| 39 | + assert_in_range(result, expected) |
| 40 | + |
| 41 | + |
| 42 | +def test_ckd_epi_male_with_cystatin_c(): |
| 43 | + """Test CKD-EPI formula for male patient with cystatin C.""" |
| 44 | + # 60-year-old male, creatinine 1.2 mg/dl, cystatin C 1.0 mg/dl |
| 45 | + result = ckd_epi(creatinine=1.2, age=60, gender=Gender.MALE, cystatin_c=1.0) |
| 46 | + expected = 76.8 |
| 47 | + assert_in_range(result, expected) |
| 48 | + |
| 49 | + |
| 50 | +def test_ckd_epi_female_with_cystatin_c(): |
| 51 | + """Test CKD-EPI formula for female patient with cystatin C.""" |
| 52 | + # 50-year-old female, creatinine 0.9 mg/dl, cystatin C 1.1 mg/dl |
| 53 | + result = ckd_epi(creatinine=0.9, age=50, gender=Gender.FEMALE, cystatin_c=1.1) |
| 54 | + expected = 72.8 |
| 55 | + assert_in_range(result, expected) |
| 56 | + |
| 57 | + |
| 58 | +def test_ckd_epi_zero_creatinine(): |
| 59 | + """Test that AssertionError is raised for zero creatinine.""" |
| 60 | + with pytest.raises(AssertionError, match="Creatinine must be positive"): |
| 61 | + ckd_epi(creatinine=0.0, age=50, gender=Gender.MALE) |
| 62 | + |
| 63 | + |
| 64 | +def test_ckd_epi_negative_creatinine(): |
| 65 | + """Test that AssertionError is raised for negative creatinine.""" |
| 66 | + with pytest.raises(AssertionError, match="Creatinine must be positive"): |
| 67 | + ckd_epi(creatinine=-0.5, age=50, gender=Gender.MALE) |
| 68 | + |
| 69 | + |
| 70 | +def test_ckd_epi_zero_age(): |
| 71 | + """Test that AssertionError is raised for zero age.""" |
| 72 | + with pytest.raises(AssertionError, match="Age must be positive"): |
| 73 | + ckd_epi(creatinine=1.0, age=0, gender=Gender.MALE) |
| 74 | + |
| 75 | + |
| 76 | +def test_ckd_epi_negative_age(): |
| 77 | + """Test that AssertionError is raised for negative age.""" |
| 78 | + with pytest.raises(AssertionError, match="Age must be positive"): |
| 79 | + ckd_epi(creatinine=1.0, age=-5, gender=Gender.MALE) |
| 80 | + |
| 81 | + |
| 82 | +def test_ckd_epi_invalid_gender(): |
| 83 | + """Test that AssertionError is raised for invalid gender.""" |
| 84 | + with pytest.raises(TypeError, match="Gender must be of type 'Gender'"): |
| 85 | + ckd_epi(creatinine=1.0, age=50, gender="invalid") |
| 86 | + |
| 87 | + |
| 88 | +def test_ckd_epi_zero_cystatin_c(): |
| 89 | + """Test that AssertionError is raised for zero cystatin C.""" |
| 90 | + with pytest.raises(AssertionError, match="Cystatin C must be positive, if given"): |
| 91 | + ckd_epi(creatinine=1.0, age=50, gender=Gender.MALE, cystatin_c=0.0) |
| 92 | + |
| 93 | + |
| 94 | +def test_ckd_epi_negative_cystatin_c(): |
| 95 | + """Test that AssertionError is raised for negative cystatin C.""" |
| 96 | + with pytest.raises(AssertionError, match="Cystatin C must be positive, if given"): |
| 97 | + ckd_epi(creatinine=1.0, age=50, gender=Gender.MALE, cystatin_c=-0.5) |
| 98 | + |
| 99 | + |
| 100 | +def test_ckd_epi_very_low_creatinine(): |
| 101 | + """Test CKD-EPI formula with very low creatinine values below kappa threshold.""" |
| 102 | + # Female with very low creatinine (0.5 mg/dl, below kappa=0.7) |
| 103 | + result = ckd_epi(creatinine=0.5, age=30, gender=Gender.FEMALE) |
| 104 | + expected = 129.3 |
| 105 | + assert_in_range(result, expected) |
| 106 | + |
| 107 | + # Male with very low creatinine (0.6 mg/dl, below kappa=0.9) |
| 108 | + result = ckd_epi(creatinine=0.6, age=30, gender=Gender.MALE) |
| 109 | + expected = 133.1 |
| 110 | + assert_in_range(result, expected) |
| 111 | + |
| 112 | + |
| 113 | +def test_ckd_epi_very_high_creatinine(): |
| 114 | + """Test CKD-EPI formula with very high creatinine values above kappa threshold.""" |
| 115 | + # Female with very high creatinine (2.5 mg/dl, above kappa=0.7) |
| 116 | + result = ckd_epi(creatinine=6.0, age=80, gender=Gender.FEMALE) |
| 117 | + expected = 6.7 |
| 118 | + assert_in_range(result, expected) |
| 119 | + |
| 120 | + # Male with very high creatinine (3.0 mg/dl, above kappa=0.9) |
| 121 | + result = ckd_epi(creatinine=6.0, age=80, gender=Gender.MALE) |
| 122 | + expected = 8.8 |
| 123 | + assert_in_range(result, expected) |
| 124 | + |
| 125 | + |
| 126 | +def test_ckd_epi_elderly_patient(): |
| 127 | + """Test CKD-EPI formula for elderly patient over 80 years.""" |
| 128 | + # 85-year-old female, creatinine 1.2 mg/dl |
| 129 | + result = ckd_epi(creatinine=1.2, age=85, gender=Gender.FEMALE) |
| 130 | + expected = 44.3 |
| 131 | + assert_in_range(result, expected) |
0 commit comments