]> git.lizzy.rs Git - rust.git/blob - src/librustc_data_structures/graph/vec_graph/test.rs
introduce a `VecGraph` abstraction that cheaply stores graphs
[rust.git] / src / librustc_data_structures / graph / vec_graph / test.rs
1 #![cfg(test)]
2
3 use super::*;
4
5 fn create_graph() -> VecGraph<usize> {
6     // Create a simple graph
7     //
8     //          5
9     //          |
10     //          V
11     //    0 --> 1 --> 2
12     //          |
13     //          v
14     //          3 --> 4
15     //
16     //    6
17
18     VecGraph::new(
19         7,
20         vec![
21             (0, 1),
22             (1, 2),
23             (1, 3),
24             (3, 4),
25             (5, 1),
26         ],
27     )
28 }
29
30 #[test]
31 fn num_nodes() {
32     let graph = create_graph();
33     assert_eq!(graph.num_nodes(), 7);
34 }
35
36 #[test]
37 fn succesors() {
38     let graph = create_graph();
39     assert_eq!(graph.successors(0), &[1]);
40     assert_eq!(graph.successors(1), &[2, 3]);
41     assert_eq!(graph.successors(2), &[]);
42     assert_eq!(graph.successors(3), &[4]);
43     assert_eq!(graph.successors(4), &[]);
44     assert_eq!(graph.successors(5), &[1]);
45     assert_eq!(graph.successors(6), &[]);
46 }