Skip to content

Commit 9f14656

Browse files
committed
Add test
1 parent d78cdaf commit 9f14656

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/scc.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,41 @@ impl SccGraph {
2323
}
2424
}
2525

26+
#[cfg(test)]
27+
mod tests {
28+
use super::*;
29+
30+
#[test]
31+
fn test_scc_simple() {
32+
let mut graph = SccGraph::new(2);
33+
graph.add_edge(0, 1);
34+
graph.add_edge(1, 0);
35+
let scc = graph.scc();
36+
assert_eq!(scc.len(), 1);
37+
}
38+
39+
#[test]
40+
fn test_scc_self_loop() {
41+
let mut graph = SccGraph::new(2);
42+
graph.add_edge(0, 0);
43+
graph.add_edge(0, 0);
44+
graph.add_edge(1, 1);
45+
let scc = graph.scc();
46+
assert_eq!(scc.len(), 2);
47+
}
48+
49+
#[test]
50+
fn solve_alpc_scc_sample1() {
51+
// https://atcoder.jp/contests/practice2/tasks/practice2_g
52+
let n: usize = 6;
53+
let edges = vec![(1, 4), (5, 2), (3, 0), (5, 5), (4, 1), (0, 3), (4, 2)];
54+
55+
let mut graph = SccGraph::new(n);
56+
for (u, v) in edges.into_iter() {
57+
graph.add_edge(u, v);
58+
}
59+
60+
let scc = graph.scc();
61+
assert_eq!(scc, vec![vec![5], vec![1, 4], vec![2], vec![0, 3]]);
62+
}
63+
}

0 commit comments

Comments
 (0)