]>
Commit | Line | Data |
---|---|---|
416331ca | 1 | use super::super::tests::TestGraph; |
3157f602 XL |
2 | |
3 | use super::*; | |
4 | ||
5 | #[test] | |
6 | fn diamond_post_order() { | |
c30ab7b3 | 7 | let graph = TestGraph::new(0, &[(0, 1), (0, 2), (1, 3), (2, 3)]); |
3157f602 XL |
8 | |
9 | let result = post_order_from(&graph, 0); | |
10 | assert_eq!(result, vec![3, 1, 2, 0]); | |
11 | } | |
e74abb32 XL |
12 | |
13 | #[test] | |
14 | fn is_cyclic() { | |
15 | use super::super::is_cyclic; | |
16 | ||
17 | let diamond_acyclic = TestGraph::new(0, &[(0, 1), (0, 2), (1, 3), (2, 3)]); | |
18 | let diamond_cyclic = TestGraph::new(0, &[(0, 1), (1, 2), (2, 3), (3, 0)]); | |
19 | ||
20 | assert!(!is_cyclic(&diamond_acyclic)); | |
21 | assert!(is_cyclic(&diamond_cyclic)); | |
22 | } | |
c295e0f8 XL |
23 | |
24 | #[test] | |
25 | fn dfs() { | |
26 | let graph = TestGraph::new(0, &[(0, 1), (0, 2), (1, 3), (2, 3), (3, 0)]); | |
27 | ||
28 | let result: Vec<usize> = DepthFirstSearch::new(&graph).with_start_node(0).collect(); | |
29 | assert_eq!(result, vec![0, 2, 3, 1]); | |
30 | } | |
31 | ||
32 | #[test] | |
33 | fn dfs_debug() { | |
34 | let graph = TestGraph::new(0, &[(0, 1), (0, 2), (1, 3), (2, 3), (3, 0)]); | |
35 | let mut dfs = DepthFirstSearch::new(&graph).with_start_node(0); | |
36 | dfs.complete_search(); | |
37 | assert_eq!(format!("{{0, 1, 2, 3}}"), format!("{:?}", dfs)); | |
38 | } |