]> git.lizzy.rs Git - rust.git/blob - src/librustc_data_structures/graph/vec_graph/test.rs
97a9bd2ad0b08c74fb5528ddcef46aab09669409
[rust.git] / src / librustc_data_structures / graph / vec_graph / test.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(
17         7,
18         vec![
19             (0, 1),
20             (1, 2),
21             (1, 3),
22             (3, 4),
23             (5, 1),
24         ],
25     )
26 }
27
28 #[test]
29 fn num_nodes() {
30     let graph = create_graph();
31     assert_eq!(graph.num_nodes(), 7);
32 }
33
34 #[test]
35 fn succesors() {
36     let graph = create_graph();
37     assert_eq!(graph.successors(0), &[1]);
38     assert_eq!(graph.successors(1), &[2, 3]);
39     assert_eq!(graph.successors(2), &[]);
40     assert_eq!(graph.successors(3), &[4]);
41     assert_eq!(graph.successors(4), &[]);
42     assert_eq!(graph.successors(5), &[1]);
43     assert_eq!(graph.successors(6), &[]);
44 }
45
46 #[test]
47 fn dfs() {
48     let graph = create_graph();
49     let dfs: Vec<_> = graph.depth_first_search(0).collect();
50     assert_eq!(dfs, vec![0, 1, 3, 4, 2]);
51 }