-
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
4 changed files
with
213 additions
and
133 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
80 changes: 78 additions & 2 deletions
80
...src/test/scala/kpn/server/analyzer/engine/monitor/MonitorRouteStructureAnalyzerTest.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 |
---|---|---|
@@ -1,13 +1,89 @@ | ||
package kpn.server.analyzer.engine.monitor | ||
|
||
import kpn.api.common.SharedTestObjects | ||
import kpn.api.custom.Relation | ||
import kpn.core.util.UnitTest | ||
import kpn.server.analyzer.engine.analysis.caseStudies.CaseStudy | ||
|
||
class MonitorRouteStructureAnalyzerTest extends UnitTest { | ||
class MonitorRouteStructureAnalyzerTest extends UnitTest with SharedTestObjects { | ||
|
||
test("relation") { | ||
ignore("simulation") { | ||
val relation = CaseStudy.load("/case-studies/monitor/4840541.xml") | ||
println(s"relation.members.size=${relation.members.size}") | ||
new MonitorRouteStructureAnalyzer().analyzeRoute(relation) | ||
} | ||
|
||
test("simple route 3 ways") { | ||
val relation = new MonitorRouteTestData() { | ||
memberWay(10, "", 1, 2, 3) | ||
memberWay(11, "", 3, 4, 5) | ||
memberWay(12, "", 5, 6, 7) | ||
}.relation | ||
|
||
analyze(relation).shouldMatchTo( | ||
Seq( | ||
Seq(1, 2, 3, 4, 5, 6, 7) | ||
) | ||
) | ||
} | ||
|
||
test("simple route 3 ways - first way reversed") { | ||
val relation = new MonitorRouteTestData() { | ||
memberWay(10, "", 3, 2, 1) | ||
memberWay(11, "", 3, 4, 5) | ||
memberWay(12, "", 5, 6, 7) | ||
}.relation | ||
|
||
analyze(relation).shouldMatchTo( | ||
Seq( | ||
Seq(1, 2, 3, 4, 5, 6, 7) | ||
) | ||
) | ||
} | ||
|
||
test("simple route 3 ways - second and third way reversed") { | ||
val relation = new MonitorRouteTestData() { | ||
memberWay(10, "", 1, 2, 3) | ||
memberWay(11, "", 5, 4, 3) | ||
memberWay(12, "", 7, 6, 5) | ||
}.relation | ||
|
||
analyze(relation).shouldMatchTo( | ||
Seq( | ||
Seq(1, 2, 3, 4, 5, 6, 7) | ||
) | ||
) | ||
} | ||
|
||
test("gaps") { | ||
val relation = new MonitorRouteTestData() { | ||
memberWay(10, "", 1, 2) | ||
memberWay(11, "", 3, 4) | ||
memberWay(12, "", 4, 5) | ||
memberWay(13, "", 6, 7) | ||
memberWay(14, "", 7, 8) | ||
}.relation | ||
|
||
analyze(relation).shouldMatchTo( | ||
Seq( | ||
Seq(1, 2), | ||
Seq(3, 4, 5), | ||
Seq(6, 7, 8), | ||
) | ||
) | ||
} | ||
|
||
private def analyze(relation: Relation): Seq[Seq[Long]] = { | ||
val segments = new MonitorRouteStructureAnalyzer().analyzeRoute(relation) | ||
segments.map { segment => | ||
segment.zipWithIndex.flatMap { case (routeWay, index) => | ||
if (index == 0) { | ||
routeWay.nodeIds | ||
} | ||
else { | ||
routeWay.nodeIds.tail | ||
} | ||
} | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
server/src/test/scala/kpn/server/analyzer/engine/monitor/MonitorRouteTestData.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,67 @@ | ||
package kpn.server.analyzer.engine.monitor | ||
|
||
import kpn.api.common.SharedTestObjects | ||
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.custom.Relation | ||
import kpn.api.custom.Tags | ||
import kpn.core.data.DataBuilder | ||
|
||
import scala.collection.mutable.ListBuffer | ||
|
||
class MonitorRouteTestData 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 = { | ||
addNodesIfMissing(nodeIds) | ||
memberWay(wayId, Tags.from("highway" -> "road"), 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 relation: Relation = { | ||
val relation = newRawRelation(1, members = memberBuffer.toSeq) | ||
val rawData = RawData(None, nodeBuffer.toSeq, wayBuffer.toSeq, Seq(relation)) | ||
new DataBuilder(rawData).data.relations(1) | ||
} | ||
} |