Skip to content

Commit

Permalink
back to DebugDump.debugDump
Browse files Browse the repository at this point in the history
  • Loading branch information
mpollmeier committed Nov 23, 2023
1 parent 85e9c8b commit 3340437
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/flatgraph/misc/DebugDump.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object DebugDump {
}
}

def apply(g: Graph): String = {
def debugDump(g: Graph): String = {
val sb = new java.lang.StringBuilder(0)
val numstr =
g.nodesArray
Expand Down
86 changes: 43 additions & 43 deletions core/src/test/scala/flatgraph/misc/GraphTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package flatgraph

import flatgraph.TestHelpers.withTemporaryFile
import flatgraph.TestSchema.{getClass, testSerialization}
import flatgraph.misc.DebugDump
import flatgraph.misc.DebugDump.debugDump
import flatgraph.storage.{Deserialization, Serialization}
import flatgraph.traversal.Language.*
import org.scalatest.matchers.should.Matchers
Expand All @@ -13,12 +13,12 @@ import java.nio.file.Files

class GraphTests extends AnyWordSpec with Matchers {

// General tip: If a test fails, add println(DebugDump.debugDump(g)) in front, in order to get untruncated "actual" for copy-paste
// General tip: If a test fails, add println(debugDump.debugDump(g)) in front, in order to get untruncated "actual" for copy-paste
"basically work for construction" in {
val schema = TestSchema.make(1, 1)
val g = new Graph(schema)
// empty graph
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 0), total 0
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 0 [NA], 0 [NA]),
|""".stripMargin
Expand All @@ -35,7 +35,7 @@ class GraphTests extends AnyWordSpec with Matchers {
._addEdge(V0_3, V0_0, 0)
._addEdge(V0_1, V0_0, 0)
DiffGraphApplier.applyDiff(g, diff0)
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 4), total 4
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 5 [dense], 5 [dense]),
| V0_0 [0] -> V0_1
Expand All @@ -53,7 +53,7 @@ class GraphTests extends AnyWordSpec with Matchers {
val diff2 = new DiffGraphBuilder(schema)
diff2._addEdge(V0_2, V0_3, 0)
DiffGraphApplier.applyDiff(g, diff2)
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 4), total 4
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 6 [dense], 6 [dense]),
| V0_0 [0] -> V0_1
Expand All @@ -69,7 +69,7 @@ class GraphTests extends AnyWordSpec with Matchers {
// add a node. Don't resize edges array
val V0_4 = new GenericDNode(0)
DiffGraphApplier.applyDiff(g, new DiffGraphBuilder(schema).addNode(V0_4))
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 5), total 5
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 6 [dense], 6 [dense]),
| V0_0 [0] -> V0_1
Expand All @@ -85,7 +85,7 @@ class GraphTests extends AnyWordSpec with Matchers {

// add an interior edge. Check that adding edges in the middle and at the end of undersized edge arrays works
DiffGraphApplier.applyDiff(g, new DiffGraphBuilder(schema)._addEdge(V0_1, V0_4, 0))
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 5), total 5
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 7 [dense], 7 [dense]),
| V0_0 [0] -> V0_1
Expand All @@ -107,7 +107,7 @@ class GraphTests extends AnyWordSpec with Matchers {
val schema = TestSchema.make(3, 2)
val g = new Graph(schema)
// empty graph
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 0), (1: 0), (2: 0), total 0
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 0 [NA], 0 [NA]), (1, 0 [NA], 0 [NA]),
|Node kind 1. (eid, nEdgesOut, nEdgesIn): (0, 0 [NA], 0 [NA]), (1, 0 [NA], 0 [NA]),
Expand All @@ -129,7 +129,7 @@ class GraphTests extends AnyWordSpec with Matchers {
._addEdge(V0_1, V1_0, 0)
._addEdge(V1_1, V0_0, 1)
)
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 2), (1: 2), (2: 0), total 4
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 2 [dense], 1 [dense]), (1, 0 [NA], 1 [dense]),
| V0_0 [0] -> V0_0
Expand Down Expand Up @@ -238,7 +238,7 @@ class GraphTests extends AnyWordSpec with Matchers {
| V0_2 [0] <- V0_0, V0_3
| V0_3 [0] -> V0_2, V0_1
|""".stripMargin
DebugDump(g) shouldBe badGraphDump
debugDump(g) shouldBe badGraphDump
signature(g) shouldBe "+-+-"
val perms = Array(
List(0, 1, 2, 3),
Expand Down Expand Up @@ -278,7 +278,7 @@ class GraphTests extends AnyWordSpec with Matchers {
"permit an edge deletions" in {
// empty
var g = mkGraph()
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 4), total 4
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 7 [dense], 7 [dense]),
| V0_0 [0] -> V0_2, V0_1, V0_3, V0_2, V0_1
Expand All @@ -303,7 +303,7 @@ class GraphTests extends AnyWordSpec with Matchers {
new DiffGraphBuilder(schema)
.removeEdge(Accessors.getEdgesOut(g.nodesArray(0)(0), 0).toList(1))
)
DebugDump(g) shouldBe expectation
debugDump(g) shouldBe expectation

// remove first V0_1<-V0_0, i.e. same edge from the other side
g = mkGraph()
Expand All @@ -312,7 +312,7 @@ class GraphTests extends AnyWordSpec with Matchers {
new DiffGraphBuilder(schema)
.removeEdge(Accessors.getEdgesIn(g.nodesArray(0)(1), 0).toList(0))
)
DebugDump(g) shouldBe expectation
debugDump(g) shouldBe expectation

// remove the edge twice
// remove first V0_1<-V0_0, i.e. same edge from the other side
Expand All @@ -323,13 +323,13 @@ class GraphTests extends AnyWordSpec with Matchers {
.removeEdge(Accessors.getEdgesIn(g.nodesArray(0)(1), 0).toList(0))
.removeEdge(Accessors.getEdgesOut(g.nodesArray(0)(0), 0).toList(1))
)
DebugDump(g) shouldBe expectation
debugDump(g) shouldBe expectation
testSerialization(g)
}

"permit a different edge deletion" in {
var g = mkGraph()
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 4), total 4
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 7 [dense], 7 [dense]),
| V0_0 [0] -> V0_2, V0_1, V0_3, V0_2, V0_1
Expand All @@ -354,20 +354,20 @@ class GraphTests extends AnyWordSpec with Matchers {
new DiffGraphBuilder(schema)
.removeEdge(Accessors.getEdgesOut(g.nodesArray(0)(0), 0).toList(4))
)
DebugDump(g) shouldBe expectation
debugDump(g) shouldBe expectation

g = mkGraph()
DiffGraphApplier.applyDiff(
g,
new DiffGraphBuilder(schema)
.removeEdge(Accessors.getEdgesIn(g.nodesArray(0)(1), 0).toList(2))
)
DebugDump(g) shouldBe expectation
debugDump(g) shouldBe expectation
}

