]> git.lizzy.rs Git - rust.git/blob - src/librustc_data_structures/graph/vec_graph/tests.rs
Rollup merge of #68504 - tmiasko:check-pass, r=alexcrichton
[rust.git] / src / librustc_data_structures / graph / vec_graph / tests.rs
1 use super::*;
2
3 fn create_graph() -> VecGraph<usize> {
4     // Create a simple graph
5     //
6     //          5
7     //          |
8     //          V
9     //    0 --> 1 --> 2
10     //          |
11     //          v
12     //          3 --> 4
13     //
14     //    6
15
16     VecGraph::new(7, vec![(0, 1), (1, 2), (1, 3), (3, 4), (5, 1)])
17 }
18
19 #[test]
20 fn num_nodes() {
21     let graph = create_graph();
22     assert_eq!(graph.num_nodes(), 7);
23 }
24
25 #[test]
26 fn succesors() {
27     let graph = create_graph();
28     assert_eq!(graph.successors(0), &[1]);
29     assert_eq!(graph.successors(1), &[2, 3]);
30     assert_eq!(graph.successors(2), &[]);
31     assert_eq!(graph.successors(3), &[4]);
32     assert_eq!(graph.successors(4), &[]);
33     assert_eq!(graph.successors(5), &[1]);
34     assert_eq!(graph.successors(6), &[]);
35 }
36
37 #[test]
38 fn dfs() {
39     let graph = create_graph();
40     let dfs: Vec<_> = graph.depth_first_search(0).collect();
41     assert_eq!(dfs, vec![0, 1, 3, 4, 2]);
42 }