Skip to content

Commit c57ef29

Browse files
committed
Add unit tests for minimal_scc_representative
1 parent 2d5e80b commit c57ef29

File tree

1 file changed

+41
-0
lines changed
  • compiler/rustc_data_structures/src/transitive_relation

1 file changed

+41
-0
lines changed

compiler/rustc_data_structures/src/transitive_relation/tests.rs

+41
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,44 @@ fn parent() {
376376
let p = relation.postdom_parent(3);
377377
assert_eq!(p, Some(0));
378378
}
379+
380+
#[test]
381+
fn minimal_scc_representative_1() {
382+
// +---------+
383+
// v |
384+
// a -> c -> d -> e
385+
// ^ ^
386+
// | |
387+
// b ---+
388+
389+
// "digraph { a -> c -> d -> e -> c; b -> d; b -> e; }",
390+
let mut relation = TransitiveRelationBuilder::default();
391+
relation.add("a", "c");
392+
relation.add("c", "d");
393+
relation.add("d", "e");
394+
relation.add("e", "c");
395+
relation.add("b", "d");
396+
relation.add("b", "e");
397+
let relation = relation.freeze();
398+
399+
assert_eq!(relation.minimal_scc_representative("a"), "a");
400+
assert_eq!(relation.minimal_scc_representative("b"), "b");
401+
assert_eq!(relation.minimal_scc_representative("c"), "c");
402+
assert_eq!(relation.minimal_scc_representative("d"), "c");
403+
assert_eq!(relation.minimal_scc_representative("e"), "c");
404+
}
405+
406+
#[test]
407+
fn minimal_scc_representative_2() {
408+
// "digraph { a -> b; a -> a; b -> a; c -> c}",
409+
let mut relation = TransitiveRelationBuilder::default();
410+
relation.add("a", "b");
411+
relation.add("b", "a");
412+
relation.add("a", "a");
413+
relation.add("c", "c");
414+
let relation = relation.freeze();
415+
416+
assert_eq!(relation.minimal_scc_representative("a"), "a");
417+
assert_eq!(relation.minimal_scc_representative("b"), "a");
418+
assert_eq!(relation.minimal_scc_representative("c"), "c");
419+
}

0 commit comments

Comments
 (0)