Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove ExampleGraphSetup, port RepeatTraversalTests to generated domains #187

Merged
merged 3 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ final class AccessNeighborsForNodeA(val node: nodes.NodeA) extends AnyVal {
*/
def nodeAViaConnectedToIn: Iterator[nodes.NodeA] = connectedToIn.collectAll[nodes.NodeA]

/** Traverse to node_a via connected_to OUT edge.
/** Connected neighbor node Traverse to node_a via connected_to OUT edge.
*/
@deprecated("please use connectedTo instead")
def nodeAViaConnectedToOut: Iterator[nodes.NodeA] = connectedTo

/** Traverse to node_a via connected_to OUT edge.
/** Connected neighbor node Traverse to node_a via connected_to OUT edge.
*/
def connectedTo: Iterator[nodes.NodeA] = connectedToOut.collectAll[nodes.NodeA]

Expand All @@ -29,11 +29,11 @@ final class AccessNeighborsForNodeATraversal(val traversal: Iterator[nodes.NodeA
*/
def nodeAViaConnectedToIn: Iterator[nodes.NodeA] = traversal.flatMap(_.nodeAViaConnectedToIn)

/** Traverse to node_a via connected_to OUT edge.
/** Connected neighbor node Traverse to node_a via connected_to OUT edge.
*/
def connectedTo: Iterator[nodes.NodeA] = traversal.flatMap(_.connectedTo)

/** Traverse to node_a via connected_to OUT edge.
/** Connected neighbor node Traverse to node_a via connected_to OUT edge.
*/
@deprecated("please use connectedTo instead")
def nodeAViaConnectedToOut: Iterator[nodes.NodeA] = traversal.flatMap(_.nodeAViaConnectedToOut)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object Schema {

// TODO add support for edge properties with cardinality ONE and LIST
val connectedTo = builder.addEdgeType("connected_to").addProperty(stringMandatory)
nodeA.addOutEdge(connectedTo, nodeA, stepNameOut = "connectedTo")
nodeA.addOutEdge(connectedTo, nodeA, stepNameOut = "connectedTo", stepNameOutDoc = "Connected neighbor node")

builder.build
}
Expand Down
21 changes: 19 additions & 2 deletions tests/src/test/scala/flatgraph/TestGraphs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package flatgraph
import flatgraph.testdomains.generic.GenericDomain
import flatgraph.testdomains.generic.edges.ConnectedTo
import flatgraph.testdomains.generic.nodes.NewNodeA
import flatgraph.testdomains.generic.Language.*

import java.nio.file.Path

Expand Down Expand Up @@ -32,8 +33,7 @@ object TestGraphs {
genericDomain
}

/** L3 <- L2 <- L1 <- Center -> R1 -> R2 -> R3 -> R4 -> R5
*/
/** L3 <- L2 <- L1 <- Center -> R1 -> R2 -> R3 -> R4 -> R5 */
def createFlatlineGraph(): GenericDomain = {
val genericDomain = GenericDomain.empty
val diffGraph = GenericDomain.newDiffGraphBuilder
Expand Down Expand Up @@ -74,4 +74,21 @@ object TestGraphs {
genericDomain
}

/** L3 <- L2 <- L1 <- Center -> R1 -> R2 -> R3 -> R4 -> R5 */
trait FlatlineGraphFixture {
val genericDomain = TestGraphs.createFlatlineGraph()
val Seq(center, l1, l2, l3, r1, r2, r3, r4, r5) = genericDomain.nodeA.sortBy(_.stringMandatory).l

// verify graph setup
assert(center.stringMandatory == "Center")
assert(l1.stringMandatory == "L1")
assert(l2.stringMandatory == "L2")
assert(l3.stringMandatory == "L3")
assert(r1.stringMandatory == "R1")
assert(r2.stringMandatory == "R2")
assert(r3.stringMandatory == "R3")
assert(r4.stringMandatory == "R4")
assert(r5.stringMandatory == "R5")
}

}
24 changes: 5 additions & 19 deletions tests/src/test/scala/flatgraph/algorithm/PathFinderTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,17 @@ package flatgraph.algorithm

import flatgraph.Edge.Direction
import flatgraph.TestGraphs
import flatgraph.TestGraphs.FlatlineGraphFixture
import flatgraph.algorithm.PathFinder.*
import flatgraph.testdomains.generic.Language.*
import flatgraph.testdomains.generic.edges.ConnectedTo
import org.scalatest.matchers.should.Matchers.*
import org.scalatest.wordspec.AnyWordSpec

class PathFinderTests extends AnyWordSpec {

/* sample graph:
* L3 <- L2 <- L1 <- Center -> R1 -> R2 -> R3 -> R4 -> R5
*/
val flatlineGraph = TestGraphs.createFlatlineGraph()
val Seq(center, l1, l2, l3, r1, r2, r3, r4, r5) = flatlineGraph.nodeA.sortBy(_.stringMandatory).l

"verify graph setup" in {
center.stringMandatory shouldBe "Center"
l1.stringMandatory shouldBe "L1"
l2.stringMandatory shouldBe "L2"
l3.stringMandatory shouldBe "L3"
r1.stringMandatory shouldBe "R1"
r2.stringMandatory shouldBe "R2"
r3.stringMandatory shouldBe "R3"
r4.stringMandatory shouldBe "R4"
r5.stringMandatory shouldBe "R5"
}
/* uses 'flat line' sample graph:
* L3 <- L2 <- L1 <- Center -> R1 -> R2 -> R3 -> R4 -> R5
*/
class PathFinderTests extends AnyWordSpec with FlatlineGraphFixture {

"identity" in {
val path = PathFinder(center, center)
Expand Down
Loading
Loading