Skip to content

Commit

Permalink
WIP: Test Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerrad Thramer authored and Jerrad Thramer committed Oct 22, 2019
1 parent 268e651 commit 1206af1
Show file tree
Hide file tree
Showing 18 changed files with 114 additions and 117 deletions.
28 changes: 2 additions & 26 deletions MapboxDirections.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,6 @@
DA737EE41D05F91E005BDA16 /* v5_driving_dc_geojson.json in Resources */ = {isa = PBXBuildFile; fileRef = DA737EE31D05F91E005BDA16 /* v5_driving_dc_geojson.json */; };
DA737EE51D05F91E005BDA16 /* v5_driving_dc_geojson.json in Resources */ = {isa = PBXBuildFile; fileRef = DA737EE31D05F91E005BDA16 /* v5_driving_dc_geojson.json */; };
DA737EE61D05F91E005BDA16 /* v5_driving_dc_geojson.json in Resources */ = {isa = PBXBuildFile; fileRef = DA737EE31D05F91E005BDA16 /* v5_driving_dc_geojson.json */; };
DA737EEE1D06175B005BDA16 /* v4_driving_dc_geojson.json in Resources */ = {isa = PBXBuildFile; fileRef = DA737EED1D06175B005BDA16 /* v4_driving_dc_geojson.json */; };
DA737EEF1D06175B005BDA16 /* v4_driving_dc_geojson.json in Resources */ = {isa = PBXBuildFile; fileRef = DA737EED1D06175B005BDA16 /* v4_driving_dc_geojson.json */; };
DA737EF01D06175B005BDA16 /* v4_driving_dc_geojson.json in Resources */ = {isa = PBXBuildFile; fileRef = DA737EED1D06175B005BDA16 /* v4_driving_dc_geojson.json */; };
DA737EF21D061AA2005BDA16 /* v4_driving_dc_polyline.json in Resources */ = {isa = PBXBuildFile; fileRef = DA737EF11D061AA2005BDA16 /* v4_driving_dc_polyline.json */; };
DA737EF31D061AA2005BDA16 /* v4_driving_dc_polyline.json in Resources */ = {isa = PBXBuildFile; fileRef = DA737EF11D061AA2005BDA16 /* v4_driving_dc_polyline.json */; };
DA737EF41D061AA2005BDA16 /* v4_driving_dc_polyline.json in Resources */ = {isa = PBXBuildFile; fileRef = DA737EF11D061AA2005BDA16 /* v4_driving_dc_polyline.json */; };
DA9E1B131E5A675F0081EDC7 /* Polyline.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA9E1B121E5A675F0081EDC7 /* Polyline.framework */; };
DAA76D681DD127CB0015EC78 /* MBLaneIndication.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAA76D671DD127CB0015EC78 /* MBLaneIndication.swift */; };
DAA76D691DD127CB0015EC78 /* MBLaneIndication.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAA76D671DD127CB0015EC78 /* MBLaneIndication.swift */; };
Expand Down Expand Up @@ -394,8 +388,6 @@
DA6C9DAB1CAEC72800094FBC /* V5Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = V5Tests.swift; sourceTree = "<group>"; };
DA6C9DB11CAECA0E00094FBC /* Fixture.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Fixture.swift; sourceTree = "<group>"; };
DA737EE31D05F91E005BDA16 /* v5_driving_dc_geojson.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = v5_driving_dc_geojson.json; sourceTree = "<group>"; };
DA737EED1D06175B005BDA16 /* v4_driving_dc_geojson.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = v4_driving_dc_geojson.json; sourceTree = "<group>"; };
DA737EF11D061AA2005BDA16 /* v4_driving_dc_polyline.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = v4_driving_dc_polyline.json; sourceTree = "<group>"; };
DA9E1B121E5A675F0081EDC7 /* Polyline.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Polyline.framework; path = Carthage/Build/watchOS/Polyline.framework; sourceTree = "<group>"; };
DAA76D671DD127CB0015EC78 /* MBLaneIndication.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MBLaneIndication.swift; sourceTree = "<group>"; };
DAC05F151CFBFAC400FA0071 /* MBWaypoint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MBWaypoint.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -669,7 +661,6 @@
8D381B5F1FD9F592008D5A58 /* Responses */,
C5D1D7EE1F6AF8FA00A1C4F1 /* Instructions */,
C5247D721E818A8D004B6154 /* annotation */,
DA737EEC1D061514005BDA16 /* V4 */,
DA737EEB1D0614FA005BDA16 /* V5 */,
);
path = Fixtures;
Expand All @@ -686,16 +677,6 @@
path = v5;
sourceTree = "<group>";
};
DA737EEC1D061514005BDA16 /* V4 */ = {
isa = PBXGroup;
children = (
DA737EED1D06175B005BDA16 /* v4_driving_dc_geojson.json */,
DA737EF11D061AA2005BDA16 /* v4_driving_dc_polyline.json */,
);
name = V4;
path = v4;
sourceTree = "<group>";
};
DA9E1B111E5A675F0081EDC7 /* watchOS Frameworks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1048,7 +1029,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
DA737EF31D061AA2005BDA16 /* v4_driving_dc_polyline.json in Resources */,
DA737EE51D05F91E005BDA16 /* v5_driving_dc_geojson.json in Resources */,
DA1A10CF1D00F975009F82FA /* v5_driving_dc_polyline.json in Resources */,
C5C0D63520586419003A3B1D /* null-tracepoint.json in Resources */,
Expand All @@ -1061,7 +1041,6 @@
AEAB391220D9469A008F4E54 /* subVisualInstructions.json in Resources */,
DACCFCAA2225359600110FC9 /* v5_driving_oldenburg_polyline.json in Resources */,
C5DAACB5201AA9A7001F9261 /* match.json in Resources */,
DA737EEF1D06175B005BDA16 /* v4_driving_dc_geojson.json in Resources */,
C53A022B1E92C281009837BD /* annotation.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -1077,7 +1056,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
DA737EF41D061AA2005BDA16 /* v4_driving_dc_polyline.json in Resources */,
DA737EE61D05F91E005BDA16 /* v5_driving_dc_geojson.json in Resources */,
DA1A10F31D010251009F82FA /* v5_driving_dc_polyline.json in Resources */,
C5C0D6362058641B003A3B1D /* null-tracepoint.json in Resources */,
Expand All @@ -1090,7 +1068,6 @@
AEAB391320D9469A008F4E54 /* subVisualInstructions.json in Resources */,
DACCFCAB2225359600110FC9 /* v5_driving_oldenburg_polyline.json in Resources */,
C5DAACB6201AA9A7001F9261 /* match.json in Resources */,
DA737EF01D06175B005BDA16 /* v4_driving_dc_geojson.json in Resources */,
C53A022C1E92C281009837BD /* annotation.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -1113,14 +1090,12 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
DA737EF21D061AA2005BDA16 /* v4_driving_dc_polyline.json in Resources */,
DA737EE41D05F91E005BDA16 /* v5_driving_dc_geojson.json in Resources */,
DAC05F1C1CFC1E5300FA0071 /* v5_driving_dc_polyline.json in Resources */,
C5C0D6342058523E003A3B1D /* null-tracepoint.json in Resources */,
AEAB390D20D7F4F4008F4E54 /* subLaneInstructions.json in Resources */,
C5D1D7F01F6AF91700A1C4F1 /* instructions.json in Resources */,
8D381B611FD9F5B1008D5A58 /* noDestinationName.json in Resources */,
DA737EEE1D06175B005BDA16 /* v4_driving_dc_geojson.json in Resources */,
35DBF019217F38A30009D2AE /* versions.json in Resources */,
35D92FF0218203AB000C78CB /* 2018-10-16-Liechtenstein.tar in Resources */,
AEAB391120D9469A008F4E54 /* subVisualInstructions.json in Resources */,
Expand Down Expand Up @@ -1151,13 +1126,14 @@
inputPaths = (
"$(SRCROOT)/Carthage/Build/iOS/Mapbox.framework",
"$(SRCROOT)/Carthage/Build/iOS/Polyline.framework",
"$(SRCROOT)/Carthage/Build/iOS/Turf.framework",
);
name = "Copy Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "/usr/local/bin/carthage copy-frameworks";
shellScript = "/usr/local/bin/carthage copy-frameworks\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@
BlueprintName = "MapboxDirectionsTests"
ReferencedContainer = "container:MapboxDirections.xcodeproj">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "SpokenInstructionsTests">
</Test>
</SkippedTests>
</TestableReference>
</Testables>
</TestAction>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DA6C9D871CAE442B00094FBC"
BuildableName = "MapboxDirections.framework"
BlueprintName = "MapboxDirections"
ReferencedContainer = "container:MapboxDirections.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -40,17 +49,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DA6C9D871CAE442B00094FBC"
BuildableName = "MapboxDirections.framework"
BlueprintName = "MapboxDirections"
ReferencedContainer = "container:MapboxDirections.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -71,8 +69,6 @@
ReferencedContainer = "container:MapboxDirections.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
4 changes: 3 additions & 1 deletion Sources/MapboxDirections/Extensions/CoreLocation.Swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import Foundation
import CoreLocation

