Skip to content

Commit

Permalink
Add some missing main actor annotations in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NickEntin committed Aug 29, 2024
1 parent a2ba600 commit 9799342
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ParalayoutTests/AngleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ import XCTest

final class AngleTests: XCTestCase {

@MainActor
func testConstants() {
XCTAssertEqual(Angle.zero.radians, 0)
XCTAssertEqual(Angle.right.degrees, 90, accuracy: 1e-4)
XCTAssertEqual(Angle.halfCircle.degrees, 180, accuracy: 1e-4)
XCTAssertEqual(Angle.fullCircle.degrees, 360, accuracy: 1e-4)
}

@MainActor
func testValueInitializers() {
func assertRadianInitPreservesValue(_ radians: CGFloat) {
XCTAssertEqual(Angle(radians: radians).radians, radians)
Expand All @@ -45,6 +47,7 @@ final class AngleTests: XCTestCase {
}
}

@MainActor
func testPointInitializer() {
let rect = CGRect(x: -1, y: -1, width: 2, height: 2)
let centerPoint = Position.center.point(in: rect, layoutDirection: .leftToRight)
Expand Down Expand Up @@ -94,6 +97,7 @@ final class AngleTests: XCTestCase {
)
}

@MainActor
func testPointAtDistance() {
let rect = CGRect(x: -1, y: -1, width: 2, height: 2)
let diagonalUnit: CGFloat = sqrt(2)
Expand Down Expand Up @@ -151,6 +155,7 @@ final class AngleTests: XCTestCase {
}
}

@MainActor
func testPositiveNormalization() {
// In the range [0,2π), the angle should be unmutated.
XCTAssertEqual(Angle.zero.normalizedPositive.radians, Angle.zero.radians)
Expand All @@ -168,6 +173,7 @@ final class AngleTests: XCTestCase {
XCTAssertEqual(Angle(radians: -.pi / 2).normalizedPositive.radians, 1.5 * .pi, accuracy: 1e-4)
}

@MainActor
func testHalfCircleNormalization() {
// In the range [-180º,180º), the angle should be unmutated.
XCTAssertEqual(Angle.zero.normalizedHalfCircle.radians, Angle.zero.radians, accuracy: 1e-4)
Expand Down
1 change: 1 addition & 0 deletions ParalayoutTests/DistributionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ final class DistributionTests: XCTestCase {

// MARK: - Tests - Orthogonal Alignment

@MainActor
func testOrthogonalAlignmentInHorizontalDistribution() {
// The layout direction shouldn't affect the orthogonal alignment in a horizontal distribution.
for forcedLayoutDirection in [UISemanticContentAttribute.forceLeftToRight, .forceRightToLeft] {
Expand Down
14 changes: 14 additions & 0 deletions ParalayoutTests/GeometryAdditionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ final class GeometryAdditionsTests: XCTestCase {

// MARK: - Tests - Operators

@MainActor
func testOffsetOperators() {
// Combine offsets.
XCTAssertEqual(
Expand Down Expand Up @@ -66,6 +67,7 @@ final class GeometryAdditionsTests: XCTestCase {

// MARK: - Tests - CGPoint Extensions

@MainActor
func testMidpoint() {
// The midpoint between two of the same point should be that point.
XCTAssertEqual(CGPoint(midpointBetween: .zero, and: .zero), .zero)
Expand All @@ -85,6 +87,7 @@ final class GeometryAdditionsTests: XCTestCase {
)
}

@MainActor
func testDistanceBetweenPoints() {
// A point's distance from itself is always zero.
XCTAssertEqual(CGPoint.zero.distance(to: .zero), 0)
Expand All @@ -102,12 +105,14 @@ final class GeometryAdditionsTests: XCTestCase {

// MARK: - Tests - CGSize Extensions

@MainActor
func testSizeOfGreatestFiniteMagnitude() {
let size = CGSize.greatestFiniteMagnitude
XCTAssertEqual(size.width, .greatestFiniteMagnitude)
XCTAssertEqual(size.height, .greatestFiniteMagnitude)
}

@MainActor
func testScalingSize() {
// A zero size scaled by anything should still be zero.
XCTAssertEqual(CGSize.zero * 100, .zero)
Expand All @@ -124,11 +129,13 @@ final class GeometryAdditionsTests: XCTestCase {

// MARK: - Tests - CGRect Extensions

@MainActor
func testCGRectCreation() {
XCTAssertEqual(CGRect(left: 10, top: 10, right: 50, bottom: 50), CGRect(x: 10, y: 10, width: 40, height: 40))
XCTAssertEqual(CGRect(left: 50, top: 50, right: 10, bottom: 10), CGRect(x: 10, y: 10, width: 40, height: 40))
}

@MainActor
func testCGRectInset() {
// CGRect.insetBy(left:top:right:bottom:)
XCTAssertEqual(
Expand Down Expand Up @@ -165,6 +172,7 @@ final class GeometryAdditionsTests: XCTestCase {
)
}

@MainActor
func testCGRectSlice() {
// CGRect.zero tests
XCTAssert(CGRect.zero.slice(from: .minXEdge, amount: 0) == (.zero, .zero))
Expand Down Expand Up @@ -201,18 +209,21 @@ final class GeometryAdditionsTests: XCTestCase {

// MARK: - Tests - UIEdgeInsets Extensions

@MainActor
func testCreateUniformInsets() {
XCTAssertEqual(UIEdgeInsets(uniform: 20), UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20))
XCTAssertEqual(UIEdgeInsets(uniformOutset: 20), UIEdgeInsets(top: -20, left: -20, bottom: -20, right: -20))
}

@MainActor
func testCreateInsetsByAxis() {
XCTAssertEqual(
UIEdgeInsets(vertical: 10, horizontal: 20),
UIEdgeInsets(top: 10, left: 20, bottom: 10, right: 20)
)
}

@MainActor
func testInsetAmountOnAxis() {
XCTAssertEqual(UIEdgeInsets(top: 10, left: 20, bottom: 30, right: 40).horizontalAmount, 60)
XCTAssertEqual(UIEdgeInsets(top: 10, left: 20, bottom: 15, right: 40).verticalAmount, 25)
Expand All @@ -223,6 +234,7 @@ final class GeometryAdditionsTests: XCTestCase {

// MARK: - Tests - NSDirectionalEdgeInsets Extensions

@MainActor
func testCreateUniformDirectionalInsets() {
XCTAssertEqual(
NSDirectionalEdgeInsets(uniform: 20),
Expand All @@ -234,13 +246,15 @@ final class GeometryAdditionsTests: XCTestCase {
)
}

@MainActor
func testCreateDirectionalInsetsByAxis() {
XCTAssertEqual(
NSDirectionalEdgeInsets(vertical: 10, horizontal: 20),
NSDirectionalEdgeInsets(top: 10, leading: 20, bottom: 10, trailing: 20)
)
}

@MainActor
func testDirectionalInsetAmountOnAxis() {
XCTAssertEqual(NSDirectionalEdgeInsets(top: 10, leading: 20, bottom: 30, trailing: 40).horizontalAmount, 60)
XCTAssertEqual(NSDirectionalEdgeInsets(top: 10, leading: 20, bottom: 15, trailing: 40).verticalAmount, 25)
Expand Down
25 changes: 25 additions & 0 deletions ParalayoutTests/InterpolationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ final class InterpolationTests: XCTestCase {

// MARK: - CGRect

@MainActor
func testCGRectInterpolation() {
let startRect = CGRect(x: 1, y: 2, width: 5, height: 6)
let endRect = CGRect(x: 3, y: 4, width: 7, height: 8)
Expand All @@ -33,6 +34,7 @@ final class InterpolationTests: XCTestCase {

// MARK: - Float

@MainActor
func testLinearFloatInterpolation_fromMinToMax() {
let value: Float = 3.0
let min: Float = 1.0
Expand All @@ -43,6 +45,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 3)
}

@MainActor
func testEaseInFloatInterpolation_fromMinToMax() {
let value: Float = 3.0
let min: Float = 1.0
Expand All @@ -53,6 +56,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 2)
}

@MainActor
func testEaseOutFloatInterpolation_fromMinToMax() {
let value: Float = 3.0
let min: Float = 1.0
Expand All @@ -63,6 +67,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 4)
}

@MainActor
func testEaseInOutFloatInterpolation_fromMinToMax() {
let value: Float = 3.0
let min: Float = 1.0
Expand All @@ -73,6 +78,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 3)
}

@MainActor
func testLinearFloatInterpolation_ofUnit() {
let value: Float = 3.0
let min: Float = 1.0
Expand All @@ -82,6 +88,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 5)
}

@MainActor
func testEaseInFloatInterpolation_ofUnit() {
let value: Float = 3.0
let min: Float = 1.0
Expand All @@ -91,6 +98,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 5)
}

@MainActor
func testEaseOutFloatInterpolation_ofUnit() {
let value: Float = 3.0
let min: Float = 1.0
Expand All @@ -100,6 +108,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 5)
}

@MainActor
func testEaseInOutFloatInterpolation_ofUnit() {
let value: Float = 3.0
let min: Float = 1.0
Expand All @@ -109,6 +118,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 5)
}

@MainActor
func testLinearFloatInterpolation_fromMinToMax_withMidpoint() {
let value: Float = 3.0
let min: Float = 1.0
Expand All @@ -120,6 +130,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 2)
}

@MainActor
func testEaseInFloatInterpolation_fromMinToMax_withMidpoint() {
let value: Float = 3.0
let min: Float = 1.0
Expand All @@ -131,6 +142,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 2)
}

@MainActor
func testEaseOutFloatInterpolation_fromMinToMax_withMidpoint() {
let value: Float = 3.0
let min: Float = 1.0
Expand All @@ -142,6 +154,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 2)
}

@MainActor
func testEaseInOutFloatInterpolation_fromMinToMax_withMidpoint() {
let value: Float = 3.0
let min: Float = 1.0
Expand All @@ -155,6 +168,7 @@ final class InterpolationTests: XCTestCase {

// MARK: - Double

@MainActor
func testLinearDoubleInterpolation_fromMinToMax() {
let value: Double = 3.0
let min: Double = 1.0
Expand All @@ -165,6 +179,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 3)
}

@MainActor
func testEaseInDoubleInterpolation_fromMinToMax() {
let value: Double = 3.0
let min: Double = 1.0
Expand All @@ -175,6 +190,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 2)
}

@MainActor
func testEaseOutDoubleInterpolation_fromMinToMax() {
let value: Double = 3.0
let min: Double = 1.0
Expand All @@ -185,6 +201,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 4)
}

@MainActor
func testEaseInOutDoubleInterpolation_fromMinToMax() {
let value: Double = 3.0
let min: Double = 1.0
Expand All @@ -195,6 +212,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 3)
}

@MainActor
func testLinearDoubleInterpolation_ofUnit() {
let value: Double = 3.0
let min: Double = 1.0
Expand All @@ -204,6 +222,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 5)
}

@MainActor
func testEaseInDoubleInterpolation_ofUnit() {
let value: Double = 3.0
let min: Double = 1.0
Expand All @@ -213,6 +232,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 5)
}

@MainActor
func testEaseOutDoubleInterpolation_ofUnit() {
let value: Double = 3.0
let min: Double = 1.0
Expand All @@ -222,6 +242,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 5)
}

@MainActor
func testEaseInOutDoubleInterpolation_ofUnit() {
let value: Double = 3.0
let min: Double = 1.0
Expand All @@ -231,6 +252,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 5)
}

@MainActor
func testLinearDoubleInterpolation_fromMinToMax_withMidpoint() {
let value: Double = 3.0
let min: Double = 1.0
Expand All @@ -242,6 +264,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 2)
}

@MainActor
func testEaseInDoubleInterpolation_fromMinToMax_withMidpoint() {
let value: Double = 3.0
let min: Double = 1.0
Expand All @@ -253,6 +276,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 2)
}

@MainActor
func testEaseOutDoubleInterpolation_fromMinToMax_withMidpoint() {
let value: Double = 3.0
let min: Double = 1.0
Expand All @@ -264,6 +288,7 @@ final class InterpolationTests: XCTestCase {
XCTAssertEqual(interpolation, 2)
}

@MainActor
func testEaseInOutDoubleInterpolation_fromMinToMax_withMidpoint() {
let value: Double = 3.0
let min: Double = 1.0
Expand Down
2 changes: 2 additions & 0 deletions ParalayoutTests/PositionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import XCTest

final class PositionTests: XCTestCase {

@MainActor
func testResolvePositionsInLeftToRightLayout() {
func resolve(_ position: Position) -> ResolvedPosition {
return ResolvedPosition(resolving: position, with: .leftToRight)
Expand All @@ -45,6 +46,7 @@ final class PositionTests: XCTestCase {
XCTAssertEqual(resolve(.bottomTrailing), .bottomRight)
}

@MainActor
func testResolvePositionsInRightToLeftLayout() {
func resolve(_ position: Position) -> ResolvedPosition {
return ResolvedPosition(resolving: position, with: .rightToLeft)
Expand Down
Loading

0 comments on commit 9799342

Please sign in to comment.