Skip to content

Commit

Permalink
RouteStep encoding rounding (#697)
Browse files Browse the repository at this point in the history
* vk-670-route-step-rounding: removed rounding distance and travel times when encoding RouteStep. Unit test updated.

* vk-670-route-step-rounding: CHANGELOG entry added
  • Loading branch information
Udumft authored May 24, 2022
1 parent 2c46382 commit f100545
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes to Mapbox Directions for Swift

## main

* Removed limiting `RouteStep.distance`, `RouteStep.expectedTravelTime` and `RouteStep.typicalTravelTime` precision to 1 decimal digit when being encoded. ([#697](https://github.com/mapbox/mapbox-directions-swift/pull/697))

## v2.5.0

* Added the `RestStop.name` property. ([#689](https://github.com/mapbox/mapbox-directions-swift/pull/689))
Expand Down
6 changes: 3 additions & 3 deletions Sources/MapboxDirections/RouteStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,9 @@ open class RouteStep: Codable, ForeignMemberContainerClass {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(instructionsSpokenAlongStep, forKey: .instructionsSpokenAlongStep)
try container.encodeIfPresent(instructionsDisplayedAlongStep, forKey: .instructionsDisplayedAlongStep)
try container.encode(distance.rounded(to: 1e1), forKey: .distance)
try container.encode(expectedTravelTime.rounded(to: 1e1), forKey: .expectedTravelTime)
try container.encodeIfPresent(typicalTravelTime?.rounded(to: 1e1), forKey: .typicalTravelTime)
try container.encode(distance, forKey: .distance)
try container.encode(expectedTravelTime, forKey: .expectedTravelTime)
try container.encodeIfPresent(typicalTravelTime, forKey: .typicalTravelTime)
try container.encode(transportType, forKey: .transportType)

let isRound = maneuverType == .takeRotary || maneuverType == .takeRoundabout
Expand Down
8 changes: 4 additions & 4 deletions Tests/MapboxDirectionsTests/RouteStepTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ class RouteStepTests: XCTestCase {
],
"ref": "CA 24",
"weight": 2.5,
"duration": 2.5,
"duration": 2.55,
"duration_typical": 2.369,
"name": "Grove Shafter Freeway",
"pronunciation": "ˈaɪˌfoʊ̯n ˈtɛn",
"distance": 24.5,
"distance": 24.50001,
] as [String: Any?]

let stepData = try! JSONSerialization.data(withJSONObject: stepJSON, options: [])
Expand All @@ -139,11 +139,11 @@ class RouteStepTests: XCTestCase {
XCTAssertEqual(step.maneuverType, .reachFork)
XCTAssertEqual(step.instructions, "Keep right onto CA 24")
XCTAssertEqual(step.codes, ["CA 24"])
XCTAssertEqual(step.expectedTravelTime, 2.5)
XCTAssertEqual(step.expectedTravelTime, 2.55)
XCTAssertEqual(step.typicalTravelTime, 2.369)
XCTAssertEqual(step.names, ["Grove Shafter Freeway"])
XCTAssertEqual(step.phoneticNames, ["ˈaɪˌfoʊ̯n ˈtɛn"])
XCTAssertEqual(step.distance, 24.5)
XCTAssertEqual(step.distance, 24.50001)
}
}

Expand Down

0 comments on commit f100545

Please sign in to comment.