Skip to content

Commit 9c52413

Browse files
Full coverage of adjustment and registry
1 parent 038b199 commit 9c52413

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

tests/testthat/test-adjustment.R

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2432
test_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+
})

tests/testthat/test-registry.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,20 @@ test_that("new edge type, x-x, cannot create duplicate or parallel edges", {
167167

168168
reset_caugi_registry()
169169
})
170+
171+
# ──────────────────────────────────────────────────────────────────────────────
172+
# ─────────────────────────── Is edge symmetric? ───────────────────────────────
173+
# ──────────────────────────────────────────────────────────────────────────────
174+
175+
test_that("is_edge_symmetric errors with non registered glyph", {
176+
reset_caugi_registry()
177+
expect_error(is_edge_symmetric(":o)"), "not registered")
178+
reset_caugi_registry()
179+
})
180+
181+
test_that("is_edge_symmetric works for registered edges", {
182+
reset_caugi_registry()
183+
expect_error(is_edge_symmetric("-->"))
184+
expect_true(is_edge_symmetric("---"))
185+
reset_caugi_registry()
186+
})

0 commit comments

Comments
 (0)