1
1
import unittest
2
- from causal_testing .testing .causal_test_outcome import ExactValue , SomeEffect , Positive , Negative
2
+ from causal_testing .testing .causal_test_outcome import ExactValue , SomeEffect , Positive , Negative , NoEffect
3
3
from causal_testing .testing .causal_test_result import CausalTestResult , TestValue
4
4
from causal_testing .testing .estimators import LinearRegressionEstimator
5
5
from causal_testing .testing .validation import CausalValidator
@@ -86,6 +86,17 @@ def test_Positive_fail(self):
86
86
ev = Positive ()
87
87
self .assertFalse (ev .apply (ctr ))
88
88
89
+ def test_Positive_fail_ci (self ):
90
+ test_value = TestValue (type = "ate" , value = 0 )
91
+ ctr = CausalTestResult (
92
+ estimator = self .estimator ,
93
+ test_value = test_value ,
94
+ confidence_intervals = [- 1 , 1 ],
95
+ effect_modifier_configuration = None ,
96
+ )
97
+ ev = Positive ()
98
+ self .assertFalse (ev .apply (ctr ))
99
+
89
100
def test_Negative_pass (self ):
90
101
test_value = TestValue (type = "ate" , value = - 5.05 )
91
102
ctr = CausalTestResult (
@@ -108,6 +119,17 @@ def test_Negative_fail(self):
108
119
ev = Negative ()
109
120
self .assertFalse (ev .apply (ctr ))
110
121
122
+ def test_Negative_fail_ci (self ):
123
+ test_value = TestValue (type = "ate" , value = 0 )
124
+ ctr = CausalTestResult (
125
+ estimator = self .estimator ,
126
+ test_value = test_value ,
127
+ confidence_intervals = [- 1 , 1 ],
128
+ effect_modifier_configuration = None ,
129
+ )
130
+ ev = Negative ()
131
+ self .assertFalse (ev .apply (ctr ))
132
+
111
133
def test_exactValue_pass (self ):
112
134
test_value = TestValue (type = "ate" , value = 5.05 )
113
135
ctr = CausalTestResult (
@@ -119,6 +141,17 @@ def test_exactValue_pass(self):
119
141
ev = ExactValue (5 , 0.1 )
120
142
self .assertTrue (ev .apply (ctr ))
121
143
144
+ def test_exactValue_pass_ci (self ):
145
+ test_value = TestValue (type = "ate" , value = 5.05 )
146
+ ctr = CausalTestResult (
147
+ estimator = self .estimator ,
148
+ test_value = test_value ,
149
+ confidence_intervals = [4 , 6 ],
150
+ effect_modifier_configuration = None ,
151
+ )
152
+ ev = ExactValue (5 , 0.1 )
153
+ self .assertTrue (ev .apply (ctr ))
154
+
122
155
def test_exactValue_fail (self ):
123
156
test_value = TestValue (type = "ate" , value = 0 )
124
157
ctr = CausalTestResult (
@@ -130,18 +163,52 @@ def test_exactValue_fail(self):
130
163
ev = ExactValue (5 , 0.1 )
131
164
self .assertFalse (ev .apply (ctr ))
132
165
133
- def test_someEffect_pass (self ):
134
- test_value = TestValue (type = "ate " , value = 5.05 )
166
+ def test_someEffect_invalid (self ):
167
+ test_value = TestValue (type = "invalid " , value = 5.05 )
135
168
ctr = CausalTestResult (
136
169
estimator = self .estimator ,
137
170
test_value = test_value ,
138
171
confidence_intervals = [4.8 , 6.7 ],
139
172
effect_modifier_configuration = None ,
140
173
)
141
174
ev = SomeEffect ()
142
- self .assertTrue (ev .apply (ctr ))
175
+ with self .assertRaises (ValueError ):
176
+ ev .apply (ctr )
177
+
178
+ def test_someEffect_pass_ate (self ):
179
+ test_value = TestValue (type = "ate" , value = 5.05 )
180
+ ctr = CausalTestResult (
181
+ estimator = self .estimator ,
182
+ test_value = test_value ,
183
+ confidence_intervals = [4.8 , 6.7 ],
184
+ effect_modifier_configuration = None ,
185
+ )
186
+ self .assertTrue (SomeEffect ().apply (ctr ))
187
+ self .assertFalse (NoEffect ().apply (ctr ))
188
+
189
+ def test_someEffect_pass_rr (self ):
190
+ test_value = TestValue (type = "risk_ratio" , value = 5.05 )
191
+ ctr = CausalTestResult (
192
+ estimator = self .estimator ,
193
+ test_value = test_value ,
194
+ confidence_intervals = [4.8 , 6.7 ],
195
+ effect_modifier_configuration = None ,
196
+ )
197
+ self .assertTrue (SomeEffect ().apply (ctr ))
198
+ self .assertFalse (NoEffect ().apply (ctr ))
143
199
144
200
def test_someEffect_fail (self ):
201
+ test_value = TestValue (type = "ate" , value = 0 )
202
+ ctr = CausalTestResult (
203
+ estimator = self .estimator ,
204
+ test_value = test_value ,
205
+ confidence_intervals = [- 0.1 , 0.2 ],
206
+ effect_modifier_configuration = None ,
207
+ )
208
+ self .assertFalse (SomeEffect ().apply (ctr ))
209
+ self .assertTrue (NoEffect ().apply (ctr ))
210
+
211
+ def test_someEffect_str (self ):
145
212
test_value = TestValue (type = "ate" , value = 0 )
146
213
ctr = CausalTestResult (
147
214
estimator = self .estimator ,
@@ -150,20 +217,29 @@ def test_someEffect_fail(self):
150
217
effect_modifier_configuration = None ,
151
218
)
152
219
ev = SomeEffect ()
153
- self .assertFalse (ev .apply (ctr ))
154
220
self .assertEqual (
155
- str (ctr ),
156
- (
157
- "Causal Test Result\n ==============\n "
158
- "Treatment: A\n "
159
- "Control value: 0\n "
160
- "Treatment value: 1\n "
161
- "Outcome: A\n "
162
- "Adjustment set: set()\n "
163
- "ate: 0\n "
164
- "Confidence intervals: [-0.1, 0.2]\n "
165
- ),
221
+ ctr .to_dict (),
222
+ {
223
+ "treatment" : "A" ,
224
+ "control_value" : 0 ,
225
+ "treatment_value" : 1 ,
226
+ "outcome" : "A" ,
227
+ "adjustment_set" : set (),
228
+ "test_value" : test_value ,
229
+ "ci_low" : - 0.1 ,
230
+ "ci_high" : 0.2 ,
231
+ },
232
+ )
233
+
234
+ def test_someEffect_dict (self ):
235
+ test_value = TestValue (type = "ate" , value = 0 )
236
+ ctr = CausalTestResult (
237
+ estimator = self .estimator ,
238
+ test_value = test_value ,
239
+ confidence_intervals = [- 0.1 , 0.2 ],
240
+ effect_modifier_configuration = None ,
166
241
)
242
+ ev = SomeEffect ()
167
243
self .assertEqual (
168
244
ctr .to_dict (),
169
245
{
0 commit comments