]> git.proxmox.com Git - rustc.git/blobdiff - compiler/rustc_data_structures/src/graph/iterate/tests.rs
New upstream version 1.57.0+dfsg1
[rustc.git] / compiler / rustc_data_structures / src / graph / iterate / tests.rs
index 0e038e88b221dfed3f8d3b6aabbdb0b272d9ab96..c498c289337f1a1eebe77955943ab88812ae2b9c 100644 (file)
@@ -20,3 +20,19 @@ fn is_cyclic() {
     assert!(!is_cyclic(&diamond_acyclic));
     assert!(is_cyclic(&diamond_cyclic));
 }
+
+#[test]
+fn dfs() {
+    let graph = TestGraph::new(0, &[(0, 1), (0, 2), (1, 3), (2, 3), (3, 0)]);
+
+    let result: Vec<usize> = DepthFirstSearch::new(&graph).with_start_node(0).collect();
+    assert_eq!(result, vec![0, 2, 3, 1]);
+}
+
+#[test]
+fn dfs_debug() {
+    let graph = TestGraph::new(0, &[(0, 1), (0, 2), (1, 3), (2, 3), (3, 0)]);
+    let mut dfs = DepthFirstSearch::new(&graph).with_start_node(0);
+    dfs.complete_search();
+    assert_eq!(format!("{{0, 1, 2, 3}}"), format!("{:?}", dfs));
+}