-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the Waypoint.targetCoordinate property corresponding to the Directions API’s waypoint_targets property. Added unit tests of copying and coding waypoints, as well as specifying waypoint_targets and other waypoint properties in conjunction with a RouteOptions object. Added documentation associating some properties with their API counterparts for discoverability.
- Loading branch information
Showing
8 changed files
with
114 additions
and
1 deletion.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import XCTest | ||
import MapboxDirections | ||
|
||
class WaypointTests: XCTestCase { | ||
func testCopying() { | ||
let originalWaypoint = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 38.8977, longitude: -77.0365), coordinateAccuracy: 5, name: "White House") | ||
originalWaypoint.targetCoordinate = CLLocationCoordinate2D(latitude: 38.8952261, longitude: -77.0327882) | ||
originalWaypoint.heading = 90 | ||
originalWaypoint.headingAccuracy = 10 | ||
originalWaypoint.allowsArrivingOnOppositeSide = false | ||
|
||
guard let copy = originalWaypoint.copy() as? Waypoint else { | ||
return XCTFail("Waypoint copy method should an object of same type") | ||
} | ||
|
||
XCTAssertEqual(copy.coordinate.latitude, originalWaypoint.coordinate.latitude) | ||
XCTAssertEqual(copy.coordinate.longitude, originalWaypoint.coordinate.longitude) | ||
XCTAssertEqual(copy.coordinateAccuracy, originalWaypoint.coordinateAccuracy) | ||
XCTAssertEqual(copy.targetCoordinate.latitude, originalWaypoint.targetCoordinate.latitude) | ||
XCTAssertEqual(copy.targetCoordinate.longitude, originalWaypoint.targetCoordinate.longitude) | ||
XCTAssertEqual(copy.heading, originalWaypoint.heading) | ||
XCTAssertEqual(copy.headingAccuracy, originalWaypoint.headingAccuracy) | ||
XCTAssertEqual(copy.allowsArrivingOnOppositeSide, originalWaypoint.allowsArrivingOnOppositeSide) | ||
} | ||
|
||
func testCoding() { | ||
let originalWaypoint = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 38.8977, longitude: -77.0365), coordinateAccuracy: 5, name: "White House") | ||
originalWaypoint.targetCoordinate = CLLocationCoordinate2D(latitude: 38.8952261, longitude: -77.0327882) | ||
originalWaypoint.heading = 90 | ||
originalWaypoint.headingAccuracy = 10 | ||
originalWaypoint.allowsArrivingOnOppositeSide = false | ||
|
||
let encodedData = NSMutableData() | ||
let coder = NSKeyedArchiver(forWritingWith: encodedData) | ||
coder.requiresSecureCoding = true | ||
coder.encode(originalWaypoint, forKey: "waypoint") | ||
coder.finishEncoding() | ||
|
||
let decoder = NSKeyedUnarchiver(forReadingWith: encodedData as Data) | ||
decoder.requiresSecureCoding = true | ||
defer { | ||
decoder.finishDecoding() | ||
} | ||
guard let decodedWaypoint = decoder.decodeObject(of: Waypoint.self, forKey: "waypoint") else { | ||
return XCTFail("Unable to decode waypoint") | ||
} | ||
|
||
XCTAssertEqual(decodedWaypoint.coordinate.latitude, originalWaypoint.coordinate.latitude) | ||
XCTAssertEqual(decodedWaypoint.coordinate.longitude, originalWaypoint.coordinate.longitude) | ||
XCTAssertEqual(decodedWaypoint.coordinateAccuracy, originalWaypoint.coordinateAccuracy) | ||
XCTAssertEqual(decodedWaypoint.targetCoordinate.latitude, originalWaypoint.targetCoordinate.latitude) | ||
XCTAssertEqual(decodedWaypoint.targetCoordinate.longitude, originalWaypoint.targetCoordinate.longitude) | ||
XCTAssertEqual(decodedWaypoint.heading, originalWaypoint.heading) | ||
XCTAssertEqual(decodedWaypoint.headingAccuracy, originalWaypoint.headingAccuracy) | ||
XCTAssertEqual(decodedWaypoint.allowsArrivingOnOppositeSide, originalWaypoint.allowsArrivingOnOppositeSide) | ||
} | ||
} |