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
@@ -140,6 +140,17 @@ def test_exactValue_pass(self):
140
140
ev = ExactValue (5 , 0.1 )
141
141
self .assertTrue (ev .apply (ctr ))
142
142
143
+ def test_exactValue_pass_ci (self ):
144
+ test_value = TestValue (type = "ate" , value = 5.05 )
145
+ ctr = CausalTestResult (
146
+ estimator = self .estimator ,
147
+ test_value = test_value ,
148
+ confidence_intervals = [4 , 6 ],
149
+ effect_modifier_configuration = None ,
150
+ )
151
+ ev = ExactValue (5 , 0.1 )
152
+ self .assertTrue (ev .apply (ctr ))
153
+
143
154
def test_exactValue_fail (self ):
144
155
test_value = TestValue (type = "ate" , value = 0 )
145
156
ctr = CausalTestResult (
@@ -151,18 +162,52 @@ def test_exactValue_fail(self):
151
162
ev = ExactValue (5 , 0.1 )
152
163
self .assertFalse (ev .apply (ctr ))
153
164
154
- def test_someEffect_pass (self ):
155
- test_value = TestValue (type = "ate " , value = 5.05 )
165
+ def test_someEffect_invalid (self ):
166
+ test_value = TestValue (type = "invalid " , value = 5.05 )
156
167
ctr = CausalTestResult (
157
168
estimator = self .estimator ,
158
169
test_value = test_value ,
159
170
confidence_intervals = [4.8 , 6.7 ],
160
171
effect_modifier_configuration = None ,
161
172
)
162
173
ev = SomeEffect ()
163
- self .assertTrue (ev .apply (ctr ))
174
+ with self .assertRaises (ValueError ):
175
+ ev .apply (ctr )
176
+
177
+ def test_someEffect_pass_ate (self ):
178
+ test_value = TestValue (type = "ate" , value = 5.05 )
179
+ ctr = CausalTestResult (
180
+ estimator = self .estimator ,
181
+ test_value = test_value ,
182
+ confidence_intervals = [4.8 , 6.7 ],
183
+ effect_modifier_configuration = None ,
184
+ )
185
+ self .assertTrue (SomeEffect ().apply (ctr ))
186
+ self .assertFalse (NoEffect ().apply (ctr ))
187
+
188
+ def test_someEffect_pass_rr (self ):
189
+ test_value = TestValue (type = "risk_ratio" , value = 5.05 )
190
+ ctr = CausalTestResult (
191
+ estimator = self .estimator ,
192
+ test_value = test_value ,
193
+ confidence_intervals = [4.8 , 6.7 ],
194
+ effect_modifier_configuration = None ,
195
+ )
196
+ self .assertTrue (SomeEffect ().apply (ctr ))
197
+ self .assertFalse (NoEffect ().apply (ctr ))
164
198
165
199
def test_someEffect_fail (self ):
200
+ test_value = TestValue (type = "ate" , value = 0 )
201
+ ctr = CausalTestResult (
202
+ estimator = self .estimator ,
203
+ test_value = test_value ,
204
+ confidence_intervals = [- 0.1 , 0.2 ],
205
+ effect_modifier_configuration = None ,
206
+ )
207
+ self .assertFalse (SomeEffect ().apply (ctr ))
208
+ self .assertTrue (NoEffect ().apply (ctr ))
209
+
210
+ def test_someEffect_str (self ):
166
211
test_value = TestValue (type = "ate" , value = 0 )
167
212
ctr = CausalTestResult (
168
213
estimator = self .estimator ,
@@ -171,20 +216,29 @@ def test_someEffect_fail(self):
171
216
effect_modifier_configuration = None ,
172
217
)
173
218
ev = SomeEffect ()
174
- self .assertFalse (ev .apply (ctr ))
175
219
self .assertEqual (
176
- str (ctr ),
177
- (
178
- "Causal Test Result\n ==============\n "
179
- "Treatment: A\n "
180
- "Control value: 0\n "
181
- "Treatment value: 1\n "
182
- "Outcome: A\n "
183
- "Adjustment set: set()\n "
184
- "ate: 0\n "
185
- "Confidence intervals: [-0.1, 0.2]\n "
186
- ),
220
+ ctr .to_dict (),
221
+ {
222
+ "treatment" : "A" ,
223
+ "control_value" : 0 ,
224
+ "treatment_value" : 1 ,
225
+ "outcome" : "A" ,
226
+ "adjustment_set" : set (),
227
+ "test_value" : test_value ,
228
+ "ci_low" : - 0.1 ,
229
+ "ci_high" : 0.2 ,
230
+ },
231
+ )
232
+
233
+ def test_someEffect_dict (self ):
234
+ test_value = TestValue (type = "ate" , value = 0 )
235
+ ctr = CausalTestResult (
236
+ estimator = self .estimator ,
237
+ test_value = test_value ,
238
+ confidence_intervals = [- 0.1 , 0.2 ],
239
+ effect_modifier_configuration = None ,
187
240
)
241
+ ev = SomeEffect ()
188
242
self .assertEqual (
189
243
ctr .to_dict (),
190
244
{
0 commit comments