Did stuff
This commit is contained in:
parent
48c88e800d
commit
84d96f5028
2 changed files with 40 additions and 1 deletions
|
|
@ -15,7 +15,7 @@ final class SCC private (val value: Set[Vertex]):
|
|||
*/
|
||||
override def equals(obj: Any): Boolean =
|
||||
obj match
|
||||
case other: SCC => value.iterator.sameElements(other.value)
|
||||
case other: SCC => value.equals(other.value)
|
||||
case _ => false
|
||||
|
||||
/** @inheritDocs
|
||||
|
|
|
|||
|
|
@ -60,4 +60,43 @@ class TarjansTests extends FunSuite:
|
|||
assertEquals(sccs.toSet, Set(SCC.of(0), SCC.of(1), SCC.of(2)))
|
||||
}
|
||||
|
||||
test("should handle a graph with multiple SCCs") {
|
||||
val n = Size(9)
|
||||
|
||||
// Establish discrete cycles
|
||||
// 0 -> 1 -> 2 -> 0
|
||||
// 3 -> 4 -> 5 -> 3
|
||||
// 6 -> 7 -> 8 -> 6
|
||||
val g = Digraph.fromAdjacency(
|
||||
Adjacency.fromEdges(
|
||||
n,
|
||||
List(
|
||||
// Cycle 1
|
||||
Edge(0, 1),
|
||||
Edge(1, 2),
|
||||
Edge(2, 0),
|
||||
// Cycle 2
|
||||
Edge(3, 4),
|
||||
Edge(4, 5),
|
||||
Edge(5, 3),
|
||||
// Cycle 3
|
||||
Edge(6, 7),
|
||||
Edge(7, 8),
|
||||
Edge(8, 6)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
val sccs = SCC.findAll(g)
|
||||
assertEquals(g.roots, Vector.empty)
|
||||
assertEquals(
|
||||
sccs.toSet,
|
||||
Set(
|
||||
SCC.of(0, 1, 2),
|
||||
SCC.of(3, 4, 5),
|
||||
SCC.of(6, 7, 8)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
end TarjansTests
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue