Skip to content

Commit 83f89b7

Browse files
committed
Convert all tests to Swift Testing
1 parent 8aaa2bc commit 83f89b7

File tree

3 files changed

+43
-32
lines changed

3 files changed

+43
-32
lines changed

Tests/GeoProjectorTests/MapBoundsTests.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55
// Created by Adrian Schönig on 9/12/2022.
66
//
77

8-
import XCTest
8+
#if canImport(Testing)
9+
import Testing
910

1011
@testable import GeoProjector
1112

12-
final class MapBoundsTests: XCTestCase {
13-
func testEqualEarthBounds() {
14-
guard case let .bezier(bounds) = Projections.EqualEarth().mapBounds else { return XCTFail() }
15-
XCTAssertEqual(bounds.count, 82)
13+
struct MapBoundsTests {
14+
@Test func equalEarthBounds() {
15+
guard case let .bezier(bounds) = Projections.EqualEarth().mapBounds else {
16+
Issue.record("Expected bezier map bounds")
17+
return
18+
}
19+
#expect(bounds.count == 82)
1620
}
17-
1821
}
22+
23+
#endif
Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
1-
import XCTest
1+
#if canImport(Testing)
2+
import Testing
23

34
import GeoJSONKit
45
@testable import GeoProjector
56

6-
final class ProjectionTests: XCTestCase {
7+
struct ProjectionTests {
78

8-
func testFlatSquare() throws {
9+
@Test func flatSquare() throws {
910
let topLeft = GeoJSON.Position(latitude: 90, longitude: -180)
10-
XCTAssertEqual(Projections.Equirectangular().point(for: topLeft, size: .init(width: 200, height: 100), coordinateSystem: .topLeft)?.0, .init(x: 0, y: 0))
11+
#expect(Projections.Equirectangular().point(for: topLeft, size: .init(width: 200, height: 100), coordinateSystem: .topLeft)?.0 == .init(x: 0, y: 0))
1112

1213
let topRight = GeoJSON.Position(latitude: 90, longitude: 180)
13-
XCTAssertEqual(Projections.Equirectangular().point(for: topRight, size: .init(width: 200, height: 100), coordinateSystem: .topLeft)?.0, .init(x: 200, y: 0))
14+
#expect(Projections.Equirectangular().point(for: topRight, size: .init(width: 200, height: 100), coordinateSystem: .topLeft)?.0 == .init(x: 200, y: 0))
1415

1516
let bottomLeft = GeoJSON.Position(latitude: -90, longitude: -180)
16-
XCTAssertEqual(Projections.Equirectangular().point(for: bottomLeft, size: .init(width: 200, height: 100), coordinateSystem: .topLeft)?.0, .init(x: 0, y: 100))
17+
#expect(Projections.Equirectangular().point(for: bottomLeft, size: .init(width: 200, height: 100), coordinateSystem: .topLeft)?.0 == .init(x: 0, y: 100))
1718

1819
let bottomRight = GeoJSON.Position(latitude: -90, longitude: 180)
19-
XCTAssertEqual(Projections.Equirectangular().point(for: bottomRight, size: .init(width: 200, height: 100), coordinateSystem: .topLeft)?.0, .init(x: 200, y: 100))
20+
#expect(Projections.Equirectangular().point(for: bottomRight, size: .init(width: 200, height: 100), coordinateSystem: .topLeft)?.0 == .init(x: 200, y: 100))
2021

2122
let zeroZero = GeoJSON.Position(latitude: 0, longitude: 0)
22-
XCTAssertEqual(Projections.Equirectangular().point(for: zeroZero, size: .init(width: 200, height: 100), coordinateSystem: .topLeft)?.0, .init(x: 100, y: 50))
23+
#expect(Projections.Equirectangular().point(for: zeroZero, size: .init(width: 200, height: 100), coordinateSystem: .topLeft)?.0 == .init(x: 100, y: 50))
2324
}
2425

25-
func testOrthographic() throws {
26+
@Test func orthographic() throws {
2627
let zeroZero = GeoJSON.Position(latitude: 0, longitude: 0)
27-
XCTAssertEqual(Projections.Orthographic().point(for: zeroZero, size: .init(width: 100, height: 100), coordinateSystem: .topLeft)?.0, .init(x: 50, y: 50))
28+
#expect(Projections.Orthographic().point(for: zeroZero, size: .init(width: 100, height: 100), coordinateSystem: .topLeft)?.0 == .init(x: 50, y: 50))
2829

2930
let easternOrthographic = Projections.Orthographic(reference: .init(latitude: 0, longitude: 100))
3031
let sydney = GeoJSON.Position(latitude: -33.8, longitude: 151.3)
3132
let projected = easternOrthographic.point(for: sydney, size: .init(width: 100, height: 100), coordinateSystem: .topLeft)?.0
32-
XCTAssertEqual(projected?.x ?? 0, 82.4, accuracy: 0.1)
33-
XCTAssertEqual(projected?.y ?? 0, 77.8, accuracy: 0.1)
33+
#expect(abs((projected?.x ?? 0) - 82.4) < 0.1)
34+
#expect(abs((projected?.y ?? 0) - 77.8) < 0.1)
3435
}
3536

3637
}
@@ -41,3 +42,5 @@ extension Projection {
4142
return self.point(for: point, size: size, zoomTo: zoomTo, insets: insets, coordinateSystem: coordinateSystem)
4243
}
4344
}
45+
46+
#endif

Tests/GeoProjectorTests/TranslationTests.swift

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,35 @@
55
// Created by Adrian Schönig on 9/12/2022.
66
//
77

8-
import XCTest
8+
#if canImport(Testing)
9+
import Testing
910

1011
@testable import GeoProjector
1112

12-
final class TranslationTests: XCTestCase {
13-
func testEquirectangularInSquare() throws {
14-
XCTAssertEqual(Projections.Equirectangular().translate(Point(x: 0, y: 0), to: .init(width: 100, height: 100), coordinateSystem: .topLeft), .init(x: 50, y: 50))
13+
struct TranslationTests {
14+
@Test func equirectangularInSquare() throws {
15+
#expect(Projections.Equirectangular().translate(Point(x: 0, y: 0), to: .init(width: 100, height: 100), coordinateSystem: .topLeft) == .init(x: 50, y: 50))
1516

16-
XCTAssertEqual(Projections.Equirectangular().translate(Point(x: -1 * .pi, y: 0.5 * .pi), to: .init(width: 100, height: 100), coordinateSystem: .topLeft), .init(x: 0, y: 25))
17+
#expect(Projections.Equirectangular().translate(Point(x: -1 * .pi, y: 0.5 * .pi), to: .init(width: 100, height: 100), coordinateSystem: .topLeft) == .init(x: 0, y: 25))
1718

18-
XCTAssertEqual(Projections.Equirectangular().translate(Point(x: .pi, y: 0.5 * .pi), to: .init(width: 100, height: 100), coordinateSystem: .topLeft), .init(x: 100, y: 25))
19+
#expect(Projections.Equirectangular().translate(Point(x: .pi, y: 0.5 * .pi), to: .init(width: 100, height: 100), coordinateSystem: .topLeft) == .init(x: 100, y: 25))
1920

20-
XCTAssertEqual(Projections.Equirectangular().translate(Point(x: .pi, y: -0.5 * .pi), to: .init(width: 100, height: 100), coordinateSystem: .topLeft), .init(x: 100, y: 75))
21+
#expect(Projections.Equirectangular().translate(Point(x: .pi, y: -0.5 * .pi), to: .init(width: 100, height: 100), coordinateSystem: .topLeft) == .init(x: 100, y: 75))
2122

22-
XCTAssertEqual(Projections.Equirectangular().translate(Point(x: -1 * .pi, y: -0.5 * .pi), to: .init(width: 100, height: 100), coordinateSystem: .topLeft), .init(x: 0, y: 75))
23+
#expect(Projections.Equirectangular().translate(Point(x: -1 * .pi, y: -0.5 * .pi), to: .init(width: 100, height: 100), coordinateSystem: .topLeft) == .init(x: 0, y: 75))
2324
}
2425

25-
func testEquirectangularInWideStripe() throws {
26-
XCTAssertEqual(Projections.Equirectangular().translate(Point(x: 0, y: 0), to: .init(width: 400, height: 100), coordinateSystem: .topLeft), .init(x: 200, y: 50))
26+
@Test func equirectangularInWideStripe() throws {
27+
#expect(Projections.Equirectangular().translate(Point(x: 0, y: 0), to: .init(width: 400, height: 100), coordinateSystem: .topLeft) == .init(x: 200, y: 50))
2728

28-
XCTAssertEqual(Projections.Equirectangular().translate(Point(x: -1 * .pi, y: 0.5 * .pi), to: .init(width: 400, height: 100), coordinateSystem: .topLeft), .init(x: 100, y: 0))
29+
#expect(Projections.Equirectangular().translate(Point(x: -1 * .pi, y: 0.5 * .pi), to: .init(width: 400, height: 100), coordinateSystem: .topLeft) == .init(x: 100, y: 0))
2930

30-
XCTAssertEqual(Projections.Equirectangular().translate(Point(x: .pi, y: 0.5 * .pi), to: .init(width: 400, height: 100), coordinateSystem: .topLeft), .init(x: 300, y: 0))
31+
#expect(Projections.Equirectangular().translate(Point(x: .pi, y: 0.5 * .pi), to: .init(width: 400, height: 100), coordinateSystem: .topLeft) == .init(x: 300, y: 0))
3132

32-
XCTAssertEqual(Projections.Equirectangular().translate(Point(x: .pi, y: -0.5 * .pi), to: .init(width: 400, height: 100), coordinateSystem: .topLeft), .init(x: 300, y: 100))
33+
#expect(Projections.Equirectangular().translate(Point(x: .pi, y: -0.5 * .pi), to: .init(width: 400, height: 100), coordinateSystem: .topLeft) == .init(x: 300, y: 100))
3334

34-
XCTAssertEqual(Projections.Equirectangular().translate(Point(x: -1 * .pi, y: -0.5 * .pi), to: .init(width: 400, height: 100), coordinateSystem: .topLeft), .init(x: 100, y: 100))
35+
#expect(Projections.Equirectangular().translate(Point(x: -1 * .pi, y: -0.5 * .pi), to: .init(width: 400, height: 100), coordinateSystem: .topLeft) == .init(x: 100, y: 100))
3536
}
3637
}
38+
39+
#endif

0 commit comments

Comments
 (0)