-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
270 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
server/src/main/java/kpn/server/analyzer/engine/monitor/structure/StructurePathElement.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package kpn.server.analyzer.engine.monitor.structure | ||
|
||
case class StructurePathElement( | ||
element: StructureElement, | ||
reversed: Boolean | ||
) { | ||
|
||
def nodeIds: Seq[Long] = { | ||
if (reversed) { | ||
element.nodeIds.reverse | ||
} | ||
else { | ||
element.nodeIds | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...er/src/test/scala/kpn/server/analyzer/engine/monitor/structure/StructureElementTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package kpn.server.analyzer.engine.monitor.structure | ||
|
||
import kpn.core.util.UnitTest | ||
|
||
class StructureElementTest extends UnitTest { | ||
|
||
test("element") { | ||
pending | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...r/src/test/scala/kpn/server/analyzer/engine/monitor/structure/StructureFragmentTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package kpn.server.analyzer.engine.monitor.structure | ||
|
||
import kpn.api.common.data.Way | ||
import kpn.core.util.UnitTest | ||
|
||
class StructureFragmentTest extends UnitTest { | ||
|
||
test("reversed false") { | ||
|
||
val way = setupWay() | ||
val fragment = StructureFragment(way, reversed = false) | ||
|
||
fragment.nodeIds.shouldMatchTo(Seq(1, 2, 3)) | ||
fragment.startNode.id.shouldEqual(1) | ||
fragment.endNode.id.shouldEqual(3) | ||
fragment.string.shouldEqual("(11) 1>3") | ||
} | ||
|
||
test("reversed true") { | ||
|
||
val way = setupWay() | ||
val fragment = StructureFragment(way, reversed = true) | ||
|
||
fragment.nodeIds.shouldMatchTo(Seq(3, 2, 1)) | ||
fragment.startNode.id.shouldEqual(3) | ||
fragment.endNode.id.shouldEqual(1) | ||
fragment.string.shouldEqual("(11) 3>1*") | ||
} | ||
|
||
private def setupWay(): Way = { | ||
val setup = new StructureTestSetupBuilder() { | ||
memberWay(11, "", 1, 2, 3) | ||
}.build | ||
setup.data.ways(11) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
server/src/test/scala/kpn/server/analyzer/engine/monitor/structure/StructurePathTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package kpn.server.analyzer.engine.monitor.structure | ||
|
||
import kpn.core.util.UnitTest | ||
|
||
class StructurePathTest extends UnitTest { | ||
|
||
test("path") { | ||
|
||
val setup = new StructureTestSetupBuilder() { | ||
memberWay(11, "", 1, 2, 3) | ||
}.build | ||
val way = setup.data.ways(11) | ||
|
||
val element = StructurePathElement( | ||
element = StructureElement( | ||
id = 1, | ||
fragments = Seq( | ||
StructureFragment( | ||
way, | ||
reversed = false | ||
) | ||
), | ||
direction = None, | ||
), | ||
reversed = false | ||
) | ||
|
||
val path = StructurePath( | ||
startNodeId = 1, | ||
endNodeId = 3, | ||
elements = Seq(element) | ||
) | ||
|
||
path.nodeIds.shouldMatchTo(Seq(1, 2, 3)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...c/test/scala/kpn/server/analyzer/engine/monitor/structure/StructureTestSetupBuilder.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package kpn.server.analyzer.engine.monitor.structure | ||
|
||
import kpn.api.common.data.raw.RawData | ||
import kpn.api.common.data.raw.RawMember | ||
import kpn.api.common.data.raw.RawNode | ||
import kpn.api.common.data.raw.RawWay | ||
import kpn.api.common.SharedTestObjects | ||
import kpn.api.custom.Relation | ||
import kpn.api.custom.Tags | ||
import kpn.core.data.Data | ||
import kpn.core.data.DataBuilder | ||
|
||
import scala.collection.mutable.ListBuffer | ||
|
||
class StructureTestSetupBuilder extends SharedTestObjects { | ||
|
||
private val nodeBuffer = ListBuffer[RawNode]() | ||
private val wayBuffer = ListBuffer[RawWay]() | ||
private val memberBuffer = ListBuffer[RawMember]() | ||
|
||
def memberWay(wayId: Long, role: String, nodeIds: Long*): RawMember = { | ||
memberWayWithTags(wayId, role, Tags.from("highway" -> "road"), nodeIds: _*) | ||
} | ||
|
||
def memberWayWithTags(wayId: Long, role: String, tags: Tags, nodeIds: Long*): RawMember = { | ||
addNodesIfMissing(nodeIds) | ||
memberWay(wayId, tags, role, nodeIds: _*) | ||
} | ||
|
||
private def node(id: Long, name: String = "", lattitude: Double = 0, longitude: Double = 0): RawNode = { | ||
rawNode(newRawNode(id, lattitude.toString, longitude.toString, tags = Tags.empty)) | ||
} | ||
|
||
private def rawNode(rawNode: RawNode): RawNode = { | ||
nodeBuffer += rawNode | ||
rawNode | ||
} | ||
|
||
private def way(wayId: Long, nodeIds: Long*): RawWay = { | ||
way(wayId, Tags.empty, nodeIds: _*) | ||
} | ||
|
||
private def way(wayId: Long, tags: Tags, nodeIds: Long*): RawWay = { | ||
addNodesIfMissing(nodeIds) | ||
val w = newRawWay(wayId, nodeIds = nodeIds.toVector, tags = tags) | ||
wayBuffer += w | ||
w | ||
} | ||
|
||
private def memberWay(wayId: Long, tags: Tags, role: String, nodeIds: Long*): RawMember = { | ||
addNodesIfMissing(nodeIds) | ||
way(wayId, tags, nodeIds: _*) | ||
member("way", wayId, role) | ||
} | ||
|
||
private def member(memberType: String, ref: Long, role: String = ""): RawMember = { | ||
val m = RawMember(memberType, ref, if (role.nonEmpty) Some(role) else None) | ||
memberBuffer += m | ||
m | ||
} | ||
|
||
private def addNodesIfMissing(nodeIds: Seq[Long]): Unit = { | ||
val missingNodeIds = nodeIds.toSet -- nodeBuffer.map(_.id).toSet | ||
missingNodeIds.foreach(id => node(id)) | ||
} | ||
|
||
def build: StructureTestSetup = { | ||
val relation = newRawRelation(1, members = memberBuffer.toSeq) | ||
val rawData = RawData(None, nodeBuffer.toSeq, wayBuffer.toSeq, Seq(relation)) | ||
new StructureTestSetup(new DataBuilder(rawData).data) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.