@@ -19,6 +19,14 @@ test_that("d-separation checks", {
1919 expect_false(d_separated(adjustment_set_cg , " X" , " Y" , Z = " D" )) # backdoor still open
2020 expect_true(d_separated(adjustment_set_cg , " X" , " Y" , Z = c(" A" , " D" ))) # backdoor and causal both blocked
2121 expect_true(d_separated(adjustment_set_cg , " X" , " Y" , Z = c(" K" , " D" ))) # backdoor and causal both blocked
22+
23+ # now with indexes
24+ expect_false(d_separated(adjustment_set_cg , X_index = 2L , Y_index = 6L )) # backdoor via A-->K-->Y and causal X-->D-->Y
25+ expect_false(d_separated(adjustment_set_cg , X_index = 2L , Y_index = 6L , Z_index = 3L )) # causal path still open
26+ expect_false(d_separated(adjustment_set_cg , X_index = 2L , Y_index = 6L , Z_index = 4L )) # causal path still open
27+ expect_false(d_separated(adjustment_set_cg , X_index = 2L , Y_index = 6L , Z_index = 5L )) # backdoor still open
28+ expect_true(d_separated(adjustment_set_cg , X_index = 2L , Y_index = 6L , Z_index = c(3L , 5L )))
29+ expect_true(d_separated(adjustment_set_cg , X_index = 2L , Y_index = 6L , Z_index = c(4L , 5L )))
2230})
2331
2432test_that(" adjustment_set(type = 'parents') returns Pa(X) \\ {X,Y}" , {
@@ -93,3 +101,37 @@ test_that("all_backdoor_sets includes empty set, if valid", {
93101 )
94102 expect_setequal(sets , valid_sets )
95103})
104+
105+ test_that(" adjustment functions cannot take multiple inputs" , {
106+ expect_error(
107+ adjustment_set(adjustment_set_cg , X = c(" X" , " A" ), Y = " Y" , type = " parents" ),
108+ " Provide exactly one X and one Y."
109+ )
110+ expect_error(
111+ is_valid_backdoor(adjustment_set_cg , X = " X" , Y = c(" Y" , " D" ), Z = " A" ),
112+ " Provide exactly one X and one Y."
113+ )
114+ expect_error(
115+ all_backdoor_sets(adjustment_set_cg , X = " X" , Y = c(" Y" , " D" )),
116+ " Provide exactly one X and one Y."
117+ )
118+ expect_error(
119+ d_separated(adjustment_set_cg , X_index = c(1L , 2L ), Y = " Y" , Z = " A" ),
120+ " Provide exactly one X and one Y."
121+ )
122+ })
123+
124+ test_that(" adjust functions fails with faulty input" , {
125+ expect_error(
126+ adjustment_set(adjustment_set_cg , X = " X" , Y = NULL , type = " parents" ),
127+ " Either the node name or the node index must be provided"
128+ )
129+ expect_error(
130+ adjustment_set(adjustment_set_cg , X = " X" , Y = " Y" , Y_index = 6L , type = " parent" ),
131+ " Provide either a node name or node index"
132+ )
133+ expect_error(
134+ d_separated(adjustment_set_cg , X = " X" , Y = " Y" , Z = " A" , Z_index = 3L ),
135+ " Provide either a node name or node index"
136+ )
137+ })
0 commit comments