|
4 | 4 | from lung_cancer_screening.calculators.plco import Plco |
5 | 5 |
|
6 | 6 | class TestPlco(TestCase): |
| 7 | + def setUp(self): |
| 8 | + self.defaultArgs = { |
| 9 | + "age": 62, |
| 10 | + "bmi": 27, |
| 11 | + "copd_enphysema_or_chronic_bronchitis": False, |
| 12 | + "personal_history_of_cancer": False, |
| 13 | + "family_history_of_cancer": False |
| 14 | + } |
| 15 | + |
7 | 16 | def test_age_in_years_contribution_to_estimate_when_age_is_none(self): |
8 | | - calculator = Plco(age=None) |
| 17 | + calculator = Plco(**dict(self.defaultArgs, age=None)) |
9 | 18 | result = calculator.age_in_years_contribution_to_estimate() |
10 | 19 |
|
11 | 20 | self.assertEqual(result, Decimal('-4.8289816')) |
12 | 21 |
|
13 | 22 | def test_age_in_years_contribution_to_estimate_at_74(self): |
14 | | - calculator = Plco(age=74) |
| 23 | + calculator = Plco(**dict(self.defaultArgs, age=74)) |
15 | 24 | result = calculator.age_in_years_contribution_to_estimate() |
16 | 25 |
|
17 | 26 | self.assertEqual(result, Decimal('0.9346416')) |
18 | 27 |
|
19 | 28 | def test_age_in_years_contribution_to_estimate_at_62(self): |
20 | | - calculator = Plco(age=58) |
| 29 | + calculator = Plco(**dict(self.defaultArgs, age=58)) |
21 | 30 | result = calculator.age_in_years_contribution_to_estimate() |
22 | 31 |
|
23 | 32 | self.assertEqual(result, Decimal('-0.3115472')) |
24 | 33 |
|
25 | 34 | def test_bmi_contribution_to_estimate_when_bmi_is_none(self): |
26 | | - calculator = Plco(bmi=None) |
| 35 | + calculator = Plco(**dict(self.defaultArgs, bmi=None)) |
27 | 36 | result = calculator.bmi_contribution_to_estimate() |
28 | 37 |
|
29 | 38 | self.assertEqual(result, Decimal('0.7403238')) |
30 | 39 |
|
31 | 40 | def test_bmi_contribution_to_estimate_when_bmi_is_23_point_5(self): |
32 | | - calculator = Plco(bmi=23.5) |
| 41 | + calculator = Plco(**dict(self.defaultArgs, bmi=23.5)) |
33 | 42 | result = calculator.bmi_contribution_to_estimate() |
34 | 43 |
|
35 | 44 | self.assertEqual(result, Decimal('0.0959679')) |
36 | 45 |
|
37 | 46 | def test_bmi_contribution_to_estimate_when_bmi_is_a_long_decimal(self): |
38 | | - calculator = Plco(bmi="26.4749212") |
| 47 | + calculator = Plco(**dict(self.defaultArgs, bmi="26.4749212")) |
39 | 48 | result = calculator.bmi_contribution_to_estimate() |
40 | 49 |
|
41 | 50 | self.assertEqual(result, Decimal('0.01439734564872')) |
42 | 51 |
|
43 | 52 | def test_copd_enphysema_or_chronic_bronchitiscontribution_to_estimate_when_none(self): |
44 | | - calculator = Plco(copd_enphysema_or_chronic_bronchitis=None) |
| 53 | + calculator = Plco(**dict(self.defaultArgs, copd_enphysema_or_chronic_bronchitis=None)) |
45 | 54 |
|
46 | 55 | self.assertRaises( |
47 | 56 | Plco.InvalidValueError, |
48 | 57 | calculator.copd_enphysema_or_chronic_bronchitis_contribution_to_estimate |
49 | 58 | ) |
50 | 59 |
|
51 | 60 | def test_copd_enphysema_or_chronic_bronchitiscontribution_to_estimate_when_true(self): |
52 | | - calculator = Plco(copd_enphysema_or_chronic_bronchitis=True) |
| 61 | + calculator = Plco(**dict(self.defaultArgs, copd_enphysema_or_chronic_bronchitis=True)) |
53 | 62 |
|
54 | 63 | result = calculator.copd_enphysema_or_chronic_bronchitis_contribution_to_estimate() |
55 | 64 |
|
56 | 65 | self.assertEqual(result, Decimal('0.3553063')) |
57 | 66 |
|
58 | 67 | def test_copd_enphysema_or_chronic_bronchitiscontribution_to_estimate_when_false(self): |
59 | | - calculator = Plco(copd_enphysema_or_chronic_bronchitis=False) |
| 68 | + calculator = Plco(**dict(self.defaultArgs, copd_enphysema_or_chronic_bronchitis=False)) |
60 | 69 |
|
61 | 70 | result = calculator.copd_enphysema_or_chronic_bronchitis_contribution_to_estimate() |
62 | 71 |
|
63 | 72 | self.assertEqual(result, Decimal('0')) |
64 | 73 |
|
65 | 74 | def test_personal_history_of_cancer_contribution_to_estimate_when_none(self): |
66 | | - calculator = Plco(personal_history_of_cancer=None) |
| 75 | + calculator = Plco(**dict(self.defaultArgs, personal_history_of_cancer=None)) |
67 | 76 |
|
68 | 77 | self.assertRaises( |
69 | 78 | Plco.InvalidValueError, |
70 | 79 | calculator.personal_history_of_cancer_contribution_to_estimate |
71 | 80 | ) |
72 | 81 |
|
73 | 82 | def test_personal_history_of_cancer_contribution_to_estimate_when_true(self): |
74 | | - calculator = Plco(personal_history_of_cancer=True) |
| 83 | + calculator = Plco(**dict(self.defaultArgs, personal_history_of_cancer=True)) |
75 | 84 |
|
76 | 85 | result = calculator.personal_history_of_cancer_contribution_to_estimate() |
77 | 86 |
|
78 | 87 | self.assertEqual(result, Decimal('0.4589971')) |
79 | 88 |
|
80 | 89 | def test_personal_history_of_cancer_contribution_to_estimate_when_false(self): |
81 | | - calculator = Plco(personal_history_of_cancer=False) |
| 90 | + calculator = Plco(**dict(self.defaultArgs, personal_history_of_cancer=False)) |
82 | 91 |
|
83 | 92 | result = calculator.personal_history_of_cancer_contribution_to_estimate() |
84 | 93 |
|
85 | 94 | self.assertEqual(result, Decimal('0')) |
86 | 95 |
|
87 | 96 | def test_family_history_of_cancer_contribution_to_estimate_when_none(self): |
88 | | - calculator = Plco(family_history_of_cancer=None) |
| 97 | + calculator = Plco(**dict(self.defaultArgs, family_history_of_cancer=None)) |
89 | 98 |
|
90 | 99 | self.assertRaises( |
91 | 100 | Plco.InvalidValueError, |
92 | 101 | calculator.family_history_of_cancer_contribution_to_estimate |
93 | 102 | ) |
94 | 103 |
|
95 | 104 | def test_family_history_of_cancer_contribution_to_estimate_when_true(self): |
96 | | - calculator = Plco(family_history_of_cancer=True) |
| 105 | + calculator = Plco(**dict(self.defaultArgs, family_history_of_cancer=True)) |
97 | 106 |
|
98 | 107 | result = calculator.family_history_of_cancer_contribution_to_estimate() |
99 | 108 |
|
100 | 109 | self.assertEqual(result, Decimal('0.587185')) |
101 | 110 |
|
102 | 111 | def test_family_history_of_cancer_contribution_to_estimate_when_false(self): |
103 | | - calculator = Plco(family_history_of_cancer=False) |
| 112 | + calculator = Plco(**dict(self.defaultArgs, family_history_of_cancer=False)) |
104 | 113 |
|
105 | 114 | result = calculator.family_history_of_cancer_contribution_to_estimate() |
106 | 115 |
|
|
0 commit comments