-
Notifications
You must be signed in to change notification settings - Fork 318
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
6 changed files
with
152 additions
and
7 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
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
30 changes: 30 additions & 0 deletions
30
libnavigation-core/src/main/java/com/mapbox/navigation/core/fasterroute/RouteComparator.kt
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,30 @@ | ||
package com.mapbox.navigation.core.fasterroute | ||
|
||
import com.mapbox.api.directions.v5.models.DirectionsRoute | ||
import com.mapbox.navigation.base.trip.model.RouteProgress | ||
|
||
/** | ||
* Compares if an alternative route is different from the current route. | ||
*/ | ||
internal class RouteComparator { | ||
|
||
/** | ||
* @param routeProgress current route progress | ||
* @param alternativeRoute suggested new route | ||
* | ||
* @return true when the alternative route has different | ||
* geometry from the current route progress | ||
*/ | ||
fun isNewRoute(routeProgress: RouteProgress, alternativeRoute: DirectionsRoute): Boolean { | ||
val currentGeometry = routeProgress.route.geometry() ?: "" | ||
val alternativeGeometry = (alternativeRoute.geometry() ?: "").ifEmpty { | ||
return false | ||
} | ||
|
||
return isNewRoute(currentGeometry, alternativeGeometry) | ||
} | ||
|
||
private fun isNewRoute(currentGeometry: String, alternativeGeometry: String): Boolean { | ||
return currentGeometry != alternativeGeometry | ||
} | ||
} |
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
86 changes: 86 additions & 0 deletions
86
...vigation-core/src/test/java/com/mapbox/navigation/core/fasterroute/RouteComparatorTest.kt
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,86 @@ | ||
package com.mapbox.navigation.core.fasterroute | ||
|
||
import com.mapbox.api.directions.v5.models.DirectionsRoute | ||
import com.mapbox.navigation.base.trip.model.RouteProgress | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import junit.framework.Assert.assertFalse | ||
import junit.framework.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
class RouteComparatorTest { | ||
|
||
private val routeComparator = RouteComparator() | ||
|
||
@Test | ||
fun `route with different geometry is new`() { | ||
val currentRoute = """indacAcvqniGkFBmJB{FJ_JrEqBbAoRvEwJdBmC\sJb@eEDkEI_Mc@oIUsEF_FTgFt@qHjBmFjB}ItEqItAkE~BeW`NcEbCsNjIcCaFq@wA""" | ||
val alternative = """{{dacAiaqniGdAlIjA^vC\nD?GwX\sFgH?oJ?yF\_JtEqBz@qRtEuJxBoC?uJ|@_E?mE?aM}@oI?sE?}E^cF\yHxBkFzA_JrEmIzAmExBcWfNeExCoNnHgCuEu@yA""" | ||
val routeProgress: RouteProgress = mockk { | ||
every { route } returns mockk { | ||
every { geometry() } returns currentRoute | ||
} | ||
} | ||
val directionsRoute: DirectionsRoute = mockk { | ||
every { geometry() } returns alternative | ||
} | ||
|
||
val isNewRoute = routeComparator.isNewRoute(routeProgress, directionsRoute) | ||
|
||
assertTrue(isNewRoute) | ||
} | ||
|
||
@Test | ||
fun `route with same geometry is not new`() { | ||
val currentRoute = """indacAcvqniGkFBmJB{FJ_JrEqBbAoRvEwJdBmC\sJb@eEDkEI_Mc@oIUsEF_FTgFt@qHjBmFjB}ItEqItAkE~BeW`NcEbCsNjIcCaFq@wA""" | ||
val alternative = """indacAcvqniGkFBmJB{FJ_JrEqBbAoRvEwJdBmC\sJb@eEDkEI_Mc@oIUsEF_FTgFt@qHjBmFjB}ItEqItAkE~BeW`NcEbCsNjIcCaFq@wA""" | ||
val routeProgress: RouteProgress = mockk { | ||
every { route } returns mockk { | ||
every { geometry() } returns currentRoute | ||
} | ||
} | ||
val directionsRoute: DirectionsRoute = mockk { | ||
every { geometry() } returns alternative | ||
} | ||
|
||
val isNewRoute = routeComparator.isNewRoute(routeProgress, directionsRoute) | ||
|
||
assertFalse(isNewRoute) | ||
} | ||
|
||
@Test | ||
fun `alternative is not new when alternative is empty`() { | ||
val currentGeometry = """indacAcvqniGkFBmJB{FJ_JrEqBbAoRvEwJdBmC\sJb@eEDkEI_Mc@oIUsEF_FTgFt@qHjBmFjB}ItEqItAkE~BeW`NcEbCsNjIcCaFq@wA""" | ||
val alternativeGeometry = "" | ||
val routeProgress: RouteProgress = mockk { | ||
every { route } returns mockk { | ||
every { geometry() } returns currentGeometry | ||
} | ||
} | ||
val directionsRoute: DirectionsRoute = mockk { | ||
every { geometry() } returns alternativeGeometry | ||
} | ||
|
||
val isNewRoute = routeComparator.isNewRoute(routeProgress, directionsRoute) | ||
|
||
assertFalse(isNewRoute) | ||
} | ||
|
||
@Test | ||
fun `routes with same beginning and end, can still be different`() { | ||
val currentGeometry = """e|h~bAslcjiGvBab@tHe}AnEs~@AqdAB{d@EsQCii@Ie\EeUFoh@Reg@nHwEbUsNjUuM`ZiQ|McI`e@eZbf@yX|[wRdCyAfYcQpYwPlVcOvn@y^nUqKfPwFnLeDvW{Hd^sKhr@kTzk@yd@jMuK|IqC`PrgAhM|u@nInm@pB`KnCjMbFzS`EtOrIl_@`T|{@rChMzL`i@jGbX|CzMtd@bjBbEfPdU~}@pFdTjAxDzH~XjGrSdOlc@xTvs@tUzt@jKl_@hP`d@bM``@tQ`h@vVlu@dYlw@pLl]nNrd@lApEtCdIpXpv@|AtExUpt@bXps@`Stk@lDfKlSbl@rv@~{BdD~HdIdMnOpQ|e@la@tt@|m@nEpDlItBxYhVlJ~H|P|L`LhI~SdL~FnBbXjElYbFlW`G|f@|Hpt@|J|Fm^vJs`@|Swk@jPee@j@_BpA{BrEaIfHcM~]vS`EbB""" | ||
val alternativeGeometry = """e|h~bAslcjiGvBab@tHe}AnEs~@AqdAB{d@EsQCii@Ie\EeUh`@}@ta@_@x\mAlE~YjA`IpAxGvCzSxG`c@lJjn@~AxKZvIIvDfYzSpAdAbHvFlLnEnJHvJEXtKnBdh@mCxV\~H|Jv`@zc@uKtZoIz]aKva@kKj]mIzOyDf_@mJvNcEbOqD`SmF~XiH\bOj@jXZnIX`Lt@jMt@fLnAlPn@bJ|BfS`Pg@nFOpDUde@iFbOk@fq@}BrRL|SCfBWfa@wU|[eR\SrOaJpJkFxTvs@tUzt@jKl_@hP`d@bM``@tQ`h@vVlu@dYlw@pLl]nNrd@lApEtCdIpXpv@|AtExUpt@bXps@`Stk@lDfKlSbl@rv@~{BdD~HdIdMnOpQ|e@la@tt@|m@nEpDlItBxYhVlJ~H|P|L`LhI~SdL~FnBbXjElYbFlW`G|f@|Hpt@|J|Fm^vJs`@|Swk@jPee@j@_BpA{BrEaIfHcM~]vS`EbB""" | ||
val routeProgress: RouteProgress = mockk { | ||
every { route } returns mockk { | ||
every { geometry() } returns currentGeometry | ||
} | ||
} | ||
val directionsRoute: DirectionsRoute = mockk { | ||
every { geometry() } returns alternativeGeometry | ||
} | ||
|
||
val isNewRoute = routeComparator.isNewRoute(routeProgress, directionsRoute) | ||
|
||
assertTrue(isNewRoute) | ||
} | ||
} |