Skip to content

Commit

Permalink
#368 migrate structure tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarc committed Jul 13, 2024
1 parent 4e1070d commit ba18e3f
Show file tree
Hide file tree
Showing 68 changed files with 489 additions and 1,057 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,12 @@ class RouteStructureAnalyzer(context: RouteDetailAnalysisContext) {

def analyze: RouteDetailAnalysisContext = {

val structure = new StructureAnalyzer().analyze(
context.segments,
context.routeNodeAnalysis,
context.paths
)
val structure = new StructureAnalyzer(context).analyze()

val oneWayRouteForward = context.relation.hasTag("direction", "forward")
val oneWayRouteBackward = context.relation.hasTag("direction", "backward")

val oneWayRoute = context.relation.tags.exists { tag =>
(tag.key == "comment" && tag.value.contains("to be used in one direction")) ||
(tag.key == "oneway" && tag.value == "yes") ||
(tag.key == "signed_direction" && tag.value == "yes")
}
val oneWayRoute = context.relation.hasTag("oneway", "yes") || context.relation.hasTag("signed_direction", "yes")

val hasValidForwardPath = structure.forwardPath.isDefined // TODO redesign && !structure.forwardPath.exists(_.broken)
val hasValidBackwardPath = structure.backwardPath.isDefined // TODO redesign && !structure.backwardPath.exists(_.broken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@ case class NewRouteSegmentElement(
fragments: Seq[NewRouteSegmentElementFragment]
) {
def nodeIds: Seq[Long] = {
val ids = fragments.headOption match {
fragments.headOption match {
case Some(firstLink) => firstLink.nodeIds ++ fragments.tail.flatMap(link => link.nodeIds.tail)
case None => Seq.empty
}
if (direction == RoutePathDirection.Backward) {
ids.reverse
}
else {
ids
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ case class RoutePath(
direction: RoutePathDirection,
elements: Seq[NewRouteSegmentElement]
) {

if (elements.isEmpty || elements.size > 1) {
throw new RuntimeException("UNEXPECTED !!!")
}

def nodeIds: Seq[Long] = {
val ids: Seq[Long] = elements.headOption match {
case Some(firstElement) => firstElement.nodeIds ++ elements.tail.flatMap(_.nodeIds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,21 @@ class RoutePathAnalyzer(context: RouteDetailAnalysisContext) {
private val pathIds = Util.ids

def analyze(): Seq[RoutePath] = {
val paths = context.segments.flatMap { segment =>
findPaths(segment.elements)
}
val pathSegmentElementIds = paths.flatMap(_.elements.map(_.id))
val otherSegmentElements = context.segments.flatMap(_.elements).filterNot(el => pathSegmentElementIds.contains(el.id))
val otherPaths = otherSegmentElements.map { element =>
RoutePath(pathIds.next(), element.direction, Seq(element))
context.segments.flatMap { segment =>
segment.elements.map { element =>
RoutePath(pathIds.next(), element.direction, Seq(element))
}
}

paths ++ otherPaths
// val paths = context.segments.flatMap { segment =>
// findPaths(segment.elements)
// }
// val pathSegmentElementIds = paths.flatMap(_.elements.map(_.id))
// val otherSegmentElements = context.segments.flatMap(_.elements).filterNot(el => pathSegmentElementIds.contains(el.id))
// val otherPaths = otherSegmentElements.map { element =>
// RoutePath(pathIds.next(), element.direction, Seq(element))
// }
//
// paths ++ otherPaths
}

private def findPaths(remainingElements: Seq[NewRouteSegmentElement]): Seq[RoutePath] = {
Expand Down
Loading

0 comments on commit ba18e3f

Please sign in to comment.