"permit multiple edge deletion" in {
var g = mkGraph()
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 4), total 4
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 7 [dense], 7 [dense]),
| V0_0 [0] -> V0_2, V0_1, V0_3, V0_2, V0_1
Expand All @@ -393,12 +393,12 @@ class GraphTests extends AnyWordSpec with Matchers {
.removeEdge(Accessors.getEdgesOut(g.nodesArray(0)(0), 0).toList(4))
.removeEdge(Accessors.getEdgesIn(g.nodesArray(0)(2), 0).toList(1))
)
DebugDump(g) shouldBe expectation
debugDump(g) shouldBe expectation
}

"permit node deletion" in {
var g = mkGraph()
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 4), total 4
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 7 [dense], 7 [dense]),
| V0_0 [0] -> V0_2, V0_1, V0_3, V0_2, V0_1
Expand All @@ -413,7 +413,7 @@ class GraphTests extends AnyWordSpec with Matchers {
new DiffGraphBuilder(schema)
.removeNode((g.nodesArray(0)(0)))
)
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 4), total 4
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 2 [dense], 2 [dense]),
| V0_1 [0] <- V0_3
Expand All @@ -427,7 +427,7 @@ class GraphTests extends AnyWordSpec with Matchers {
new DiffGraphBuilder(schema)
.removeNode((g.nodesArray(0)(1)))
)
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 4), total 4
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 4 [dense], 4 [dense]),
| V0_0 [0] -> V0_2, V0_3, V0_2
Expand All @@ -445,7 +445,7 @@ class GraphTests extends AnyWordSpec with Matchers {
.removeNode((g.nodesArray(0)(2)))
.removeNode((g.nodesArray(0)(3)))
)
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 4), total 4
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 2 [dense], 2 [dense]),
| V0_0 [0] -> V0_1, V0_1
Expand Down Expand Up @@ -474,7 +474,7 @@ class GraphTests extends AnyWordSpec with Matchers {
._addEdge(V0_1, V0_0, 0, "E")
)

DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 4), total 4
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 6 [dense], 6 [dense]),
| V0_0 [0] -> V0_1, (A) V0_1
Expand All @@ -493,7 +493,7 @@ class GraphTests extends AnyWordSpec with Matchers {
new DiffGraphBuilder(schema)
.setEdgeProperty(Accessors.getEdgesIn(V0_1.storedRef.get, 0)(0), "X")
)
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 4), total 4
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 6 [dense], 6 [dense]),
| V0_0 [0] -> (X) V0_1, (A) V0_1
Expand All @@ -511,7 +511,7 @@ class GraphTests extends AnyWordSpec with Matchers {
new DiffGraphBuilder(schema)
.setEdgeProperty(Accessors.getEdgesIn(V0_1.storedRef.get, 0)(1), DefaultValue)
)
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 4), total 4
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 6 [dense], 6 [dense]),
| V0_0 [0] -> (X) V0_1, V0_1
Expand All @@ -529,7 +529,7 @@ class GraphTests extends AnyWordSpec with Matchers {
new DiffGraphBuilder(schema)
.removeEdge(Accessors.getEdgesIn(V0_1.storedRef.get, 0)(0))
)
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 4), total 4
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 5 [dense], 5 [dense]),
| V0_0 [0] -> V0_1
Expand All @@ -548,7 +548,7 @@ class GraphTests extends AnyWordSpec with Matchers {
new DiffGraphBuilder(schema)
.removeNode(V0_2.storedRef.get)
)
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 4), total 4
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 3 [dense], 3 [dense]),
| V0_0 [0] -> V0_1
Expand All @@ -569,7 +569,7 @@ class GraphTests extends AnyWordSpec with Matchers {
g.neighbors(2).asInstanceOf[DefaultValue].default.getClass.getName shouldBe "java.lang.Short"
DiffGraphApplier.applyDiff(g, new DiffGraphBuilder(schema).addNode(V0_0).addNode(V0_1)._addEdge(V0_0, V0_1, 0)._addEdge(V0_0, V0_1, 0))
g.neighbors(2).asInstanceOf[DefaultValue].default.getClass.getName shouldBe "java.lang.Short"
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 2), total 2
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 2 [dense], 2 [dense]),
| V0_0 [0] -> (-1) V0_1, (-1) V0_1
Expand All @@ -578,15 +578,15 @@ class GraphTests extends AnyWordSpec with Matchers {

DiffGraphApplier.applyDiff(g, new DiffGraphBuilder(schema).setEdgeProperty(Accessors.getEdgesOut(V0_0.storedRef.get, 0)(0), 5.toShort))
g.neighbors(2).getClass.getName shouldBe "[S"
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 2), total 2
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 2 [dense], 2 [dense]),
| V0_0 [0] -> (5) V0_1, (-1) V0_1
| V0_1 [0] <- (5) V0_0, (-1) V0_0
|""".stripMargin

DiffGraphApplier.applyDiff(g, new DiffGraphBuilder(schema)._addEdge(V0_1.storedRef.get, V0_1, 0, 2.toShort))
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 2), total 2
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 3 [dense], 3 [dense]),
| V0_0 [0] -> (5) V0_1, (-1) V0_1
Expand All @@ -598,7 +598,7 @@ class GraphTests extends AnyWordSpec with Matchers {
g,
new DiffGraphBuilder(schema).setEdgeProperty(Accessors.getEdgesOut(V0_0.storedRef.get, 0)(0), DefaultValue)
)
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 2), total 2
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 3 [dense], 3 [dense]),
| V0_0 [0] -> (-1) V0_1, (-1) V0_1
Expand All @@ -618,7 +618,7 @@ class GraphTests extends AnyWordSpec with Matchers {
val V1_0 = new GenericDNode(1)
val V1_1 = new GenericDNode(1)
DiffGraphApplier.applyDiff(g, new DiffGraphBuilder(schema).addNode(V0_0).addNode(V0_1).addNode(V1_0).addNode(V1_1))
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 2), (1: 2), total 4
|Node kind 0. (eid, nEdgesOut, nEdgesIn):
|Node kind 1. (eid, nEdgesOut, nEdgesIn):
Expand All @@ -629,7 +629,7 @@ class GraphTests extends AnyWordSpec with Matchers {
._setNodeProperty(V0_0.storedRef.get, 1, V0_2 :: V0_0 :: Nil)
._setNodeProperty(V1_1.storedRef.get, 0, 0.toShort :: 1.toShort :: Nil)
)
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 3), (1: 2), total 5
|Node kind 0. (eid, nEdgesOut, nEdgesIn):
| V0_0 : 1: [V0_2, V0_0]
Expand All @@ -642,7 +642,7 @@ class GraphTests extends AnyWordSpec with Matchers {
._setNodeProperty(V0_2.storedRef.get, 1, V0_2)
._setNodeProperty(V1_0.storedRef.get, 0, 0.toShort)
)
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 3), (1: 2), total 5
|Node kind 0. (eid, nEdgesOut, nEdgesIn):
| V0_0 : 1: [V0_2, V0_0]
Expand All @@ -659,7 +659,7 @@ class GraphTests extends AnyWordSpec with Matchers {
._setNodeProperty(V1_0.storedRef.get, 0, null)
._setNodeProperty(V0_1.storedRef.get, 1, null :: Nil)
)
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 3), (1: 2), total 5
|Node kind 0. (eid, nEdgesOut, nEdgesIn):
| V0_0 : 1: [<deleted V0_2>, V0_0]
Expand Down Expand Up @@ -701,7 +701,7 @@ class GraphTests extends AnyWordSpec with Matchers {
val schema = TestSchema.make(2, 0, 2, nodePropertyPrototypes = Array(new Array[GNode](0), new Array[String](0)))
val g = new Graph(schema)
DiffGraphApplier.applyDiff(g, new DiffGraphBuilder(schema).addNode(V0_0))
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 3), (1: 0), total 3
|Node kind 0. (eid, nEdgesOut, nEdgesIn):
| V0_0 : 0: [V0_1]
Expand Down Expand Up @@ -732,7 +732,7 @@ class GraphTests extends AnyWordSpec with Matchers {
._setNodeProperty(v1.storedRef.get, 0, "p1")
._setNodeProperty(v3.storedRef.get, 0, "p1" :: "p3" :: Nil)
)
DebugDump(g) shouldBe
debugDump(g) shouldBe
"""#Node numbers (kindId, nnodes) (0: 4), total 4
|Node kind 0. (eid, nEdgesOut, nEdgesIn):
| V0_0 : 0: [p0]
Expand All @@ -757,7 +757,7 @@ class GraphTests extends AnyWordSpec with Matchers {
._setNodeProperty(v2.storedRef.get, 0, "p2")
)
g.inverseIndices.get(0) shouldBe null
// println(DebugDump.debugDump(g))
// println(debugDump.debugDump(g))
}

