]> git.proxmox.com Git - rustc.git/blame - src/librustc_data_structures/graph/vec_graph/tests.rs
New upstream version 1.43.0+dfsg1
[rustc.git] / src / librustc_data_structures / graph / vec_graph / tests.rs
CommitLineData
dc9dc135
XL
1use super::*;
2
3fn 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
dfeec247 16 VecGraph::new(7, vec![(0, 1), (1, 2), (1, 3), (3, 4), (5, 1)])
dc9dc135
XL
17}
18
19#[test]
20fn num_nodes() {
21 let graph = create_graph();
22 assert_eq!(graph.num_nodes(), 7);
23}
24
25#[test]
74b04a01 26fn successors() {
dc9dc135
XL
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]
38fn 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}