Skip to content

Commit

Permalink
Add basic integration tests for navigation controller state machine
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthetechie committed Oct 9, 2023
1 parent d9d4fb2 commit bf89936
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 81 deletions.
119 changes: 54 additions & 65 deletions common/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/ferrostar-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ assert-json-diff = "2.0.2"
proptest = "1.3.1"

[lib]
crate-type = ["cdylib", "staticlib"]
crate-type = ["cdylib", "staticlib", "lib"]
5 changes: 4 additions & 1 deletion common/ferrostar-core/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub struct Route {
/// NOTE: OSRM specifies this rather precisely as "travel along a single way to the subsequent step"
/// but we will intentionally define this somewhat looser unless/until it becomes clear something
///
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub struct RouteStep {
/// The starting location of the step (start of the maneuver).
pub start_location: GeographicCoordinates,
Expand All @@ -96,6 +96,7 @@ pub struct RouteStep {

// TODO: trigger_at doesn't really have to live in the public interface; figure out if we want to have a separate FFI vs internal type

#[derive(Debug, PartialEq)]
pub struct SpokenInstruction {
/// Plain-text instruction which can be synthesized with a TTS engine.
pub text: String,
Expand All @@ -104,6 +105,7 @@ pub struct SpokenInstruction {
pub trigger_at: GeographicCoordinates,
}

#[derive(Debug, PartialEq)]
pub struct VisualInstructions {
pub primary_content: VisualInstructionContent,
pub secondary_content: Option<VisualInstructionContent>,
Expand Down Expand Up @@ -144,6 +146,7 @@ pub enum ManeuverModifier {
SharpLeft,
}

#[derive(Debug, Eq, PartialEq)]
pub struct VisualInstructionContent {
pub text: String,
pub maneuver_type: Option<ManeuverType>,
Expand Down
1 change: 1 addition & 0 deletions common/ferrostar-core/src/navigation_controller/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub(super) enum TripState {
}

/// Public updates pushed up to the direct user of the NavigationController.
#[derive(Debug, PartialEq)]
pub enum NavigationStateUpdate {
Navigating {
snapped_user_location: UserLocation,
Expand Down
12 changes: 6 additions & 6 deletions common/ferrostar-core/src/navigation_controller/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::models::{GeographicCoordinates, RouteStep, UserLocation};
use geo::{Closest, HaversineClosestPoint, HaversineDistance, LineString, Point};
use geo::{Closest, ClosestPoint, HaversineDistance, LineString, Point};

#[cfg(test)]
use proptest::prelude::*;
Expand All @@ -13,7 +13,7 @@ use std::time::SystemTime;
pub fn snap_to_line(location: &UserLocation, line: &LineString) -> UserLocation {
let original_point = Point::new(location.coordinates.lng, location.coordinates.lat);

match line.haversine_closest_point(&original_point) {
match line.closest_point(&original_point) {
Closest::Intersection(snapped) | Closest::SinglePoint(snapped) => UserLocation {
coordinates: GeographicCoordinates {
lng: snapped.x(),
Expand Down Expand Up @@ -92,10 +92,10 @@ pub fn do_advance_to_next_step(
#[cfg(test)]
proptest! {
#[test]
fn test_should_advance_exact_position(x1 in -180f64..180f64, y1 in -90f64..90f64,
x2 in -180f64..180f64, y2 in -90f64..90f64,
distance: u16, minimum_horizontal_accuracy: u16,
excess_inaccuracy in 0f64..65535f64) {
fn should_advance_exact_position(x1 in -180f64..180f64, y1 in -90f64..90f64,
x2 in -180f64..180f64, y2 in -90f64..90f64,
distance: u16, minimum_horizontal_accuracy: u16,
excess_inaccuracy in 0f64..65535f64) {
let route_step = RouteStep {
start_location: GeographicCoordinates { lng: x1, lat: y1 },
end_location: GeographicCoordinates { lng: x2, lat: y2 },
Expand Down
Loading

0 comments on commit bf89936

Please sign in to comment.