"write to storage on close and read from storage on open" in {
Expand All @@ -782,7 +782,7 @@ class GraphTests extends AnyWordSpec with Matchers {
._addEdge(V0_1, V1_0, 0)
._addEdge(V1_1, V0_0, 1)
)
val g1Dump = DebugDump(graph1)
val g1Dump = debugDump(graph1)
g1Dump shouldBe
"""#Node numbers (kindId, nnodes) (0: 2), (1: 2), (2: 0), total 4
|Node kind 0. (eid, nEdgesOut, nEdgesIn): (0, 2 [dense], 1 [dense]), (1, 0 [NA], 1 [dense]),
Expand All @@ -803,7 +803,7 @@ class GraphTests extends AnyWordSpec with Matchers {
intercept[GraphClosedException](DiffGraphApplier.applyDiff(graph1, DiffGraphBuilder(schema)))

val graph2 = Graph.withStorage(schema, storagePath)
val g2Dump = DebugDump(graph2)
val g2Dump = debugDump(graph2)
g2Dump shouldBe g1Dump
}
}
Expand Down Expand Up @@ -832,11 +832,11 @@ object TestSchema {
}

def testSerialization(graph: Graph): Unit = {
val orig = DebugDump(graph)
val orig = debugDump(graph)
withTemporaryFile(s"flatgraph-${getClass.getSimpleName}", "fg") { storagePath =>
Serialization.writeGraph(graph, storagePath)
val deserialized = Deserialization.readGraph(storagePath, Option(graph.schema))
val newdump = DebugDump(deserialized)
val newdump = debugDump(deserialized)
// if (newdump != orig) {
// 1 + 1 // for easier breakpoints
// }
Expand Down

0 comments on commit 3340437

Please sign in to comment.