(patch) fix incoming algorithm -- inverted boolean (#7)
All checks were successful
/ Build and Release Library (push) Successful in 2m31s
All checks were successful
/ Build and Release Library (push) Successful in 2m31s
Reviewed-on: #7
This commit is contained in:
parent
ebd7d98ebb
commit
c297f2f2ca
2 changed files with 28 additions and 1 deletions
|
|
@ -32,7 +32,7 @@ final class Adjacency(val neighbors: Vector[Vector[Vertex]]):
|
||||||
if vertex.ordinal >= neighbors.length then Vector.empty
|
if vertex.ordinal >= neighbors.length then Vector.empty
|
||||||
else
|
else
|
||||||
neighbors.zipWithIndex
|
neighbors.zipWithIndex
|
||||||
.filterNot {
|
.filter {
|
||||||
// ignore the neighbors of the input vertex
|
// ignore the neighbors of the input vertex
|
||||||
case (_, index) => index != vertex.ordinal
|
case (_, index) => index != vertex.ordinal
|
||||||
}
|
}
|
||||||
|
|
|
||||||
27
modules/core/src/test/scala/gs/graph/v0/AdjacencyTests.scala
Normal file
27
modules/core/src/test/scala/gs/graph/v0/AdjacencyTests.scala
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
package gs.graph.v0
|
||||||
|
|
||||||
|
class AdjacencyTests extends munit.FunSuite:
|
||||||
|
|
||||||
|
test("should provide incoming") {
|
||||||
|
val N = Size(7)
|
||||||
|
val vs = (0 until N.value).map(Vertex(_)).toArray
|
||||||
|
val E = List(
|
||||||
|
Edge(vs(0), vs(1)),
|
||||||
|
Edge(vs(0), vs(2)),
|
||||||
|
Edge(vs(0), vs(3)),
|
||||||
|
Edge(vs(1), vs(4)),
|
||||||
|
Edge(vs(2), vs(4)),
|
||||||
|
Edge(vs(3), vs(4)),
|
||||||
|
Edge(vs(3), vs(5)),
|
||||||
|
Edge(vs(4), vs(6))
|
||||||
|
)
|
||||||
|
val A = Adjacency.fromDirectedEdges(N, E)
|
||||||
|
|
||||||
|
assertEquals(A.incoming(vs(0)), Vector.empty)
|
||||||
|
assertEquals(A.incoming(vs(1)), Vector(vs(0)))
|
||||||
|
assertEquals(A.incoming(vs(2)), Vector(vs(0)))
|
||||||
|
assertEquals(A.incoming(vs(3)), Vector(vs(0)))
|
||||||
|
assertEquals(A.incoming(vs(4)), Vector(vs(1), vs(2), vs(3)))
|
||||||
|
assertEquals(A.incoming(vs(5)), Vector(vs(3)))
|
||||||
|
assertEquals(A.incoming(vs(6)), Vector(vs(4)))
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue