16
16
from causal_testing .specification .variable import Input , Output
17
17
18
18
19
+ def single_input_program_under_test (X1 , Z = None , M = None , Y = None ):
20
+ if Z is None :
21
+ Z = 2 * X1 + - 3
22
+ if M is None :
23
+ M = 3 * Z
24
+ if Y is None :
25
+ Y = M / 2
26
+ return {"X1" : X1 , "Z" : Z , "M" : M , "Y" : Y }
27
+
28
+
19
29
def program_under_test (X1 , X2 , X3 , Z = None , M = None , Y = None ):
20
30
if Z is None :
21
31
Z = 2 * X1 + - 3 * X2 + 10
@@ -36,6 +46,13 @@ def buggy_program_under_test(X1, X2, X3, Z=None, M=None, Y=None):
36
46
return {"X1" : X1 , "X2" : X2 , "X3" : X3 , "Z" : Z , "M" : M , "Y" : Y }
37
47
38
48
49
+ class SingleInputProgramUnderTestEDC (ExperimentalDataCollector ):
50
+ def run_system_with_input_configuration (self , input_configuration : dict ) -> pd .DataFrame :
51
+ results_dict = single_input_program_under_test (** input_configuration )
52
+ results_df = pd .DataFrame (results_dict , index = [0 ])
53
+ return results_df
54
+
55
+
39
56
class ProgramUnderTestEDC (ExperimentalDataCollector ):
40
57
def run_system_with_input_configuration (self , input_configuration : dict ) -> pd .DataFrame :
41
58
results_dict = program_under_test (** input_configuration )
@@ -82,6 +99,20 @@ def test_should_cause_metamorphic_relations_correct_spec(self):
82
99
test_results = should_cause_MR .execute_tests (self .data_collector )
83
100
should_cause_MR .test_oracle (test_results )
84
101
102
+ def test_should_cause_metamorphic_relations_correct_spec_one_input (self ):
103
+ """Test if the ShouldCause MR passes all metamorphic tests where the DAG perfectly represents the program
104
+ and there is only a single input."""
105
+ causal_dag = CausalDAG (self .dag_dot_path )
106
+ self .data_collector = SingleInputProgramUnderTestEDC (
107
+ self .scenario , self .default_control_input_config , self .default_treatment_input_config
108
+ )
109
+ causal_dag .graph .remove_nodes_from (['X2' , 'X3' ])
110
+ adj_set = list (causal_dag .direct_effect_adjustment_sets (['X1' ], ['Z' ])[0 ])
111
+ should_cause_MR = ShouldCause ('X1' , 'Z' , adj_set , causal_dag )
112
+ should_cause_MR .generate_follow_up (10 , - 10.0 , 10.0 , 1 )
113
+ test_results = should_cause_MR .execute_tests (self .data_collector )
114
+ should_cause_MR .test_oracle (test_results )
115
+
85
116
def test_should_not_cause_metamorphic_relations_correct_spec (self ):
86
117
"""Test if the ShouldNotCause MR passes all metamorphic tests where the DAG perfectly represents the program."""
87
118
causal_dag = CausalDAG (self .dag_dot_path )
0 commit comments