|
| 1 | +import pytest |
| 2 | + |
| 3 | +from medimetry.constants import Gender |
| 4 | +from medimetry.renal import cockcroft_gault |
| 5 | + |
| 6 | + |
| 7 | +def test_cockcroft_gault_male_normal(): |
| 8 | + """Test Cockcroft-Gault formula for normal male patient.""" |
| 9 | + # 70-year-old male, 70kg, creatinine 1.0 mg/dl |
| 10 | + result = cockcroft_gault(age=70, weight=70, creatinine=1.0, gender=Gender.MALE) |
| 11 | + expected = round(((140 - 70) * 70) / (72 * 1.0)) # 68 mL/min |
| 12 | + assert result == expected |
| 13 | + assert result == 68 |
| 14 | + |
| 15 | + |
| 16 | +def test_cockcroft_gault_female_normal(): |
| 17 | + """Test Cockcroft-Gault formula for normal female patient.""" |
| 18 | + # 70-year-old female, 60kg, creatinine 1.0 mg/dl |
| 19 | + result = cockcroft_gault(age=70, weight=60, creatinine=1.0, gender=Gender.FEMALE) |
| 20 | + expected = round(((140 - 70) * 60) / (72 * 1.0) * 0.85) # 49 mL/min |
| 21 | + assert result == expected |
| 22 | + assert result == 50 |
| 23 | + |
| 24 | + |
| 25 | +def test_cockcroft_gault_young_patient(): |
| 26 | + """Test Cockcroft-Gault formula for young patient.""" |
| 27 | + # 30-year-old male, 80kg, creatinine 0.8 mg/dl |
| 28 | + result = cockcroft_gault(age=30, weight=80, creatinine=0.8, gender=Gender.MALE) |
| 29 | + expected = round(((140 - 30) * 80) / (72 * 0.8)) # 153 mL/min |
| 30 | + assert result == expected |
| 31 | + assert result == 153 |
| 32 | + |
| 33 | + |
| 34 | +def test_cockcroft_gault_elderly_patient(): |
| 35 | + """Test Cockcroft-Gault formula for elderly patient.""" |
| 36 | + # 85-year-old female, 55kg, creatinine 1.5 mg/dl |
| 37 | + result = cockcroft_gault(age=85, weight=55, creatinine=1.5, gender=Gender.FEMALE) |
| 38 | + expected = round(((140 - 85) * 55) / (72 * 1.5) * 0.85) # 25 mL/min |
| 39 | + assert result == expected |
| 40 | + assert result == 24 |
| 41 | + |
| 42 | + |
| 43 | +def test_cockcroft_gault_high_creatinine(): |
| 44 | + """Test Cockcroft-Gault formula with high creatinine.""" |
| 45 | + # 60-year-old male, 75kg, creatinine 3.0 mg/dl |
| 46 | + result = cockcroft_gault(age=60, weight=75, creatinine=3.0, gender=Gender.MALE) |
| 47 | + expected = round(((140 - 60) * 75) / (72 * 3.0)) # 28 mL/min |
| 48 | + assert result == expected |
| 49 | + assert result == 28 |
| 50 | + |
| 51 | + |
| 52 | +def test_cockcroft_gault_zero_weight(): |
| 53 | + """Test Cockcroft-Gault formula with zero weight.""" |
| 54 | + with pytest.raises(AssertionError, match="Weight must be positive"): |
| 55 | + cockcroft_gault(age=50, weight=0, creatinine=1.0, gender=Gender.MALE) |
| 56 | + |
| 57 | + |
| 58 | +def test_cockcroft_gault_negative_weight(): |
| 59 | + """Test Cockcroft-Gault formula with negative weight.""" |
| 60 | + with pytest.raises(AssertionError, match="Weight must be positive"): |
| 61 | + cockcroft_gault(age=50, weight=-10, creatinine=1.0, gender=Gender.MALE) |
| 62 | + |
| 63 | + |
| 64 | +def test_cockcroft_gault_excessive_weight(): |
| 65 | + """Test Cockcroft-Gault formula with excessive weight.""" |
| 66 | + with pytest.raises(AssertionError, match="Weight must be less than 400 kg"): |
| 67 | + cockcroft_gault(age=50, weight=450, creatinine=1.0, gender=Gender.MALE) |
| 68 | + |
| 69 | + |
| 70 | +def test_cockcroft_gault_zero_age(): |
| 71 | + """Test Cockcroft-Gault formula with zero age.""" |
| 72 | + with pytest.raises(AssertionError, match="Age must be positive"): |
| 73 | + cockcroft_gault(age=0, weight=70, creatinine=1.0, gender=Gender.MALE) |
| 74 | + |
| 75 | + |
| 76 | +def test_cockcroft_gault_negative_age(): |
| 77 | + """Test Cockcroft-Gault formula with negative age.""" |
| 78 | + with pytest.raises(AssertionError, match="Age must be positive"): |
| 79 | + cockcroft_gault(age=-5, weight=70, creatinine=1.0, gender=Gender.MALE) |
| 80 | + |
| 81 | + |
| 82 | +def test_cockcroft_gault_negative_creatinine(): |
| 83 | + """Test Cockcroft-Gault formula with negative creatinine.""" |
| 84 | + with pytest.raises(AssertionError, match="Creatinine must not be negative"): |
| 85 | + cockcroft_gault(age=50, weight=70, creatinine=-0.5, gender=Gender.MALE) |
| 86 | + |
| 87 | + |
| 88 | +def test_cockcroft_gault_zero_creatinine(): |
| 89 | + """Test Cockcroft-Gault formula with zero creatinine.""" |
| 90 | + # Zero creatinine should be allowed (though clinically unrealistic) |
| 91 | + with pytest.raises(ValueError, match="Creatinine must be non-zero"): |
| 92 | + cockcroft_gault(age=50, weight=70, creatinine=0.0, gender=Gender.MALE) |
| 93 | + # This would result in division by zero, so the function should handle this |
| 94 | + |
| 95 | + |
| 96 | +def test_cockcroft_gault_invalid_gender(): |
| 97 | + """Test Cockcroft-Gault formula with invalid gender.""" |
| 98 | + with pytest.raises(AssertionError, match="gender must be a Gender instance"): |
| 99 | + cockcroft_gault(age=50, weight=70, creatinine=1.0, gender="invalid") |
| 100 | + with pytest.raises(AssertionError, match="gender must be a Gender instance"): |
| 101 | + cockcroft_gault(age=50, weight=70, creatinine=1.0, gender=2) |
| 102 | + |
| 103 | + |
| 104 | +def test_cockcroft_gault_realistic_scenarios(): |
| 105 | + """Test Cockcroft-Gault formula with realistic clinical scenarios.""" |
| 106 | + # Healthy young adult male |
| 107 | + result = cockcroft_gault(age=25, weight=75, creatinine=0.9, gender=Gender.MALE) |
| 108 | + assert result > 100 # Should have good kidney function |
| 109 | + |
| 110 | + # Elderly female with mild kidney impairment |
| 111 | + result = cockcroft_gault(age=80, weight=60, creatinine=1.3, gender=Gender.FEMALE) |
| 112 | + assert 30 < result < 60 # Moderate kidney impairment |
| 113 | + |
| 114 | + # Middle-aged male with normal function |
| 115 | + result = cockcroft_gault(age=45, weight=80, creatinine=1.1, gender=Gender.MALE) |
| 116 | + assert 60 < result < 120 # Normal to mildly reduced |
| 117 | + |
| 118 | + |
| 119 | +def test_cockcroft_gault_gender_difference(): |
| 120 | + """Test that female patients have lower clearance than male patients.""" |
| 121 | + male_result = cockcroft_gault(age=60, weight=70, creatinine=1.0, gender=Gender.MALE) |
| 122 | + female_result = cockcroft_gault(age=60, weight=70, creatinine=1.0, gender=Gender.FEMALE) |
| 123 | + |
| 124 | + # Female result should be 85% of male result |
| 125 | + expected_female = round(male_result * 0.85) |
| 126 | + assert female_result < male_result |
| 127 | + assert abs(female_result - expected_female) <= 1 # Allow for rounding differences |
| 128 | + |
| 129 | + |
| 130 | +def test_cockcroft_gault_return_type(): |
| 131 | + """Test that Cockcroft-Gault returns an integer.""" |
| 132 | + result = cockcroft_gault(age=50, weight=70, creatinine=1.0, gender=Gender.MALE) |
| 133 | + assert isinstance(result, int) |
0 commit comments