Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into remove-telemetry-e…
Browse files Browse the repository at this point in the history
…vents
  • Loading branch information
rubenmx committed Oct 13, 2020
2 parents ad47ec2 + 63e2bfc commit 4361f2b
Show file tree
Hide file tree
Showing 15 changed files with 1,291 additions and 1,593 deletions.
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ext {
espressoVersion : '3.0.2',
spoonRunner : '1.6.2',
commonsIO : '2.6',
robolectric : '3.8',
robolectric : '4.0',
lifecycle : '1.1.1',
picasso : '2.71828',
gmsLocation : '15.0.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ void initializeTime() {
* @return list of sliced {@link Point}s.
*/
List<Point> sliceRoute(LineString lineString) {
if (lineString == null || lineString.coordinates().isEmpty()) {
return Collections.emptyList();
}

double distanceMeters = TurfMeasurement.length(lineString, TurfConstants.UNIT_METERS);
if (distanceMeters <= 0) {
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ public static StepIntersection findCurrentIntersection(@NonNull List<StepInterse
@NonNull List<Pair<StepIntersection, Double>> measuredIntersections,
double stepDistanceTraveled) {
for (Pair<StepIntersection, Double> measuredIntersection : measuredIntersections) {
if (measuredIntersection.first == null)
return intersections.get(0);
double intersectionDistance = measuredIntersection.second;
int intersectionIndex = measuredIntersections.indexOf(measuredIntersection);
int nextIntersectionIndex = intersectionIndex + ONE_INDEX;
Expand Down Expand Up @@ -486,6 +488,8 @@ static boolean isUserOffRoute(NavigationLocationUpdate navigationLocationUpdate,

static boolean shouldCheckFasterRoute(NavigationLocationUpdate navigationLocationUpdate,
RouteProgress routeProgress) {
if(navigationLocationUpdate == null)
return false;
FasterRoute fasterRoute = navigationLocationUpdate.mapboxNavigation().getFasterRouteEngine();
return fasterRoute.shouldCheckFasterRoute(navigationLocationUpdate.location(), routeProgress);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.mapbox.services.android.navigation.v5;

import android.util.Pair;

import androidx.annotation.NonNull;
import androidx.core.util.Pair;

import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.api.directions.v5.models.LegStep;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.mapbox.services.android.navigation.v5.location.replay;

import com.mapbox.geojson.LineString;
import com.mapbox.geojson.Point;

import org.junit.Test;

import java.util.List;

public class ReplayRouteLocationConverterTest {


@Test
public void testSliceRouteWithEmptyLineString() {
ReplayRouteLocationConverter replayRouteLocationConverter = new ReplayRouteLocationConverter(null, 100, 1);
List<Point> result = replayRouteLocationConverter.sliceRoute(LineString.fromJson(""));

assert (result.isEmpty());
}

@Test
public void testSliceRouteWithNullLineString() {
ReplayRouteLocationConverter replayRouteLocationConverter = new ReplayRouteLocationConverter(null, 100, 1);
List<Point> result = replayRouteLocationConverter.sliceRoute(null);

assert (result.isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;
import com.mapbox.api.directions.v5.models.DirectionsResponse;
import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.services.android.navigation.BuildConfig;
import com.mapbox.services.android.navigation.v5.BaseTest;
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress;

Expand All @@ -14,125 +13,122 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class)
public class TriggerPropertyTest extends BaseTest {
private static final String ROUTE_FIXTURE = "directions_v5_precision_6.json";

@Test
public void stepDurationRemainingProperty_onlyPassesValidationWhenEqual() throws Exception {
RouteProgress routeProgress = buildTestRouteProgressForTrigger();
double stepDuration = routeProgress.currentLegProgress().currentStepProgress().durationRemaining();

for (int i = 10; i > 0; i--) {
Milestone milestone = new StepMilestone.Builder()
.setTrigger(
Trigger.eq(TriggerProperty.STEP_DURATION_REMAINING_SECONDS, (stepDuration / i))
).build();

boolean result = milestone.isOccurring(routeProgress, routeProgress);
if ((stepDuration / i) == stepDuration) {
Assert.assertTrue(result);
} else {
Assert.assertFalse(result);
}
}
}

private static final String ROUTE_FIXTURE = "directions_v5_precision_6.json";

@Test
public void stepDurationRemainingProperty_onlyPassesValidationWhenEqual() throws Exception {
RouteProgress routeProgress = buildTestRouteProgressForTrigger();
double stepDuration = routeProgress.currentLegProgress().currentStepProgress().durationRemaining();

for (int i = 10; i > 0; i--) {
Milestone milestone = new StepMilestone.Builder()
.setTrigger(
Trigger.eq(TriggerProperty.STEP_DURATION_REMAINING_SECONDS, (stepDuration / i))
).build();

boolean result = milestone.isOccurring(routeProgress, routeProgress);
if ((stepDuration / i) == stepDuration) {
Assert.assertTrue(result);
} else {
Assert.assertFalse(result);
}
@Test
public void stepDistanceRemainingProperty_onlyPassesValidationWhenEqual() throws Exception {
RouteProgress routeProgress = buildTestRouteProgressForTrigger();
double stepDistance = routeProgress.currentLegProgress().currentStepProgress().distanceRemaining();

for (int i = 10; i > 0; i--) {
Milestone milestone = new StepMilestone.Builder()
.setTrigger(
Trigger.eq(TriggerProperty.STEP_DISTANCE_REMAINING_METERS, (stepDistance / i))
).build();

boolean result = milestone.isOccurring(routeProgress, routeProgress);
if ((stepDistance / i) == stepDistance) {
Assert.assertTrue(result);
} else {
Assert.assertFalse(result);
}
}
}
}

@Test
public void stepDistanceRemainingProperty_onlyPassesValidationWhenEqual() throws Exception {
RouteProgress routeProgress = buildTestRouteProgressForTrigger();
double stepDistance = routeProgress.currentLegProgress().currentStepProgress().distanceRemaining();

for (int i = 10; i > 0; i--) {
Milestone milestone = new StepMilestone.Builder()
.setTrigger(
Trigger.eq(TriggerProperty.STEP_DISTANCE_REMAINING_METERS, (stepDistance / i))
).build();

boolean result = milestone.isOccurring(routeProgress, routeProgress);
if ((stepDistance / i) == stepDistance) {
Assert.assertTrue(result);
} else {
Assert.assertFalse(result);
}

@Test
public void stepDistanceTotalProperty_onlyPassesValidationWhenEqual() throws Exception {
RouteProgress routeProgress = buildTestRouteProgressForTrigger();
double stepDistanceTotal = routeProgress.currentLegProgress().currentStep().distance();

for (int i = 10; i > 0; i--) {
Milestone milestone = new StepMilestone.Builder()
.setTrigger(
Trigger.eq(TriggerProperty.STEP_DISTANCE_TOTAL_METERS, (stepDistanceTotal / i))
).build();

boolean result = milestone.isOccurring(routeProgress, routeProgress);
if ((stepDistanceTotal / i) == stepDistanceTotal) {
Assert.assertTrue(result);
} else {
Assert.assertFalse(result);
}
}
}
}

@Test
public void stepDistanceTotalProperty_onlyPassesValidationWhenEqual() throws Exception {
RouteProgress routeProgress = buildTestRouteProgressForTrigger();
double stepDistanceTotal = routeProgress.currentLegProgress().currentStep().distance();

for (int i = 10; i > 0; i--) {
Milestone milestone = new StepMilestone.Builder()
.setTrigger(
Trigger.eq(TriggerProperty.STEP_DISTANCE_TOTAL_METERS, (stepDistanceTotal / i))
).build();

boolean result = milestone.isOccurring(routeProgress, routeProgress);
if ((stepDistanceTotal / i) == stepDistanceTotal) {
Assert.assertTrue(result);
} else {
Assert.assertFalse(result);
}

@Test
public void stepDurationTotalProperty_onlyPassesValidationWhenEqual() throws Exception {
RouteProgress routeProgress = buildTestRouteProgressForTrigger();
double stepDurationTotal = routeProgress.currentLegProgress().currentStep().duration();

for (int i = 10; i > 0; i--) {
Milestone milestone = new StepMilestone.Builder()
.setTrigger(
Trigger.eq(TriggerProperty.STEP_DURATION_TOTAL_SECONDS, (stepDurationTotal / i))
).build();

boolean result = milestone.isOccurring(routeProgress, routeProgress);
if ((stepDurationTotal / i) == stepDurationTotal) {
Assert.assertTrue(result);
} else {
Assert.assertFalse(result);
}
}
}
}

@Test
public void stepDurationTotalProperty_onlyPassesValidationWhenEqual() throws Exception {
RouteProgress routeProgress = buildTestRouteProgressForTrigger();
double stepDurationTotal = routeProgress.currentLegProgress().currentStep().duration();

for (int i = 10; i > 0; i--) {
Milestone milestone = new StepMilestone.Builder()
.setTrigger(
Trigger.eq(TriggerProperty.STEP_DURATION_TOTAL_SECONDS, (stepDurationTotal / i))
).build();

boolean result = milestone.isOccurring(routeProgress, routeProgress);
if ((stepDurationTotal / i) == stepDurationTotal) {
Assert.assertTrue(result);
} else {
Assert.assertFalse(result);
}

@Test
public void stepIndexProperty_onlyPassesValidationWhenEqual() throws Exception {
RouteProgress routeProgress = buildTestRouteProgressForTrigger();
int stepIndex = routeProgress.currentLegProgress().stepIndex();

for (int i = 10; i > 0; i--) {
Milestone milestone = new StepMilestone.Builder()
.setTrigger(
Trigger.eq(TriggerProperty.STEP_INDEX, Math.abs(stepIndex - i))
).build();

boolean result = milestone.isOccurring(routeProgress, routeProgress);
if (Math.abs(stepIndex - i) == stepIndex) {
Assert.assertTrue(result);
} else {
Assert.assertFalse(result);
}
}
}
}

@Test
public void stepIndexProperty_onlyPassesValidationWhenEqual() throws Exception {
RouteProgress routeProgress = buildTestRouteProgressForTrigger();
int stepIndex = routeProgress.currentLegProgress().stepIndex();

for (int i = 10; i > 0; i--) {
Milestone milestone = new StepMilestone.Builder()
.setTrigger(
Trigger.eq(TriggerProperty.STEP_INDEX, Math.abs(stepIndex - i))
).build();

boolean result = milestone.isOccurring(routeProgress, routeProgress);
if (Math.abs(stepIndex - i) == stepIndex) {
Assert.assertTrue(result);
} else {
Assert.assertFalse(result);
}

private RouteProgress buildTestRouteProgressForTrigger() throws Exception {
Gson gson = new GsonBuilder()
.registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
String body = loadJsonFixture(ROUTE_FIXTURE);
DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);

DirectionsRoute route = response.routes().get(0);
double distanceRemaining = route.distance();
double legDistanceRemaining = route.legs().get(0).distance();
double stepDistanceRemaining = route.legs().get(0).steps().get(0).distance();
return buildTestRouteProgress(route, stepDistanceRemaining,
legDistanceRemaining, distanceRemaining, 1, 0);
}
}

private RouteProgress buildTestRouteProgressForTrigger() throws Exception {
Gson gson = new GsonBuilder()
.registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
String body = loadJsonFixture(ROUTE_FIXTURE);
DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);

DirectionsRoute route = response.routes().get(0);
double distanceRemaining = route.distance();
double legDistanceRemaining = route.legs().get(0).distance();
double stepDistanceRemaining = route.legs().get(0).steps().get(0).distance();
return buildTestRouteProgress(route, stepDistanceRemaining,
legDistanceRemaining, distanceRemaining, 1, 0);
}
}
Loading

0 comments on commit 4361f2b

Please sign in to comment.