Skip to content

Commit 7a3dde6

Browse files
Test to_cpdag
1 parent 9a8d506 commit 7a3dde6

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/rust/src/graph/dag.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,4 +1278,26 @@ mod tests {
12781278
assert_eq!(adj[0], vec![2]);
12791279
assert!(adj[1].is_empty());
12801280
}
1281+
1282+
// test to_cpdag
1283+
#[test]
1284+
fn dag_to_cpdag_basic() {
1285+
// Graph: 0 -> 1, 2 -> 1
1286+
let mut reg = EdgeRegistry::new();
1287+
reg.register_builtins().unwrap();
1288+
let d = reg.code_of("-->").unwrap();
1289+
1290+
let mut b = GraphBuilder::new_with_registry(3, true, &reg);
1291+
b.add_edge(0, 1, d).unwrap();
1292+
b.add_edge(2, 1, d).unwrap();
1293+
let dag = Dag::new(Arc::new(b.finalize().unwrap())).unwrap();
1294+
1295+
let cpdag = dag.to_cpdag().unwrap();
1296+
1297+
// Check edges in CPDAG
1298+
// Expect directed edges: 0 -> 1, 2 -> 1
1299+
assert_eq!(cpdag.parents_of(1), vec![0, 2]);
1300+
assert_eq!(cpdag.children_of(0), vec![1]);
1301+
assert_eq!(cpdag.children_of(2), vec![1]);
1302+
}
12811303
}

0 commit comments

Comments
 (0)