diff --git a/Package.resolved b/Package.resolved index 2e9d536..7da6a72 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,61 +1,59 @@ { - "object": { - "pins": [ - { - "package": "swift-algorithms", - "repositoryURL": "https://github.com/apple/swift-algorithms", - "state": { - "branch": null, - "revision": "f6919dfc309e7f1b56224378b11e28bab5bccc42", - "version": "1.2.0" - } - }, - { - "package": "swift-custom-dump", - "repositoryURL": "https://github.com/pointfreeco/swift-custom-dump", - "state": { - "branch": null, - "revision": "6ea3b1b6a4957806d72030a32360d4bcb155a0d2", - "version": "1.2.0" - } - }, - { - "package": "SwiftDocCPlugin", - "repositoryURL": "https://github.com/apple/swift-docc-plugin", - "state": { - "branch": null, - "revision": "26ac5758409154cc448d7ab82389c520fa8a8247", - "version": "1.3.0" - } - }, - { - "package": "SymbolKit", - "repositoryURL": "https://github.com/apple/swift-docc-symbolkit", - "state": { - "branch": null, - "revision": "b45d1f2ed151d057b54504d653e0da5552844e34", - "version": "1.0.0" - } - }, - { - "package": "swift-numerics", - "repositoryURL": "https://github.com/apple/swift-numerics.git", - "state": { - "branch": null, - "revision": "0a5bc04095a675662cf24757cc0640aa2204253b", - "version": "1.0.2" - } - }, - { - "package": "xctest-dynamic-overlay", - "repositoryURL": "https://github.com/pointfreeco/xctest-dynamic-overlay", - "state": { - "branch": null, - "revision": "b58e6627149808b40634c4552fcf2f44d0b3ca87", - "version": "1.1.0" - } + "pins" : [ + { + "identity" : "swift-algorithms", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-algorithms", + "state" : { + "revision" : "f6919dfc309e7f1b56224378b11e28bab5bccc42", + "version" : "1.2.0" } - ] - }, - "version": 1 + }, + { + "identity" : "swift-custom-dump", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pointfreeco/swift-custom-dump", + "state" : { + "revision" : "82645ec760917961cfa08c9c0c7104a57a0fa4b1", + "version" : "1.3.3" + } + }, + { + "identity" : "swift-docc-plugin", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-docc-plugin", + "state" : { + "revision" : "26ac5758409154cc448d7ab82389c520fa8a8247", + "version" : "1.3.0" + } + }, + { + "identity" : "swift-docc-symbolkit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-docc-symbolkit", + "state" : { + "revision" : "b45d1f2ed151d057b54504d653e0da5552844e34", + "version" : "1.0.0" + } + }, + { + "identity" : "swift-numerics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-numerics.git", + "state" : { + "revision" : "0a5bc04095a675662cf24757cc0640aa2204253b", + "version" : "1.0.2" + } + }, + { + "identity" : "xctest-dynamic-overlay", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pointfreeco/xctest-dynamic-overlay", + "state" : { + "revision" : "357ca1e5dd31f613a1d43320870ebc219386a495", + "version" : "1.2.2" + } + } + ], + "version" : 2 } diff --git a/Package.swift b/Package.swift index 3dbbd34..e27cc95 100644 --- a/Package.swift +++ b/Package.swift @@ -1,7 +1,11 @@ -// swift-tools-version:5.2 +// swift-tools-version:5.9 import PackageDescription +let settings: [SwiftSetting] = [ + .enableExperimentalFeature("StrictConcurrency") +] + let package = Package( name: "GPXKit", platforms: [ @@ -16,7 +20,7 @@ let package = Package( targets: ["GPXKit"]), ], dependencies: [ - .package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.2.0"), + .package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.3"), .package(url: "https://github.com/apple/swift-algorithms", from: "1.2.0") ], targets: [ @@ -24,13 +28,17 @@ let package = Package( name: "GPXKit", dependencies: [ .product(name: "Algorithms", package: "swift-algorithms"), - ]), + ], + swiftSettings: settings + ), .testTarget( name: "GPXKitTests", dependencies: [ "GPXKit", .product(name: "CustomDump", package: "swift-custom-dump") - ]), + ], + swiftSettings: settings + ), ] ) diff --git a/Sources/GPXKit/ISO8601DateFormatter.swift b/Sources/GPXKit/ISO8601DateFormatter.swift index b8b8b34..5f979f0 100644 --- a/Sources/GPXKit/ISO8601DateFormatter.swift +++ b/Sources/GPXKit/ISO8601DateFormatter.swift @@ -1,13 +1,13 @@ import Foundation extension ISO8601DateFormatter { - static var importing: ISO8601DateFormatter = { + nonisolated(unsafe) static var importing: ISO8601DateFormatter = { let formatter = ISO8601DateFormatter() formatter.formatOptions = .withInternetDateTime return formatter }() - static var importingFractionalSeconds: ISO8601DateFormatter = { + nonisolated(unsafe) static var importingFractionalSeconds: ISO8601DateFormatter = { let formatter = ISO8601DateFormatter() if #available(macOS 10.13, iOS 12, tvOS 11.0, *) { formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds] @@ -17,7 +17,7 @@ extension ISO8601DateFormatter { return formatter }() - static var exporting: ISO8601DateFormatter = { + nonisolated(unsafe) static var exporting: ISO8601DateFormatter = { let formatter = ISO8601DateFormatter() formatter.formatOptions = .withInternetDateTime return formatter diff --git a/Tests/GPXKitTests/CollectionExtensionsTests.swift b/Tests/GPXKitTests/CollectionExtensionsTests.swift index 89c1c54..65be95b 100644 --- a/Tests/GPXKitTests/CollectionExtensionsTests.swift +++ b/Tests/GPXKitTests/CollectionExtensionsTests.swift @@ -7,19 +7,19 @@ final class ArrayExtensionsTests: XCTestCase { func testRemovingNearbyCoordinatesInEmptyCollection() { let coords: [Coordinate] = [] - XCTAssertNoDifference([], coords.removeIf(closerThan: 1)) + expectNoDifference([], coords.removeIf(closerThan: 1)) } func testRemovingNearbyCoordinatesWithOneElement() { let coords: [Coordinate] = [.leipzig] - XCTAssertNoDifference([.leipzig], coords.removeIf(closerThan: 1)) + expectNoDifference([.leipzig], coords.removeIf(closerThan: 1)) } func testRemovingNearbyCoordinatesWithTwoElement() { let coords: [Coordinate] = [.leipzig, .dehner] - XCTAssertNoDifference([.leipzig, .dehner], coords.removeIf(closerThan: 1)) + expectNoDifference([.leipzig, .dehner], coords.removeIf(closerThan: 1)) } func testRemovingDuplicateCoordinates() { @@ -34,7 +34,7 @@ final class ArrayExtensionsTests: XCTestCase { ] let result = coords.removeIf(closerThan: 50) - XCTAssertNoDifference([coords[0], coords[1], coords[3], .postPlatz], result) + expectNoDifference([coords[0], coords[1], coords[3], .postPlatz], result) } func testSmoothingElevation() { @@ -83,7 +83,7 @@ final class ArrayExtensionsTests: XCTestCase { ] let actual = try XCTUnwrap(grades.flatten(maxDelta: 0.01)) - XCTAssertNoDifference(expected, actual) + expectNoDifference(expected, actual) } func testFlatteningGradeSegmentsWithVeryLargeGradeDifferencesDoesNotResultInNotANumber() throws { @@ -92,7 +92,7 @@ final class ArrayExtensionsTests: XCTestCase { let graph = TrackGraph(coords: .init(track.trackPoints.map(\.coordinate).prefix(50))) let actual = try XCTUnwrap(graph.gradeSegments.flatten(maxDelta: 0.01)) - XCTAssertNoDifference(0, actual.filter { $0.grade.isNaN }.count) + expectNoDifference(0, actual.filter { $0.grade.isNaN }.count) } func testSmoothingElevationOnSmallCollections() { @@ -103,12 +103,12 @@ final class ArrayExtensionsTests: XCTestCase { elevation: Double.random(in: 500 ... 550) ) - XCTAssertNoDifference([], [Coordinate]().smoothedElevation(sampleCount: Int.random(in: 2...200))) - XCTAssertNoDifference([start], [start].smoothedElevation(sampleCount: Int.random(in: 5...200))) + expectNoDifference([], [Coordinate]().smoothedElevation(sampleCount: Int.random(in: 2...200))) + expectNoDifference([start], [start].smoothedElevation(sampleCount: Int.random(in: 5...200))) let coords: [Coordinate] = [start, end] let avg = coords.map(\.elevation).reduce(0, +) / Double(coords.count) - XCTAssertNoDifference([.init(latitude: start.latitude, longitude: start.longitude, elevation: avg), .init(latitude: end.latitude, longitude: end.longitude, elevation: avg)], coords.smoothedElevation(sampleCount: 50)) + expectNoDifference([.init(latitude: start.latitude, longitude: start.longitude, elevation: avg), .init(latitude: end.latitude, longitude: end.longitude, elevation: avg)], coords.smoothedElevation(sampleCount: 50)) } } diff --git a/Tests/GPXKitTests/GPXParserTests.swift b/Tests/GPXKitTests/GPXParserTests.swift index c5d88be..c43f6e1 100644 --- a/Tests/GPXKitTests/GPXParserTests.swift +++ b/Tests/GPXKitTests/GPXParserTests.swift @@ -27,8 +27,8 @@ class GPXParserTests: XCTestCase { XCTAssertNil(result) if case let .parseError(error, line) = parseError { - XCTAssertNoDifference(0, line) - XCTAssertNoDifference(1, error.code) + expectNoDifference(0, line) + expectNoDifference(1, error.code) } else { XCTFail("Exepcted parse error, got \(String(describing: parseError))") } @@ -45,13 +45,13 @@ class GPXParserTests: XCTestCase { """) let sut = try XCTUnwrap(result) - XCTAssertNoDifference("", sut.title) - XCTAssertNoDifference(nil, sut.description) - XCTAssertNoDifference(expectedDate(for: "2020-03-17T11:27:02Z"), sut.date) - XCTAssertNoDifference([], sut.trackPoints) - XCTAssertNoDifference([], sut.graph.heightMap) - XCTAssertNoDifference([], sut.graph.segments) - XCTAssertNoDifference([], sut.graph.climbs()) + expectNoDifference("", sut.title) + expectNoDifference(nil, sut.description) + expectNoDifference(expectedDate(for: "2020-03-17T11:27:02Z"), sut.date) + expectNoDifference([], sut.trackPoints) + expectNoDifference([], sut.graph.heightMap) + expectNoDifference([], sut.graph.segments) + expectNoDifference([], sut.graph.climbs()) } func testParsingTrackTitlesAndDescription() { @@ -70,8 +70,8 @@ class GPXParserTests: XCTestCase { """ ) - XCTAssertNoDifference("Frühjahrsgeschlender ach wie schön!", result?.title) - XCTAssertNoDifference("Track description", result?.description) + expectNoDifference("Frühjahrsgeschlender ach wie schön!", result?.title) + expectNoDifference("Track description", result?.description) } func testParsingTrackSegmentsWithoutExtensions() throws { @@ -238,7 +238,7 @@ class GPXParserTests: XCTestCase { let date = try XCTUnwrap(result?.trackPoints.first?.date) - XCTAssertNoDifference(1_351_121_380, date.timeIntervalSince1970) + expectNoDifference(1_351_121_380, date.timeIntervalSince1970) } func testTrackLength() throws { @@ -255,7 +255,7 @@ class GPXParserTests: XCTestCase { parseXML(given(points: [.leipzig, .postPlatz, .dehner])) let elevation = try XCTUnwrap(result?.graph.elevationGain) - XCTAssertNoDifference(0, elevation) + expectNoDifference(0, elevation) } func testItInterpolatesElevationGapsWithElevationAtStartEndEndOfTheTrack() throws { @@ -305,7 +305,7 @@ class GPXParserTests: XCTestCase { ] let result = try XCTUnwrap(result).flatMap { $0.trackPoints.map(\.coordinate) } - XCTAssertNoDifference(expected, result) + expectNoDifference(expected, result) } func testItTakesTheFirstElevationWhenTheTrackStartsWithNoElevation() throws { @@ -326,7 +326,7 @@ class GPXParserTests: XCTestCase { ] let result = try XCTUnwrap(result).flatMap { $0.trackPoints.map(\.coordinate) } - XCTAssertNoDifference(expected, result) + expectNoDifference(expected, result) } func testItTakesTheLastElevationWhenTheTrackEndsWithNoElevation() throws { @@ -351,14 +351,14 @@ class GPXParserTests: XCTestCase { ] let result = try XCTUnwrap(result).flatMap { $0.trackPoints.map(\.coordinate) } - XCTAssertNoDifference(expected, result) + expectNoDifference(expected, result) } func testEmptySegmentIsEmptyTrackPoints() throws { parseXML(given(points: [])) let result = try XCTUnwrap(result) - XCTAssertNoDifference([], result.trackPoints) + expectNoDifference([], result.trackPoints) } func testParsingKeywords() throws { @@ -384,7 +384,7 @@ class GPXParserTests: XCTestCase { """) let sut = try XCTUnwrap(self.result) - XCTAssertNoDifference(["one", "two", "three", "four"], sut.keywords) + expectNoDifference(["one", "two", "three", "four"], sut.keywords) } func testParsingAFileWithoutWaypointDefinitionsHasEmptyWaypoints() throws { @@ -414,7 +414,7 @@ class GPXParserTests: XCTestCase { description: "This is the finish" ) - XCTAssertNoDifference([waypointStart, waypointFinish], sut.waypoints) + expectNoDifference([waypointStart, waypointFinish], sut.waypoints) } func testParsingRouteFiles() throws { @@ -519,12 +519,12 @@ class GPXParserTests: XCTestCase { let sut = GPXFileParser(xmlString: input) let track = try sut.parse().get() - XCTAssertNoDifference([], track.trackPoints) - XCTAssertNoDifference([], track.graph.heightMap) - XCTAssertNoDifference([], track.graph.segments) - XCTAssertNoDifference(.zero, track.graph.distance) - XCTAssertNoDifference(.zero, track.graph.elevationGain) - XCTAssertNoDifference([ + expectNoDifference([], track.trackPoints) + expectNoDifference([], track.graph.heightMap) + expectNoDifference([], track.graph.segments) + expectNoDifference(.zero, track.graph.distance) + expectNoDifference(.zero, track.graph.elevationGain) + expectNoDifference([ Waypoint(coordinate: .init(latitude: 53.060632820504345, longitude: 5.6932974383264616, elevation: 8.4)), Waypoint(coordinate: .init(latitude: 53.06485377614443, longitude: 5.702670398232679, elevation: 8.3)), ], track.waypoints) @@ -556,12 +556,12 @@ class GPXParserTests: XCTestCase { let sut = GPXFileParser(xmlString: input) let track = try sut.parse().get() - XCTAssertNoDifference([], track.trackPoints) - XCTAssertNoDifference([], track.graph.heightMap) - XCTAssertNoDifference([], track.graph.segments) - XCTAssertNoDifference(.zero, track.graph.distance) - XCTAssertNoDifference(.zero, track.graph.elevationGain) - XCTAssertNoDifference([ + expectNoDifference([], track.trackPoints) + expectNoDifference([], track.graph.heightMap) + expectNoDifference([], track.graph.segments) + expectNoDifference(.zero, track.graph.distance) + expectNoDifference(.zero, track.graph.elevationGain) + expectNoDifference([ Waypoint(coordinate: .init(latitude: 53.060632820504345, longitude: 5.6932974383264616, elevation: 8.4)), Waypoint(coordinate: .init(latitude: 53.06485377614443, longitude: 5.702670398232679, elevation: 8.3)), ], track.waypoints) diff --git a/Tests/GPXKitTests/GPXTrackTests.swift b/Tests/GPXKitTests/GPXTrackTests.swift index a556a58..50b0338 100644 --- a/Tests/GPXKitTests/GPXTrackTests.swift +++ b/Tests/GPXKitTests/GPXTrackTests.swift @@ -27,7 +27,7 @@ final class GPXTrackTests: XCTestCase { func testBoundingBoxForEmptyTrack() { givenTrack(with: []) - XCTAssertNoDifference(.empty, sut.bounds) + expectNoDifference(.empty, sut.bounds) } func testBoundingBoxWithOnePointHasThePointAsBoundingBox() { @@ -40,7 +40,7 @@ final class GPXTrackTests: XCTestCase { maxLatitude: coord.latitude, maxLongitude: coord.longitude ) - XCTAssertNoDifference(expected, sut.bounds) + expectNoDifference(expected, sut.bounds) } func testBoundsHasTheMinimumAndMaximumCoordinates() { @@ -59,7 +59,7 @@ final class GPXTrackTests: XCTestCase { maxLatitude: 79, maxLongitude: 120 ) - XCTAssertNoDifference(expected, sut.bounds) + expectNoDifference(expected, sut.bounds) } func testGradeSegments() throws { @@ -82,7 +82,7 @@ final class GPXTrackTests: XCTestCase { XCTUnwrap(.init(start: 200, end: 300, elevationAtStart: 129.64, elevationAtEnd: 100.58)), XCTUnwrap(.init(start: 300, end: sut.graph.distance, elevationAtStart: 100.58, elevationAtEnd: 103.55)) ] - XCTAssertNoDifference(expected, sut.graph.gradeSegments) + expectNoDifference(expected, sut.graph.gradeSegments) } func testGraphHasTheDistancesFromTheTrackPointsSpeed() { @@ -97,15 +97,15 @@ final class GPXTrackTests: XCTestCase { let sut = GPXTrack(title: "Track", trackPoints: points) - XCTAssertNoDifference(4, sut.graph.distance) - XCTAssertNoDifference([ + expectNoDifference(4, sut.graph.distance) + expectNoDifference([ DistanceHeight(distance: 0, elevation: 0), DistanceHeight(distance: 1, elevation: 0), DistanceHeight(distance: 2, elevation: 0), DistanceHeight(distance: 3, elevation: 0), DistanceHeight(distance: 4, elevation: 0), ], sut.graph.heightMap) - XCTAssertNoDifference([ + expectNoDifference([ .init(coordinate: points[0].coordinate, distanceInMeters: 0), .init(coordinate: points[1].coordinate, distanceInMeters: 1), .init(coordinate: points[2].coordinate, distanceInMeters: 1), diff --git a/Tests/GPXKitTests/TestHelpers.swift b/Tests/GPXKitTests/TestHelpers.swift index b9d8a43..5f8352f 100644 --- a/Tests/GPXKitTests/TestHelpers.swift +++ b/Tests/GPXKitTests/TestHelpers.swift @@ -20,19 +20,19 @@ struct TestGPXPoint: Hashable, GeoCoordinate { } } -fileprivate var iso8601Formatter: ISO8601DateFormatter = { +nonisolated(unsafe) fileprivate let iso8601Formatter: ISO8601DateFormatter = { let formatter = ISO8601DateFormatter() formatter.formatOptions = .withInternetDateTime return formatter }() -fileprivate var importFormatter: ISO8601DateFormatter = { +nonisolated(unsafe)fileprivate let importFormatter: ISO8601DateFormatter = { let formatter = ISO8601DateFormatter() formatter.formatOptions = .withInternetDateTime return formatter }() -fileprivate var fractionalFormatter: ISO8601DateFormatter = { +nonisolated(unsafe) fileprivate let fractionalFormatter: ISO8601DateFormatter = { let formatter = ISO8601DateFormatter() if #available(macOS 10.13, iOS 12, watchOS 5, tvOS 11.0, *) { formatter.formatOptions = [.withFractionalSeconds, .withInternetDateTime] @@ -149,37 +149,42 @@ extension XCTest { _ expected: Date?, _ actual: Date?, granularity: Calendar.Component = .nanosecond, - file: StaticString = #filePath, - line: UInt = #line + fileID: StaticString = #fileID, + filePath: StaticString = #filePath, + line: UInt = #line, + column: UInt = #column ) { guard let lhs = expected, let rhs = actual else { - XCTAssertNoDifference(expected, actual, + expectNoDifference(expected, actual, "Dates are not equal - expected: \(String(describing: expected)), actual: \(String(describing: actual))", - file: file, - line: line ) + fileID: fileID, + filePath: filePath, + line: line, column: column ) return } XCTAssertTrue( Calendar.autoupdatingCurrent .isDate(lhs, equalTo: rhs, toGranularity: granularity), - "Expected dates to be equal - expected: \(lhs), actual: \(rhs)", file: file, line: line + "Expected dates to be equal - expected: \(lhs), actual: \(rhs)", file: filePath, line: line ) } func assertTracksAreEqual( _ expected: GPXTrack, _ actual: GPXTrack, - file: StaticString = #filePath, - line: UInt = #line + fileID: StaticString = #fileID, + filePath: StaticString = #filePath, + line: UInt = #line, + column: UInt = #column ) { - assertDatesEqual(expected.date, actual.date, file: file, line: line) - XCTAssertNoDifference(expected.title, actual.title, file: file, line: line) - XCTAssertNoDifference(expected.description, actual.description, file: file, line: line) - XCTAssertNoDifference(expected.keywords, actual.keywords, file: file, line: line) - XCTAssertNoDifference(expected.trackPoints, actual.trackPoints, file: file, line: line) - XCTAssertNoDifference(expected.graph, actual.graph, file: file, line: line) - XCTAssertNoDifference(expected.bounds, actual.bounds, file: file, line: line) - XCTAssertNoDifference(expected.segments, actual.segments, file: file, line: line) + assertDatesEqual(expected.date, actual.date, fileID: fileID, filePath: filePath, line: line, column: column) + expectNoDifference(expected.title, actual.title, fileID: fileID, filePath: filePath, line: line, column: column) + expectNoDifference(expected.description, actual.description, fileID: fileID, filePath: filePath, line: line, column: column) + expectNoDifference(expected.keywords, actual.keywords, fileID: fileID, filePath: filePath, line: line, column: column) + expectNoDifference(expected.trackPoints, actual.trackPoints, fileID: fileID, filePath: filePath, line: line, column: column) + expectNoDifference(expected.graph, actual.graph, fileID: fileID, filePath: filePath, line: line, column: column) + expectNoDifference(expected.bounds, actual.bounds, fileID: fileID, filePath: filePath, line: line, column: column) + expectNoDifference(expected.segments, actual.segments, fileID: fileID, filePath: filePath, line: line, column: column) } /* @@ -193,32 +198,36 @@ extension XCTest { func assertNodesAreEqual( _ expected: GPXKit.XMLNode, _ actual: GPXKit.XMLNode, - file: StaticString = #filePath, - line: UInt = #line + fileID: StaticString = #fileID, + filePath: StaticString = #filePath, + line: UInt = #line, + column: UInt = #column ) { - XCTAssertNoDifference(expected.content, actual.content, file: file, line: line) - XCTAssertNoDifference(expected.content, actual.content, file: file, line: line) - XCTAssertNoDifference(expected.attributes, actual.attributes, file: file, line: line) - XCTAssertNoDifference(expected.children, actual.children, file: file, line: line) + expectNoDifference(expected.content, actual.content, fileID: fileID, filePath: filePath, line: line, column: column) + expectNoDifference(expected.content, actual.content, fileID: fileID, filePath: filePath, line: line, column: column) + expectNoDifference(expected.attributes, actual.attributes, fileID: fileID, filePath: filePath, line: line, column: column) + expectNoDifference(expected.children, actual.children, fileID: fileID, filePath: filePath, line: line, column: column) } func assertGeoCoordinateEqual( _ expected: GeoCoordinate, _ actual: GeoCoordinate, accuracy: Double = 0.0001, - file: StaticString = #filePath, - line: UInt = #line + fileID: StaticString = #fileID, + filePath: StaticString = #filePath, + line: UInt = #line, + column: UInt = #column ) { XCTAssertEqual(expected.latitude, actual.latitude, accuracy: accuracy, "Expected latitude: \(expected.latitude), got \(actual.latitude)", - file: file, line: line) + file: filePath, line: line) XCTAssertEqual(expected.longitude, actual.longitude, accuracy: accuracy, "Expected longitude: \(expected.longitude), got \(actual.longitude)", - file: file, + file: filePath, line: line) } @@ -226,12 +235,14 @@ extension XCTest { _ expected: T, _ acutal: T, accuracy: Double = 0.00001, - file: StaticString = #filePath, - line: UInt = #line + fileID: StaticString = #fileID, + filePath: StaticString = #filePath, + line: UInt = #line, + column: UInt = #column ) where T.Element: GeoCoordinate { - XCTAssertNoDifference(expected.count, acutal.count) + expectNoDifference(expected.count, acutal.count, fileID: fileID, filePath: filePath, line: line, column: column) zip(expected, acutal).forEach { lhs, rhs in - assertGeoCoordinateEqual(lhs, rhs, accuracy: accuracy, file: file, line: line) + assertGeoCoordinateEqual(lhs, rhs, accuracy: accuracy, fileID: fileID, filePath: filePath, line: line, column: column) } } diff --git a/Tests/GPXKitTests/TrackGraphCoreLocationTests.swift b/Tests/GPXKitTests/TrackGraphCoreLocationTests.swift index 3b5846a..6e3514a 100644 --- a/Tests/GPXKitTests/TrackGraphCoreLocationTests.swift +++ b/Tests/GPXKitTests/TrackGraphCoreLocationTests.swift @@ -19,7 +19,7 @@ extension TrackGraphTests { CLLocationCoordinate2D(latitude: 51.2765020, longitude: 12.3767050), ] - XCTAssertNoDifference(coordinates, sut.coreLocationCoordinates) + expectNoDifference(coordinates, sut.coreLocationCoordinates) } } diff --git a/Tests/GPXKitTests/TrackGraphTests.swift b/Tests/GPXKitTests/TrackGraphTests.swift index 98b2608..56b498a 100644 --- a/Tests/GPXKitTests/TrackGraphTests.swift +++ b/Tests/GPXKitTests/TrackGraphTests.swift @@ -82,7 +82,7 @@ final class TrackGraphTests: XCTestCase { sut = try TrackGraph(coords: coordinates, elevationSmoothing: .segmentation(50)) - XCTAssertNoDifference(0, sut.elevationGain) + expectNoDifference(0, sut.elevationGain) } func testTotalElevationWithDifferentElevation() throws { @@ -98,7 +98,7 @@ final class TrackGraphTests: XCTestCase { sut = try TrackGraph(coords: coordinates, elevationSmoothing: .segmentation(50)) // 10 + 95 + 268 - XCTAssertNoDifference(373, sut.elevationGain) + expectNoDifference(373, sut.elevationGain) } func testInitializationFromGPX() throws { @@ -119,7 +119,7 @@ final class TrackGraphTests: XCTestCase { Coordinate(latitude: 51.2764520, longitude: 12.3767260, elevation: 1), Coordinate(latitude: 51.2765020, longitude: 12.3767050, elevation: 1), ] - XCTAssertNoDifference(expectedCoordinates, sut.segments.map { $0.coordinate }) + expectNoDifference(expectedCoordinates, sut.segments.map { $0.coordinate }) } func testTheInitialElevationIsSubstractedFromTheElevationGain() throws { @@ -135,7 +135,7 @@ final class TrackGraphTests: XCTestCase { sut = try TrackGraph(coords: coordinates, elevationSmoothing: .segmentation(50)) // 10 + 95 + 268 - XCTAssertNoDifference(50, sut.elevationGain) + expectNoDifference(50, sut.elevationGain) } func testElevationGainIsTheSumOfAllElevationDifferences() throws { @@ -150,19 +150,19 @@ final class TrackGraphTests: XCTestCase { sut = try TrackGraph(coords: coordinates, elevationSmoothing: .segmentation(50)) - XCTAssertNoDifference(30 + 80 + 10, sut.elevationGain) + expectNoDifference(30 + 80 + 10, sut.elevationGain) } func testEmptyTrackGraphHasNoClimbs() throws { sut = try TrackGraph(coords: [], elevationSmoothing: .segmentation(50)) - XCTAssertNoDifference([], sut.climbs()) + expectNoDifference([], sut.climbs()) } func testClimbsWithOnePointInTrackIsEmpty() throws { sut = try TrackGraph(coords: [.leipzig], elevationSmoothing: .segmentation(50)) - XCTAssertNoDifference([], sut.climbs()) + expectNoDifference([], sut.climbs()) } func testATrackWithTwoPointsHasOneClimb() throws { @@ -185,7 +185,7 @@ final class TrackGraphTests: XCTestCase { ) ) - XCTAssertNoDifference([expected], sut.climbs()) + expectNoDifference([expected], sut.climbs()) } func testDownhillSectionsWillNotBeInTheClimbs() throws { @@ -194,7 +194,7 @@ final class TrackGraphTests: XCTestCase { elevationSmoothing: .segmentation(50) ) - XCTAssertNoDifference([], sut.climbs()) + expectNoDifference([], sut.climbs()) } func testMultipleAdjacentClimbSegmentsWithDifferentGradesWillBeJoinedTogether() throws { @@ -220,7 +220,7 @@ final class TrackGraphTests: XCTestCase { expectedScore(start: sut.heightMap[2], end: sut.heightMap[3]) ) - XCTAssertNoDifference([expected], sut.climbs()) + expectNoDifference([expected], sut.climbs()) } func testItJoinsAdjacentSegmentsWithTheSameGrade() throws { @@ -228,7 +228,7 @@ final class TrackGraphTests: XCTestCase { .kreisel.offset(north: Double($0) * 1000, elevation: Double($0) * 100) }, elevationSmoothing: .segmentation(50)) - XCTAssertNoDifference([ + expectNoDifference([ Climb( start: sut.heightMap.first!.distance, end: sut.heightMap.last!.distance, @@ -276,7 +276,7 @@ final class TrackGraphTests: XCTestCase { score: expectedScore(start: sut.heightMap[3], end: sut.heightMap[4]) ) - XCTAssertNoDifference([expectedA, expectedB], sut.climbs()) + expectNoDifference([expectedA, expectedB], sut.climbs()) } func testItFiltersOutClimbsWithGradeLessThanMinimumGrade() throws { @@ -297,7 +297,7 @@ final class TrackGraphTests: XCTestCase { score: expectedScore(start: sut.heightMap[0], end: sut.heightMap[1]) ) - XCTAssertNoDifference([expected], sut.climbs(minimumGrade: 0.05)) + expectNoDifference([expected], sut.climbs(minimumGrade: 0.05)) } func testJoiningClimbsWithinMaxJoinDistance() throws { @@ -323,9 +323,9 @@ final class TrackGraphTests: XCTestCase { ) ) - XCTAssertNoDifference([expected], sut.climbs(minimumGrade: 0.05, maxJoinDistance: 200.0)) + expectNoDifference([expected], sut.climbs(minimumGrade: 0.05, maxJoinDistance: 200.0)) - XCTAssertNoDifference([ + expectNoDifference([ Climb( start: sut.heightMap[0].distance, end: sut.heightMap[1].distance, @@ -352,7 +352,7 @@ final class TrackGraphTests: XCTestCase { func testGradeSegmentsForEmptyGraphIsEmptyArray() throws { let sut = try TrackGraph(coords: [], elevationSmoothing: .segmentation(50)) - XCTAssertNoDifference([], sut.gradeSegments) + expectNoDifference([], sut.gradeSegments) } func testGraphWithTheSameGrade() throws { @@ -361,7 +361,7 @@ final class TrackGraphTests: XCTestCase { elevationSmoothing: .segmentation(25) ) - XCTAssertNoDifference( + expectNoDifference( [GradeSegment(start: 0, end: sut.distance, elevationAtStart: 0, elevationAtEnd: 100)], sut.gradeSegments ) @@ -380,7 +380,7 @@ final class TrackGraphTests: XCTestCase { XCTUnwrap(.init(start: 0, end: 100, grade: 0.1, elevationAtStart: 0)), XCTUnwrap(.init(start: 100, end: sut.distance, grade: 0.2, elevationAtStart: 10)), ] - XCTAssertNoDifference(expected, sut.gradeSegments) + expectNoDifference(expected, sut.gradeSegments) } func testGraphShorterThanSegmentDistance() throws { @@ -392,7 +392,7 @@ final class TrackGraphTests: XCTestCase { let expected: [GradeSegment] = try [ XCTUnwrap(GradeSegment(start: 0, end: sut.distance, elevationAtStart: 0, elevationAtEnd: 14.57)), ] - XCTAssertNoDifference(expected, sut.gradeSegments) + expectNoDifference(expected, sut.gradeSegments) } func testNegativeGrades() throws { @@ -417,7 +417,7 @@ final class TrackGraphTests: XCTestCase { elevationAtEnd: 100.56 )), ] - XCTAssertNoDifference(expected, sut.gradeSegments) + expectNoDifference(expected, sut.gradeSegments) } func testGradeSegmentsWhenInitializedFromDefaultInitializer() throws { @@ -445,7 +445,7 @@ final class TrackGraphTests: XCTestCase { elevationAtStart: 100.58 )), ] - XCTAssertNoDifference(expected, sut.gradeSegments) + expectNoDifference(expected, sut.gradeSegments) } func testElevationAtDistanceTestBeyondTheTracksBounds() throws { @@ -476,7 +476,7 @@ final class TrackGraphTests: XCTestCase { ] let sut = try TrackGraph(coords: coords, elevationSmoothing: .segmentation(50)) - XCTAssertNoDifference(start.elevation, sut.elevation(at: 0)) + expectNoDifference(start.elevation, sut.elevation(at: 0)) XCTAssertEqual(first.elevation, try XCTUnwrap(sut.elevation(at: start.distance(to: first))), accuracy: 0.001) XCTAssertEqual(second.elevation, try XCTUnwrap(sut.elevation(at: start.distance(to: second))), accuracy: 0.001) XCTAssertEqual(third.elevation, try XCTUnwrap(sut.elevation(at: start.distance(to: third))), accuracy: 0.001) @@ -530,10 +530,10 @@ final class TrackGraphTests: XCTestCase { DistanceHeight(distance: 199.77620423940783, elevation: 129.70642123410428), DistanceHeight(distance: 299.6643063591117, elevation: 100.56074178631758), ] - XCTAssertNoDifference(expected, sut.heightMap) - XCTAssertNoDifference(29.706421234104283, sut.elevationGain) - try XCTAssertNoDifference(XCTUnwrap(expected.last).distance, sut.distance) - XCTAssertNoDifference([ + expectNoDifference(expected, sut.heightMap) + expectNoDifference(29.706421234104283, sut.elevationGain) + try expectNoDifference(XCTUnwrap(expected.last).distance, sut.distance) + expectNoDifference([ GradeSegment(start: 0, end: 99.88810211970392, grade: 0.1, elevationAtStart: 100), GradeSegment(start: 99.88810211970392, end: 199.77620423940783, grade: 0.2, elevationAtStart: 110), GradeSegment( @@ -543,6 +543,6 @@ final class TrackGraphTests: XCTestCase { elevationAtEnd: 100.56074178631758 ), ], sut.gradeSegments) - XCTAssertNoDifference(sut.distance, sut.gradeSegments.last?.end) + expectNoDifference(sut.distance, sut.gradeSegments.last?.end) } }