Did stuff

This commit is contained in:
Pat Garrity 2026-04-14 22:50:07 -05:00
parent 48c88e800d
commit 84d96f5028
Signed by: pfm
GPG key ID: 5CA5D21BAB7F3A76
2 changed files with 40 additions and 1 deletions

View file

@ -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

View file

@ -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