From 84d96f50284fc3b232719356f573e41dd07f8995 Mon Sep 17 00:00:00 2001 From: Pat Garrity Date: Tue, 14 Apr 2026 22:50:07 -0500 Subject: [PATCH] Did stuff --- .../core/src/main/scala/gs/graph/v0/SCC.scala | 2 +- .../test/scala/gs/graph/v0/TarjansTests.scala | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/scala/gs/graph/v0/SCC.scala b/modules/core/src/main/scala/gs/graph/v0/SCC.scala index b768de2..7e1b6b2 100644 --- a/modules/core/src/main/scala/gs/graph/v0/SCC.scala +++ b/modules/core/src/main/scala/gs/graph/v0/SCC.scala @@ -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 diff --git a/modules/core/src/test/scala/gs/graph/v0/TarjansTests.scala b/modules/core/src/test/scala/gs/graph/v0/TarjansTests.scala index b5ec1e6..3387cdb 100644 --- a/modules/core/src/test/scala/gs/graph/v0/TarjansTests.scala +++ b/modules/core/src/test/scala/gs/graph/v0/TarjansTests.scala @@ -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