extension CLLocationCoordinate2D{
extension CLLocationCoordinate2D {
internal var requestDescription: String {
return "\(longitude.rounded(to: 1e6)),\(latitude.rounded(to: 1e6))"
}

}


extension CLLocation {
/**
Initializes a CLLocation object with the given coordinate pair.
Expand Down
2 changes: 1 addition & 1 deletion Sources/MapboxDirections/MBDirectionsOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public enum RouteShapeFormat: String, Codable {
This standard format is human-readable and can be parsed straightforwardly, but it is far more verbose than `polyline`.
*/
case geoJSON
case geoJSON = "geojson"
/**
The route’s shape is delivered in [encoded polyline algorithm](https://developers.google.com/maps/documentation/utilities/polylinealgorithm) format with 1×10<sup>−5</sup> precision.
Expand Down
26 changes: 15 additions & 11 deletions Sources/MapboxDirections/MBIntersection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public struct Intersection: Codable {
case approachIndex = "in"
case outletIndex = "out"
case lanes
case approachLanes
case usableApproachLanes
// case approachLanes
// case usableApproachLanes
case outletRoadClasses = "classes"
}

Expand Down Expand Up @@ -94,10 +94,15 @@ public struct Intersection: Codable {
try container.encode(approachIndex, forKey: .approachIndex)
try container.encode(outletIndex, forKey: .outletIndex)

try container.encode(outletIndexes, forKey: .outletIndexes)
var outletArray: [Bool] = Array<Bool>.init(repeating: false, count: (outletIndexes.max()! + 1))

for index in outletIndexes {
outletArray[index] = true
}

try container.encode(approachLanes, forKey: .approachLanes)
try container.encode(usableApproachLanes, forKey: .usableApproachLanes)
try container.encode(outletArray, forKey: .outletIndexes)

try container.encode(approachLanes, forKey: .lanes)

if let classes = outletRoadClasses?.description.components(separatedBy: ",") {
try container.encode(classes, forKey: .outletRoadClasses)
Expand Down Expand Up @@ -125,12 +130,11 @@ public struct Intersection: Codable {

outletRoadClasses = try container.decodeIfPresent(RoadClasses.self, forKey: .outletRoadClasses)

if let outletIndexes = try? container.decode(IndexSet.self, forKey: .outletIndexes) {
self.outletIndexes = outletIndexes
} else {
let outletsArray = try container.decode([Bool].self, forKey: .outletIndexes)
outletIndexes = IndexSet(outletsArray.enumerated().filter { $1 }.map { $0.offset })
}
let outletsArray = try container.decode([Bool].self, forKey: .outletIndexes)
let filtered = outletsArray.enumerated().filter { $1 }
let mapped = filtered.map { $0.offset }
outletIndexes =
IndexSet(mapped)

outletIndex = try container.decodeIfPresent(Int.self, forKey: .outletIndex) ?? -1
approachIndex = try container.decodeIfPresent(Int.self, forKey: .approachIndex) ?? -1
Expand Down
3 changes: 1 addition & 2 deletions Sources/MapboxDirections/MBLane.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public struct Lane: Codable {

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let descriptions = try container.decode([String].self, forKey: .indications)
indications = LaneIndication(descriptions: descriptions)!
indications = try container.decode(LaneIndication.self, forKey: .indications)
isValid = try container.decode(Bool.self, forKey: .valid)
}
}
27 changes: 25 additions & 2 deletions Sources/MapboxDirections/MBLaneIndication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public struct LaneIndication: OptionSet, CustomStringConvertible, Codable {
self.init(rawValue: laneIndication.rawValue)
}

public var description: String {
public var descriptions: [String] {
if isEmpty {
return "none"
return []
}

var descriptions: [String] = []
Expand Down Expand Up @@ -98,6 +98,29 @@ public struct LaneIndication: OptionSet, CustomStringConvertible, Codable {
if contains(.uTurn) {
descriptions.append("uturn")
}
return descriptions
}

public var description: String {
return descriptions.joined(separator: ",")
}

public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let stringValues = try container.decode([String].self)

self = try LaneIndication.indications(from: stringValues, container: container)
}

public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(descriptions)
}

static func indications(from strings: [String], container: SingleValueDecodingContainer) throws -> LaneIndication {
guard let indications = self.init(descriptions: strings) else {
throw DecodingError.dataCorruptedError(in: container, debugDescription: "Unable to initialize lane indications from decoded string. This should not happen.")
}
return indications
}
}
45 changes: 28 additions & 17 deletions Sources/MapboxDirections/MBRouteStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -378,23 +378,26 @@ open class RouteStep: NSObject, Codable {

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(instructionsSpokenAlongStep, forKey: .instructionsSpokenAlongStep)
try container.encode(instructionsDisplayedAlongStep, forKey: .instructionsDisplayedAlongStep)
try container.encode(exitIndex, forKey: .exitIndex)
try container.encode(exitCodes, forKey: .exitCodes)
try container.encode(exitNames, forKey: .exitNames)
try container.encode(phoneticExitNames, forKey: .phoneticExitNames)
try container.encode(phoneticNames, forKey: .phoneticNames)
try container.encode(distance, forKey: .distance)
try container.encode(expectedTravelTime, forKey: .expectedTravelTime)
try container.encode(codes, forKey: .codes)
try container.encode(transportType, forKey: .transportType)
try container.encode(destinationCodes, forKey: .destinationCodes)
try container.encode(destinations, forKey: .destinations)
try container.encode(intersections, forKey: .intersections)
try container.encodeIfPresent(instructionsSpokenAlongStep, forKey: .instructionsSpokenAlongStep)
try container.encodeIfPresent(instructionsDisplayedAlongStep, forKey: .instructionsDisplayedAlongStep)
try container.encodeIfPresent(exitIndex, forKey: .exitIndex)
try container.encodeIfPresent(exitCodes, forKey: .exitCodes)
try container.encodeIfPresent(exitNames, forKey: .exitNames)
try container.encodeIfPresent(phoneticExitNames, forKey: .phoneticExitNames)
try container.encodeIfPresent(phoneticNames, forKey: .phoneticNames)
try container.encode(distance.rounded(to: 1e1), forKey: .distance)
try container.encode(expectedTravelTime.rounded(to: 1e1), forKey: .expectedTravelTime)
try container.encodeIfPresent(codes, forKey: .codes)

if transportType != .none {
try container.encode(transportType, forKey: .transportType)
}
try container.encodeIfPresent(destinationCodes, forKey: .destinationCodes)
try container.encodeIfPresent(destinations, forKey: .destinations)
try container.encodeIfPresent(intersections, forKey: .intersections)
try container.encode(drivingSide, forKey: .drivingSide)
try container.encode(name, forKey: .name)
try container.encode(geometry, forKey: .geometry)
try container.encodeIfPresent(geometry, forKey: .geometry)

var maneuver = container.nestedContainer(keyedBy: ManeuverCodingKeys.self, forKey: .maneuver)
try maneuver.encode(instructions, forKey: .instruction)
Expand Down Expand Up @@ -448,10 +451,18 @@ open class RouteStep: NSObject, Codable {
instructions = ""
}
drivingSide = try container.decode(DrivingSide.self, forKey: .drivingSide)
(decoder as? JSONDecoder)?.userInfo[.drivingSide] = drivingSide

instructionsSpokenAlongStep = try container.decodeIfPresent([SpokenInstruction].self, forKey: .instructionsSpokenAlongStep)

instructionsDisplayedAlongStep = try container.decodeIfPresent([VisualInstructionBanner].self, forKey: .instructionsDisplayedAlongStep)

if let visuals = try container.decodeIfPresent([VisualInstructionBanner].self, forKey: .instructionsDisplayedAlongStep) {
for instruction in visuals {
instruction.drivingSide = drivingSide
}
instructionsDisplayedAlongStep = visuals
} else {
instructionsDisplayedAlongStep = nil
}

exitIndex = try container.decodeIfPresent(Int.self, forKey: .exitIndex)
exitCodes = try container.decodeIfPresent([String].self, forKey: .exitCodes)
Expand Down
Loading

0 comments on commit 1206af1

Please sign in to comment.