diff --git a/Tests/MapboxMapsTests/Foundation/CameraStateTests.swift b/Tests/MapboxMapsTests/Foundation/CameraStateTests.swift index 8bdac9a8163d..e76cb941a9cf 100644 --- a/Tests/MapboxMapsTests/Foundation/CameraStateTests.swift +++ b/Tests/MapboxMapsTests/Foundation/CameraStateTests.swift @@ -11,7 +11,7 @@ final class CameraStateTests: XCTestCase { override func setUp() { super.tearDown() - center = .random() + center = .testConstantValue() padding = .random() anchor = CGPoint( x: .random(in: 0...100), diff --git a/Tests/MapboxMapsTests/Foundation/Extensions/Core/FeatureExtensionValueTests.swift b/Tests/MapboxMapsTests/Foundation/Extensions/Core/FeatureExtensionValueTests.swift index c7a0f10889f8..2f17f2aa6abb 100644 --- a/Tests/MapboxMapsTests/Foundation/Extensions/Core/FeatureExtensionValueTests.swift +++ b/Tests/MapboxMapsTests/Foundation/Extensions/Core/FeatureExtensionValueTests.swift @@ -15,7 +15,7 @@ final class FeatureExtensionValueTests: XCTestCase { func testInitializationWithWithNonNilValues() throws { let value = Int.random(in: 0..<100) let features = Array.random(withLength: .random(in: 0..<10)) { () -> Feature in - var feature = Feature(geometry: Point(.random())) + var feature = Feature(geometry: Point(.testConstantValue())) feature.identifier = .number(Double(Int.random(in: (.min)...(.max)))) return feature } @@ -38,7 +38,7 @@ final class FeatureExtensionValueTests: XCTestCase { func testNonNilFeatures() { let features = Array.random(withLength: .random(in: 0..<10)) { () -> Feature in - var feature = Feature(geometry: Point(.random())) + var feature = Feature(geometry: Point(.testConstantValue())) feature.identifier = .number(Double(Int.random(in: (.min)...(.max)))) return feature }.map(MapboxCommon.Feature.init(_:)) diff --git a/Tests/MapboxMapsTests/Foundation/Extensions/Core/OfflineRegionGeometryDefinitionTests.swift b/Tests/MapboxMapsTests/Foundation/Extensions/Core/OfflineRegionGeometryDefinitionTests.swift index 0a65e41898ee..8a337fe39d45 100644 --- a/Tests/MapboxMapsTests/Foundation/Extensions/Core/OfflineRegionGeometryDefinitionTests.swift +++ b/Tests/MapboxMapsTests/Foundation/Extensions/Core/OfflineRegionGeometryDefinitionTests.swift @@ -14,7 +14,7 @@ final class OfflineRegionGeometryDefinitionTests: XCTestCase { override func setUp() { super.setUp() styleURL = .randomASCII(withLength: .random(in: 0...50)) - coordinate = .random() + coordinate = .testConstantValue() minZoom = .random(in: 0..<10) maxZoom = .random(in: 10...20) // swiftlint:disable:next syntactic_sugar diff --git a/Tests/MapboxMapsTests/Foundation/Extensions/Turf/FeatureTests.swift b/Tests/MapboxMapsTests/Foundation/Extensions/Turf/FeatureTests.swift index 8105e3e1e04c..fab805481a5a 100644 --- a/Tests/MapboxMapsTests/Foundation/Extensions/Turf/FeatureTests.swift +++ b/Tests/MapboxMapsTests/Foundation/Extensions/Turf/FeatureTests.swift @@ -3,7 +3,7 @@ import XCTest final class FeatureTests: XCTestCase { - let geometry = Geometry.point(Point(.random())) + let geometry = Geometry.point(Point(.testConstantValue())) func testInitializingTurfFeatureFromCommonFeatureNilIdentifier() throws { let commonFeature = MapboxCommon.Feature( diff --git a/Tests/MapboxMapsTests/Foundation/Helpers/CLLocationCoordinate2DCodable.test.swift b/Tests/MapboxMapsTests/Foundation/Helpers/CLLocationCoordinate2DCodable.test.swift index be75e2389ed2..27f983c84789 100644 --- a/Tests/MapboxMapsTests/Foundation/Helpers/CLLocationCoordinate2DCodable.test.swift +++ b/Tests/MapboxMapsTests/Foundation/Helpers/CLLocationCoordinate2DCodable.test.swift @@ -45,7 +45,7 @@ class CLLocationCoordinate2DCodableTest: XCTestCase { } func testCoreLocationCoordinatesConversion() throws { - let coordinates: CLLocationCoordinate2D = .random() + let coordinates: CLLocationCoordinate2D = .testConstantValue() let codableCoordinates = CLLocationCoordinate2DCodable(coordinates) XCTAssertEqual(coordinates, codableCoordinates.coordinates) diff --git a/Tests/MapboxMapsTests/Foundation/Interpolators/CoordinateInterpolatorTests.swift b/Tests/MapboxMapsTests/Foundation/Interpolators/CoordinateInterpolatorTests.swift index 73190813eefe..e16835b0e906 100644 --- a/Tests/MapboxMapsTests/Foundation/Interpolators/CoordinateInterpolatorTests.swift +++ b/Tests/MapboxMapsTests/Foundation/Interpolators/CoordinateInterpolatorTests.swift @@ -24,8 +24,8 @@ final class CoordinateInterpolatorTests: XCTestCase { } func testInterpolate() throws { - let from = CLLocationCoordinate2D.random() - let to = CLLocationCoordinate2D.random() + let from = CLLocationCoordinate2D.testConstantValue() + let to = CLLocationCoordinate2D.testConstantValue() let fraction = Double.random(in: 0...1) doubleInterpolator.interpolateStub.defaultReturnValue = .random(in: 0..<100) longitudeInterpolator.interpolateStub.defaultReturnValue = .random(in: 0..<100) diff --git a/Tests/MapboxMapsTests/Foundation/Interpolators/Mocks/MockCoordinateInterpolator.swift b/Tests/MapboxMapsTests/Foundation/Interpolators/Mocks/MockCoordinateInterpolator.swift index d8aa2030f18e..93ecd1d94c29 100644 --- a/Tests/MapboxMapsTests/Foundation/Interpolators/Mocks/MockCoordinateInterpolator.swift +++ b/Tests/MapboxMapsTests/Foundation/Interpolators/Mocks/MockCoordinateInterpolator.swift @@ -8,7 +8,7 @@ final class MockCoordinateInterpolator: CoordinateInterpolatorProtocol { var to: CLLocationCoordinate2D var fraction: Double } - let interpolateStub = Stub(defaultReturnValue: .random()) + let interpolateStub = Stub(defaultReturnValue: .testConstantValue()) func interpolate(from: CLLocationCoordinate2D, to: CLLocationCoordinate2D, fraction: Double) -> CLLocationCoordinate2D { interpolateStub.call(with: .init(from: from, to: to, fraction: fraction)) } diff --git a/Tests/MapboxMapsTests/Foundation/MapboxMapTests.swift b/Tests/MapboxMapsTests/Foundation/MapboxMapTests.swift index 18f656243b1a..e66b5e7080c3 100644 --- a/Tests/MapboxMapsTests/Foundation/MapboxMapTests.swift +++ b/Tests/MapboxMapsTests/Foundation/MapboxMapTests.swift @@ -382,7 +382,7 @@ final class MapboxMapTests: XCTestCase { tileId: nil, timestamp: Date()) let cameraChanged = CameraChanged( - cameraState: CameraState(center: .random(), padding: .random(), zoom: 0, bearing: 0, pitch: 0), + cameraState: CameraState(center: .testConstantValue(), padding: .random(), zoom: 0, bearing: 0, pitch: 0), timestamp: Date()) checkEvent(\.onMapIdle, \.onMapIdle, value: MapIdle(timestamp: Date())) diff --git a/Tests/MapboxMapsTests/Foundation/Mocks/MockMapboxMap.swift b/Tests/MapboxMapsTests/Foundation/Mocks/MockMapboxMap.swift index d4547681dbf0..abd3eeaab418 100644 --- a/Tests/MapboxMapsTests/Foundation/Mocks/MockMapboxMap.swift +++ b/Tests/MapboxMapsTests/Foundation/Mocks/MockMapboxMap.swift @@ -48,7 +48,7 @@ final class MockMapboxMap: MapboxMapProtocol { setCameraStub.call(with: cameraOptions) } - let coordinateForPointStub = Stub(defaultReturnValue: .random()) + let coordinateForPointStub = Stub(defaultReturnValue: .testConstantValue()) func coordinate(for point: CGPoint) -> CLLocationCoordinate2D { coordinateForPointStub.call(with: point) } diff --git a/Tests/MapboxMapsTests/Foundation/Random/CameraOptions+Random.swift b/Tests/MapboxMapsTests/Foundation/Random/CameraOptions+Random.swift index 185c6b72708f..67d08a505f4e 100644 --- a/Tests/MapboxMapsTests/Foundation/Random/CameraOptions+Random.swift +++ b/Tests/MapboxMapsTests/Foundation/Random/CameraOptions+Random.swift @@ -13,7 +13,7 @@ extension CameraOptions { } static func random() -> Self { return CameraOptions( - center: .random(), + center: .testConstantValue(), padding: .random(), anchor: .random(), zoom: .random(in: 0...20), diff --git a/Tests/MapboxMapsTests/Foundation/Random/CameraState+Random.swift b/Tests/MapboxMapsTests/Foundation/Random/CameraState+Random.swift index 724da649eeb9..3518b5744195 100644 --- a/Tests/MapboxMapsTests/Foundation/Random/CameraState+Random.swift +++ b/Tests/MapboxMapsTests/Foundation/Random/CameraState+Random.swift @@ -14,7 +14,7 @@ extension CameraState { static func random() -> Self { return CameraState( - center: .random(), + center: .testConstantValue(), padding: .random(), zoom: .random(in: 0...20), bearing: .random(in: 0..<360), diff --git a/Tests/MapboxMapsTests/Foundation/Style/StyleSourceManagerTests.swift b/Tests/MapboxMapsTests/Foundation/Style/StyleSourceManagerTests.swift index 27f7f07c8820..7abad54b9979 100644 --- a/Tests/MapboxMapsTests/Foundation/Style/StyleSourceManagerTests.swift +++ b/Tests/MapboxMapsTests/Foundation/Style/StyleSourceManagerTests.swift @@ -452,7 +452,7 @@ final class StyleSourceManagerTests: XCTestCase { // given let sourceId = String.randomASCII(withLength: 10) let dataId = String.randomASCII(withLength: 11) - let point = Point(.random()) + let point = Point(.testConstantValue()) let featureIdentifier = Double.random(in: 0...1000) var feature = Feature.init(geometry: point.geometry) feature.identifier = .number(featureIdentifier) @@ -476,7 +476,7 @@ final class StyleSourceManagerTests: XCTestCase { // given let sourceId = String.randomASCII(withLength: 10) let dataId = String.randomASCII(withLength: 11) - let point = Point(.random()) + let point = Point(.testConstantValue()) let featureIdentifier = Double.random(in: 0...1000) var feature = Feature.init(geometry: point.geometry) feature.identifier = .number(featureIdentifier) @@ -499,7 +499,7 @@ final class StyleSourceManagerTests: XCTestCase { func testPartialUpdateAPIsDontCancelPreviousUpdates() throws { // given let sourceId = String.randomASCII(withLength: 10) - let point = Point(.random()) + let point = Point(.testConstantValue()) let featureIdentifier = Double.random(in: 0...1000) var feature = Feature.init(geometry: point.geometry) feature.identifier = .number(featureIdentifier) @@ -520,7 +520,7 @@ final class StyleSourceManagerTests: XCTestCase { func testFullUpdateAPIsCancelsAllPreviousUpdates() throws { // given let sourceId = String.randomASCII(withLength: 10) - let point = Point(.random()) + let point = Point(.testConstantValue()) let featureIdentifier = Double.random(in: 0...1000) var feature = Feature.init(geometry: point.geometry) feature.identifier = .number(featureIdentifier) diff --git a/Tests/MapboxMapsTests/Foundation/Style/StyleTests.swift b/Tests/MapboxMapsTests/Foundation/Style/StyleTests.swift index 19277f656b75..87d3ddfe00ce 100644 --- a/Tests/MapboxMapsTests/Foundation/Style/StyleTests.swift +++ b/Tests/MapboxMapsTests/Foundation/Style/StyleTests.swift @@ -422,13 +422,13 @@ final class StyleManagerTests: XCTestCase { styleManager.invalidateStyleCustomGeometrySourceRegionStub.defaultReturnValue = Expected(value: NSNull()) XCTAssertNoThrow(try style.invalidateCustomGeometrySourceRegion( forSourceId: "dummy-source-id", - bounds: CoordinateBounds(southwest: .random(), northeast: .random())) + bounds: CoordinateBounds(southwest: .testConstantValue(), northeast: .testConstantValue())) ) styleManager.invalidateStyleCustomGeometrySourceRegionStub.defaultReturnValue = Expected(error: "Cannot invalidate custom geometry source tile") XCTAssertThrowsError(try style.invalidateCustomGeometrySourceRegion( forSourceId: "dummy-source-id", - bounds: CoordinateBounds(southwest: .random(), northeast: .random())) + bounds: CoordinateBounds(southwest: .testConstantValue(), northeast: .testConstantValue())) ) } @@ -623,7 +623,7 @@ final class StyleManagerTests: XCTestCase { // given let sourceId = String.randomASCII(withLength: 10) let dataId = String.randomASCII(withLength: 11) - let point = Point(.random()) + let point = Point(.testConstantValue()) let featureIdentifier = Double.random(in: 0...1000) var feature = Feature.init(geometry: point.geometry) feature.identifier = .number(featureIdentifier) @@ -643,7 +643,7 @@ final class StyleManagerTests: XCTestCase { // given let sourceId = String.randomASCII(withLength: 10) let dataId = String.randomASCII(withLength: 11) - let point = Point(.random()) + let point = Point(.testConstantValue()) let featureIdentifier = Double.random(in: 0...1000) var feature = Feature.init(geometry: point.geometry) feature.identifier = .number(featureIdentifier) diff --git a/Tests/MapboxMapsTests/Helpers/Random/CLAccuracyAuthorization+Random.swift b/Tests/MapboxMapsTests/Helpers/Random/CLAccuracyAuthorization+Random.swift deleted file mode 100644 index f82184529a2e..000000000000 --- a/Tests/MapboxMapsTests/Helpers/Random/CLAccuracyAuthorization+Random.swift +++ /dev/null @@ -1,7 +0,0 @@ -import CoreLocation - -extension CLAccuracyAuthorization { - static func random() -> Self { - return .random() ? .fullAccuracy : .reducedAccuracy - } -} diff --git a/Tests/MapboxMapsTests/Helpers/Random/CLLocationCoordinate2D+Random.swift b/Tests/MapboxMapsTests/Helpers/Random/CLLocationCoordinate2D+Random.swift index f98ef97ed77d..1296445c37fd 100644 --- a/Tests/MapboxMapsTests/Helpers/Random/CLLocationCoordinate2D+Random.swift +++ b/Tests/MapboxMapsTests/Helpers/Random/CLLocationCoordinate2D+Random.swift @@ -1,9 +1,9 @@ import CoreLocation extension CLLocationCoordinate2D { - static func random() -> Self { + static func testConstantValue() -> Self { return CLLocationCoordinate2D( - latitude: .random(in: -90...90), - longitude: .random(in: -180..<180)) + latitude: .testConstantValue(), + longitude: .testConstantValue()) } } diff --git a/Tests/MapboxMapsTests/Helpers/Random/UIColor+Random.swift b/Tests/MapboxMapsTests/Helpers/Random/UIColor+Random.swift index 1fc6716adff4..80dab83df800 100644 --- a/Tests/MapboxMapsTests/Helpers/Random/UIColor+Random.swift +++ b/Tests/MapboxMapsTests/Helpers/Random/UIColor+Random.swift @@ -8,4 +8,12 @@ extension UIColor { blue: .random(in: 0...1), alpha: .random(in: 0...1)) } + + static func testConstantValue() -> UIColor { + return UIColor( + red: 0.1, + green: 0.2, + blue: 0, + alpha: 1) + } } diff --git a/Tests/MapboxMapsTests/Location/AppleLocationProviderTests.swift b/Tests/MapboxMapsTests/Location/AppleLocationProviderTests.swift index 8a8e667a3ec7..81e65db78d4f 100644 --- a/Tests/MapboxMapsTests/Location/AppleLocationProviderTests.swift +++ b/Tests/MapboxMapsTests/Location/AppleLocationProviderTests.swift @@ -120,8 +120,24 @@ final class AppleLocationProviderTests: XCTestCase { } #endif - func testAddingALocationConsumerDoesNotRequestWhenInUseAuthorizationForOtherStatuses() { - locationManager.compatibleAuthorizationStatus = [.restricted, .denied, .authorizedWhenInUse].randomElement()! + func testAddingALocationConsumerDoesNotRequestWhenInUseAuthorizationForOtherStatusesRestricted() { + locationManager.compatibleAuthorizationStatus = .restricted + + _ = locationProvider.onLocationUpdate.observe { _ in } + + XCTAssertTrue(locationManager.requestWhenInUseAuthorizationStub.invocations.isEmpty) + } + + func testAddingALocationConsumerDoesNotRequestWhenInUseAuthorizationForOtherStatusesDenied() { + locationManager.compatibleAuthorizationStatus = .denied + + _ = locationProvider.onLocationUpdate.observe { _ in } + + XCTAssertTrue(locationManager.requestWhenInUseAuthorizationStub.invocations.isEmpty) + } + + func testAddingALocationConsumerDoesNotRequestWhenInUseAuthorizationForOtherStatusesAuthWhenInUse() { + locationManager.compatibleAuthorizationStatus = .authorizedWhenInUse _ = locationProvider.onLocationUpdate.observe { _ in } @@ -191,8 +207,8 @@ final class AppleLocationProviderTests: XCTestCase { XCTAssertEqual(observedViaObjectAPI, observed) XCTAssertEqual(locationProvider.latestHeading, nil) - let heading1 = Heading.random() - let heading2 = Heading.random() + let heading1 = Heading.testConstantValue() + let heading2 = Heading.testConstantValue() let clHeading1 = MockHeading() clHeading1.trueHeadingStub.defaultReturnValue = heading1.direction @@ -215,7 +231,7 @@ final class AppleLocationProviderTests: XCTestCase { #endif func testConsumersAreNotifiedOfNewAccuracyAuthorizationsAfterLatestLocationIsUpdated() { - let coordinate = CLLocationCoordinate2D.random() + let coordinate = CLLocationCoordinate2D.testConstantValue() let clLocation = CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude) let accuracyAuthorization = CLAccuracyAuthorization.reducedAccuracy @@ -306,7 +322,7 @@ final class AppleLocationProviderTests: XCTestCase { func testDidChangeAuthorizationNotifiesDelegateIfAccuracyAuthorizationChanged() { let accuracyAuthorizationValues: [CLAccuracyAuthorization] = [.fullAccuracy, .reducedAccuracy] - let initialIndex = Int.random(in: 0...1) + let initialIndex = 0 let changedIndex = (initialIndex + 1) % 2 // the other one locationManager.compatibleAccuracyAuthorization = accuracyAuthorizationValues[initialIndex] locationProvider = AppleLocationProvider( @@ -326,8 +342,8 @@ final class AppleLocationProviderTests: XCTestCase { XCTAssertEqual(delegate.didChangeAccuracyAuthorizationStub.invocations.first?.parameters.accuracyAuthorization, locationManager.compatibleAccuracyAuthorization) } - func testDidChangeAuthorizationDoesNotNotifyDelegateIfAccuracyAuthorizationDidNotChange() { - locationManager.compatibleAccuracyAuthorization = [.fullAccuracy, .reducedAccuracy].randomElement()! + func testDidChangeAuthorizationDoesNotNotifyDelegateIfAccuracyAuthorizationDidNotChangeFull() { + locationManager.compatibleAccuracyAuthorization = .fullAccuracy locationProvider = AppleLocationProvider( locationManager: locationManager, interfaceOrientation: $interfaceOrientation, @@ -342,6 +358,22 @@ final class AppleLocationProviderTests: XCTestCase { XCTAssertEqual(delegate.didChangeAccuracyAuthorizationStub.invocations.count, 0) } + func testDidChangeAuthorizationDoesNotNotifyDelegateIfAccuracyAuthorizationDidNotChangeReduced() { + locationManager.compatibleAccuracyAuthorization = .reducedAccuracy + locationProvider = AppleLocationProvider( + locationManager: locationManager, + interfaceOrientation: $interfaceOrientation, + mayRequestWhenInUseAuthorization: true, + locationManagerDelegateProxy: locationManagerDelegateProxy) + delegate = MockLocationProducerDelegate() + locationProvider.delegate = delegate + addNoopLocationObserver() + + locationProvider.locationManagerDidChangeAuthorization(CLLocationManager()) + + XCTAssertEqual(delegate.didChangeAccuracyAuthorizationStub.invocations.count, 0) + } + func testRequestsTemporaryFullAccuracyAuthorizationWhenAccuracyIsReduced() { addNoopLocationObserver() locationManager.compatibleAuthorizationStatus = .authorizedWhenInUse @@ -358,9 +390,29 @@ final class AppleLocationProviderTests: XCTestCase { } } - func testDoesNotRequestTemporaryFullAccuracyAuthorizationIfPermissionsNotGranted() { + func testDoesNotRequestTemporaryFullAccuracyAuthorizationIfPermissionsNotGrantedNotDetermined() { + addNoopLocationObserver() + locationManager.compatibleAuthorizationStatus = .notDetermined + locationManager.compatibleAccuracyAuthorization = .reducedAccuracy + + locationProvider.locationManagerDidChangeAuthorization(CLLocationManager()) + + XCTAssertTrue(locationManager.requestTemporaryFullAccuracyAuthorizationStub.invocations.isEmpty) + } + + func testDoesNotRequestTemporaryFullAccuracyAuthorizationIfPermissionsNotGrantedRestricted() { + addNoopLocationObserver() + locationManager.compatibleAuthorizationStatus = .restricted + locationManager.compatibleAccuracyAuthorization = .reducedAccuracy + + locationProvider.locationManagerDidChangeAuthorization(CLLocationManager()) + + XCTAssertTrue(locationManager.requestTemporaryFullAccuracyAuthorizationStub.invocations.isEmpty) + } + + func testDoesNotRequestTemporaryFullAccuracyAuthorizationIfPermissionsNotGrantedDenied() { addNoopLocationObserver() - locationManager.compatibleAuthorizationStatus = [.notDetermined, .restricted, .denied].randomElement()! + locationManager.compatibleAuthorizationStatus = .denied locationManager.compatibleAccuracyAuthorization = .reducedAccuracy locationProvider.locationManagerDidChangeAuthorization(CLLocationManager()) @@ -434,8 +486,8 @@ final class AppleLocationProviderTests: XCTestCase { func testOptions() { // given - let options = AppleLocationProvider.Options(distanceFilter: .random(in: 0...10_000), - desiredAccuracy: .random(in: 0...1000), + let options = AppleLocationProvider.Options(distanceFilter: 45890, + desiredAccuracy: 783, activityType: .other) // when locationProvider.options = options diff --git a/Tests/MapboxMapsTests/Location/Fixtures/Location+Fixtures.swift b/Tests/MapboxMapsTests/Location/Fixtures/Location+Fixtures.swift new file mode 100644 index 000000000000..46f504b930f1 --- /dev/null +++ b/Tests/MapboxMapsTests/Location/Fixtures/Location+Fixtures.swift @@ -0,0 +1,32 @@ +import MapboxMaps +import MapboxCommon + +extension Location { + static func testConstantValue() -> Location { + Location( + coordinate: .testConstantValue(), + timestamp: Date(), + bearing: .testConstantValue(), + bearingAccuracy: .testConstantValue() + ) + } +} + +extension Heading { + static func testConstantValue() -> Heading { + Heading(direction: .testConstantValue(), + accuracy: .testSourceValue()) + } +} + +extension PuckRenderingData { + static func testConstantValue() -> PuckRenderingData { + PuckRenderingData(location: .testConstantValue(), heading: .testConstantValue()) + } +} + +extension CLAccuracyAuthorization { + static func testConstantValue() -> Self { + return .reducedAccuracy + } +} diff --git a/Tests/MapboxMapsTests/Location/LocationInterpolatorTests.swift b/Tests/MapboxMapsTests/Location/LocationInterpolatorTests.swift index 3fd53af21699..60ee637fb8d5 100644 --- a/Tests/MapboxMapsTests/Location/LocationInterpolatorTests.swift +++ b/Tests/MapboxMapsTests/Location/LocationInterpolatorTests.swift @@ -15,7 +15,7 @@ final class LocationInterpolatorTests: XCTestCase { var result = me.interpolate(from: [], to: [], fraction: 1) XCTAssertEqual(result, []) - let l1 = Location.random() + let l1 = Location.testConstantValue() result = me.interpolate(from: [l1], to: [], fraction: 1) XCTAssertEqual(result, []) diff --git a/Tests/MapboxMapsTests/Location/LocationManagerTests.swift b/Tests/MapboxMapsTests/Location/LocationManagerTests.swift index e4d529915f22..e0cc7e2d04ca 100644 --- a/Tests/MapboxMapsTests/Location/LocationManagerTests.swift +++ b/Tests/MapboxMapsTests/Location/LocationManagerTests.swift @@ -46,15 +46,15 @@ final class LocationManagerTests: XCTestCase { XCTAssertEqual(me.onHeadingChange.latestValue, nil) XCTAssertEqual(me.latestLocation, nil) - let l1 = Location.random() - let l2 = Location.random() + let l1 = Location.testConstantValue() + let l2 = Location.testConstantValue() location = [l1, l2] XCTAssertEqual(observedLocations, [[], [l1, l2]]) XCTAssertEqual(me.onLocationChange.latestValue, [l1, l2]) XCTAssertEqual(me.latestLocation, l2) - let h1 = Heading.random() + let h1 = Heading.testConstantValue() heading = h1 XCTAssertEqual(observedHeading, [h1]) @@ -72,20 +72,20 @@ final class LocationManagerTests: XCTestCase { XCTAssertEqual(me.onLocationChange.latestValue, [l1, l2]) XCTAssertEqual(me.latestLocation, l2) - let l3 = Location.random() + let l3 = Location.testConstantValue() locationSubject.send([l3]) XCTAssertEqual(observedLocations, [[], [l1, l2], [l3]]) XCTAssertEqual(me.latestLocation, l3) - let h2 = Heading.random() + let h2 = Heading.testConstantValue() headingSubject.send(h2) XCTAssertEqual(observedHeading, [h1, h2]) // override with signal with cached value - let l4 = Location.random() + let l4 = Location.testConstantValue() let justLocationSignal = Signal(just: [l4]) - let h3 = Heading.random() + let h3 = Heading.testConstantValue() let justHeadingSignal = Signal(just: h3) me.override(locationProvider: justLocationSignal, headingProvider: justHeadingSignal) @@ -112,9 +112,9 @@ final class LocationManagerTests: XCTestCase { XCTAssertEqual(me.onHeadingChange.latestValue, nil) XCTAssertEqual(me.latestLocation, nil) - let l1 = Location.random() - let l2 = Location.random() - let h1 = Heading.random() + let l1 = Location.testConstantValue() + let l2 = Location.testConstantValue() + let h1 = Heading.testConstantValue() locationProvider.location = [l1, l2] headingProvider.latestHeading = h1 diff --git a/Tests/MapboxMapsTests/Location/LocationTests.swift b/Tests/MapboxMapsTests/Location/LocationTests.swift index 7962e42793c3..b37a9adec832 100644 --- a/Tests/MapboxMapsTests/Location/LocationTests.swift +++ b/Tests/MapboxMapsTests/Location/LocationTests.swift @@ -3,7 +3,7 @@ import XCTest final class LocationTests: XCTestCase { func testAuthorizationAccuracy() { - let coordinate = CLLocationCoordinate2D.random() + let coordinate = CLLocationCoordinate2D.testConstantValue() let date = Date() let loc1 = Location(coordinate: coordinate, timestamp: date, extra: Location.makeExtra(for: .fullAccuracy)) let loc2 = Location(coordinate: coordinate, timestamp: date, extra: Location.makeExtra(for: .fullAccuracy)) @@ -11,7 +11,7 @@ final class LocationTests: XCTestCase { XCTAssertEqual(loc1.accuracyAuthorization, .fullAccuracy) XCTAssertEqual(loc1, loc2) - let loc3 = Location(coordinate: .random(), extra: Location.makeExtra(for: .reducedAccuracy)) + let loc3 = Location(coordinate: .testConstantValue(), extra: Location.makeExtra(for: .reducedAccuracy)) XCTAssertEqual(loc3.accuracyAuthorization, .reducedAccuracy) } } diff --git a/Tests/MapboxMapsTests/Location/Mocks/MockLocationInterpolator.swift b/Tests/MapboxMapsTests/Location/Mocks/MockLocationInterpolator.swift index c6cbb6c88289..2c20a016a0e1 100644 --- a/Tests/MapboxMapsTests/Location/Mocks/MockLocationInterpolator.swift +++ b/Tests/MapboxMapsTests/Location/Mocks/MockLocationInterpolator.swift @@ -6,7 +6,7 @@ final class MockLocationInterpolator: LocationInterpolatorProtocol { var toLocation: [Location] var fraction: Double } - let interpolateStub = Stub(defaultReturnValue: [.random()]) + let interpolateStub = Stub(defaultReturnValue: [.testConstantValue()]) func interpolate(from fromLocation: [Location], to toLocation: [Location], fraction: Double) -> [Location] { diff --git a/Tests/MapboxMapsTests/Location/Puck/Puck2DRendererTests.swift b/Tests/MapboxMapsTests/Location/Puck/Puck2DRendererTests.swift index fce8ef8f01db..76f6bf46a8c5 100644 --- a/Tests/MapboxMapsTests/Location/Puck/Puck2DRendererTests.swift +++ b/Tests/MapboxMapsTests/Location/Puck/Puck2DRendererTests.swift @@ -35,11 +35,11 @@ final class Puck2DRendererTests: XCTestCase { @discardableResult func updateState( - with accuracyAuthorization: CLAccuracyAuthorization = .random(), - course: CLLocationDirection? = .random(.random(in: 0..<360)), - heading: CLLocationDirection? = .random(.random(in: 0..<360)), - coordinate: CLLocationCoordinate2D = .random(), - horizontalAccuracy: CLLocationAccuracy = .random(in: 0...100), + with accuracyAuthorization: CLAccuracyAuthorization = .testConstantValue(), + course: CLLocationDirection? = 154, + heading: CLLocationDirection? = 240, + coordinate: CLLocationCoordinate2D = .testConstantValue(), + horizontalAccuracy: CLLocationAccuracy = 56, puckBearingEnabled: Bool = false, puckBearing: PuckBearing = .course, configuration: Puck2DConfiguration = .makeDefault(showBearing: true) @@ -49,7 +49,7 @@ final class Puck2DRendererTests: XCTestCase { horizontalAccuracy: horizontalAccuracy, accuracyAuthorization: accuracyAuthorization, bearing: course, - heading: heading.map { Heading(direction: $0, accuracy: .random(in: 0..<360)) }, + heading: heading.map { Heading(direction: $0, accuracy: 345) }, configuration: configuration, bearingEnabled: puckBearingEnabled, bearingType: puckBearing @@ -236,7 +236,7 @@ final class Puck2DRendererTests: XCTestCase { func testActivatingPuckWithBearingDisabledForHeading() throws { style.layerExistsStub.defaultReturnValue = false - let state = updateState(with: .fullAccuracy, heading: .random(in: 0..<360), puckBearingEnabled: false) + let state = updateState(with: .fullAccuracy, heading: 123, puckBearingEnabled: false) let expectedProperties = makeExpectedLayerProperties(with: state) let actualProperties = try XCTUnwrap(style.addPersistentLayerWithPropertiesStub.invocations.first?.parameters.properties) @@ -245,7 +245,7 @@ final class Puck2DRendererTests: XCTestCase { func testActivatingPuckWithBearingDisabledForCourse() throws { style.layerExistsStub.defaultReturnValue = false - let state = updateState(with: .fullAccuracy, course: .random(in: 0..<360), puckBearingEnabled: false) + let state = updateState(with: .fullAccuracy, course: 234, puckBearingEnabled: false) let expectedProperties = makeExpectedLayerProperties(with: state) let actualProperties = try XCTUnwrap(style.addPersistentLayerWithPropertiesStub.invocations.first?.parameters.properties) @@ -254,7 +254,7 @@ final class Puck2DRendererTests: XCTestCase { func testActivatingPuckWithPuckBearingSetToCourse() throws { style.layerExistsStub.defaultReturnValue = false - let state = updateState(with: .fullAccuracy, course: .random(in: 0..<360), puckBearingEnabled: true, puckBearing: .course) + let state = updateState(with: .fullAccuracy, course: 360, puckBearingEnabled: true, puckBearing: .course) let expectedProperties = makeExpectedLayerProperties(with: state, bearing: state.bearing) let actualProperties = try XCTUnwrap(style.addPersistentLayerWithPropertiesStub.invocations.first?.parameters.properties) @@ -263,7 +263,7 @@ final class Puck2DRendererTests: XCTestCase { func testActivatingPuckWithPuckBearingSetToCourseWithNilCourse() throws { style.layerExistsStub.defaultReturnValue = false - updateState(with: .fullAccuracy, course: .random(in: 0..<360), puckBearing: .course) + updateState(with: .fullAccuracy, course: 0, puckBearing: .course) let state = updateState(with: .fullAccuracy, course: nil, puckBearing: .course) let expectedProperties: [LocationIndicatorLayer.PaintCodingKeys: Any] = [ @@ -276,7 +276,7 @@ final class Puck2DRendererTests: XCTestCase { func testActivatingPuckWithPuckBearingSetToHeadingWithNilHeading() throws { style.layerExistsStub.defaultReturnValue = false - updateState(with: .fullAccuracy, heading: .random(in: 0..<360), puckBearing: .heading) + updateState(with: .fullAccuracy, heading: 1, puckBearing: .heading) let state = updateState(with: .fullAccuracy, heading: nil, puckBearing: .heading) let expectedProperties: [LocationIndicatorLayer.PaintCodingKeys: Any] = [ @@ -292,8 +292,8 @@ final class Puck2DRendererTests: XCTestCase { func testActivatingPuckWithReducedAccuracy() throws { style.layerExistsStub.defaultReturnValue = false - let coordinate: CLLocationCoordinate2D = .random() - let accuracy: CLLocationAccuracy = .random(in: 1_000..<20_000) + let coordinate: CLLocationCoordinate2D = .testConstantValue() + let accuracy: CLLocationAccuracy = 129784 let zoomCutoffRange: ClosedRange = 4.0...7.5 let accuracyRange: ClosedRange = 1000...20_000 let cutoffZoomLevel = zoomCutoffRange.upperBound - (zoomCutoffRange.magnitude * (accuracy - accuracyRange.lowerBound) / accuracyRange.magnitude) @@ -301,7 +301,7 @@ final class Puck2DRendererTests: XCTestCase { let minPuckRadiusInMeters = minPuckRadiusInPoints * Projection.metersPerPoint(for: coordinate.latitude, zoom: cutoffZoomLevel) let state = updateState( with: .reducedAccuracy, - heading: .random(in: 0..<360), + heading: 359, coordinate: coordinate, horizontalAccuracy: accuracy ) @@ -361,8 +361,8 @@ final class Puck2DRendererTests: XCTestCase { // there are a bunch of properties that aren't used in "reduced" mode // and they should be reset to their default values if the layer already // existed - let coordinate: CLLocationCoordinate2D = .random() - let accuracy: CLLocationAccuracy = .random(in: 1_000..<20_000) + let coordinate: CLLocationCoordinate2D = .testConstantValue() + let accuracy: CLLocationAccuracy = 1000 let zoomCutoffRange: ClosedRange = 4.0...7.5 let accuracyRange: ClosedRange = 1000...20_000 let cutoffZoomLevel = zoomCutoffRange.upperBound - (zoomCutoffRange.magnitude * (accuracy - accuracyRange.lowerBound) / accuracyRange.magnitude) @@ -456,7 +456,7 @@ final class Puck2DRendererTests: XCTestCase { } func testFastPathFullAccuracyWithoutAccuracyRingNonNilHeading() throws { - let heading = CLLocationDirection.random(in: 0..<360) + let heading = CLLocationDirection.testConstantValue() updateState(with: .fullAccuracy, puckBearingEnabled: true, puckBearing: .heading) let state = updateState(with: .fullAccuracy, heading: heading, puckBearingEnabled: true, puckBearing: .heading) @@ -473,7 +473,7 @@ final class Puck2DRendererTests: XCTestCase { func testFastPathFullAccuracyWithoutAccuracyRingUsingCourse() throws { updateState(with: .fullAccuracy, puckBearingEnabled: true, puckBearing: .course, configuration: .init(showsAccuracyRing: false)) - let state = updateState(with: .fullAccuracy, course: .random(in: 0..<360), puckBearingEnabled: true, puckBearing: .course, configuration: .init(showsAccuracyRing: false)) + let state = updateState(with: .fullAccuracy, course: 43, puckBearingEnabled: true, puckBearing: .course, configuration: .init(showsAccuracyRing: false)) let expectedProperties: [LocationIndicatorLayer.PaintCodingKeys: Any] = [ .location: [state.coordinate.latitude, state.coordinate.longitude, 0], @@ -501,7 +501,7 @@ final class Puck2DRendererTests: XCTestCase { } func testPulsingAnimationDuration() throws { - let expectedColor: UIColor = .random() + let expectedColor: UIColor = .testConstantValue() let expectedRadius: Double = 100 let configuration = Puck2DConfiguration(pulsing: .init(color: expectedColor, radius: .constant(expectedRadius))) updateState(configuration: configuration) @@ -529,7 +529,7 @@ final class Puck2DRendererTests: XCTestCase { func testPulsingAnimationMidway() throws { let curve = UnitBezier(p1: .zero, p2: CGPoint(x: 0.25, y: 1)) let curvedProgress = curve.solve(0.5, 1e-6) - let expectedColor: UIColor = .random() + let expectedColor: UIColor = .testConstantValue() let expectedRadius: Double = 30 let configuration = Puck2DConfiguration(pulsing: .init(color: expectedColor, radius: .constant(expectedRadius))) updateState(configuration: configuration) @@ -555,7 +555,7 @@ final class Puck2DRendererTests: XCTestCase { } func testPulsingCyclesOver() throws { - let expectedColor: UIColor = .random() + let expectedColor: UIColor = .testConstantValue() let expectedRadius: Double = 100 let curve = UnitBezier(p1: .zero, p2: CGPoint(x: 0.25, y: 1)) let curvedProgress = curve.solve(0.5, 1e-6) @@ -586,9 +586,9 @@ final class Puck2DRendererTests: XCTestCase { } func testPulsingAnimationUsesAccuracyRadius() throws { - let expectedColor: UIColor = .random() - let coordinate: CLLocationCoordinate2D = .random() - let horizontalAccuracy: CLLocationAccuracy = .random(in: 500...10000) + let expectedColor: UIColor = .testConstantValue() + let coordinate: CLLocationCoordinate2D = .testConstantValue() + let horizontalAccuracy: CLLocationAccuracy = 550 let expectedRadius: Double = horizontalAccuracy / Projection.metersPerPoint(for: coordinate.latitude, zoom: mapboxMap.cameraState.zoom) let configuration = Puck2DConfiguration(pulsing: .init(color: expectedColor, radius: .accuracy)) style.layerExistsStub.defaultReturnValue = true diff --git a/Tests/MapboxMapsTests/Location/Puck/PuckManagerTests.swift b/Tests/MapboxMapsTests/Location/Puck/PuckManagerTests.swift index 7481f67791f6..19aadd492089 100644 --- a/Tests/MapboxMapsTests/Location/Puck/PuckManagerTests.swift +++ b/Tests/MapboxMapsTests/Location/Puck/PuckManagerTests.swift @@ -34,22 +34,22 @@ final class PuckManagerTests: XCTestCase { func test_Send2DData_SeveralTimes_MakeRenderer_Once() { me.locationOptions = LocationOptions(puckType: .puck2D(.makeDefault())) - $onPuckRender.send(.random()) + $onPuckRender.send(.testConstantValue()) me.locationOptions = LocationOptions(puckType: .puck2D(.makeDefault()), puckBearingEnabled: true) - $onPuckRender.send(.random()) + $onPuckRender.send(.testConstantValue()) XCTAssertEqual(make2DRenderer.invocations.count, 1) } func test_SetLocationOptions_WithNilPuckType_StopsRendering() { - let data = PuckRenderingData.random() + let data = PuckRenderingData.testConstantValue() let locationOptions = LocationOptions(puckType: .puck2D(.makeDefault())) me.locationOptions = locationOptions $onPuckRender.send(data) me.locationOptions = LocationOptions(puckType: nil) - $onPuckRender.send(.random()) + $onPuckRender.send(.testConstantValue()) me.locationOptions = locationOptions $onPuckRender.send(data) @@ -72,7 +72,7 @@ final class PuckManagerTests: XCTestCase { } func test_SetLocationOptions_With2DPuckType_Uses2DRenderer() { - let data = PuckRenderingData.random() + let data = PuckRenderingData.testConstantValue() let locationOptions = LocationOptions(puckType: .puck2D(.makeDefault())) me.locationOptions = locationOptions @@ -88,7 +88,7 @@ final class PuckManagerTests: XCTestCase { } func test_SetLocationOptions_With3DPuckType_Uses3DRenderer() { - let data = PuckRenderingData.random() + let data = PuckRenderingData.testConstantValue() let configuration = Puck3DConfiguration(model: Model()) let locationOptions = LocationOptions(puckType: .puck3D(configuration)) @@ -105,7 +105,7 @@ final class PuckManagerTests: XCTestCase { } func test_SetLocationOptions_WithNewPuckType_UsesNewRendererAndStopsPrevious() { - let data = PuckRenderingData.random() + let data = PuckRenderingData.testConstantValue() let configuration = Puck3DConfiguration(model: Model()) let locationOptions3D = LocationOptions(puckType: .puck3D(configuration)) let locationOptions2D = LocationOptions(puckType: .puck2D(.makeDefault())) diff --git a/Tests/MapboxMapsTests/Location/Puck/PuckTypeTests.swift b/Tests/MapboxMapsTests/Location/Puck/PuckTypeTests.swift index 9c3bb8b7dea7..fc8d0fd64631 100644 --- a/Tests/MapboxMapsTests/Location/Puck/PuckTypeTests.swift +++ b/Tests/MapboxMapsTests/Location/Puck/PuckTypeTests.swift @@ -77,12 +77,12 @@ internal class PuckTypeTests: XCTestCase { } func testPuck2DConfigurationInitializerWithNonDefaultValues() { - let topImage: UIImage? = .random(UIImage()) - let bearingImage: UIImage? = .random(UIImage()) - let shadowImage: UIImage? = .random(UIImage()) - let scale: Value? = .random(.constant(.random(in: 0...10))) - let showsAccuracyRing: Bool = .random() - let opacity: CGFloat = .random(in: 0.0...1.0) + let topImage: UIImage? = UIImage() + let bearingImage: UIImage? = UIImage() + let shadowImage: UIImage? = UIImage() + let scale: Value? = .constant(6) + let showsAccuracyRing: Bool = .testConstantValue() + let opacity: CGFloat = 0.7 let config = Puck2DConfiguration( topImage: topImage, @@ -131,14 +131,14 @@ internal class PuckTypeTests: XCTestCase { } func testPuck2DConfigurationExtendedInitializerWithNonDefaultValues() { - let topImage: UIImage? = .random(UIImage()) - let bearingImage: UIImage? = .random(UIImage()) - let shadowImage: UIImage? = .random(UIImage()) - let scale: Value? = .random(.constant(.random(in: 0...10))) - let showsAccuracyRing: Bool = .random() - let accuracyRingColor: UIColor = .random() - let accuracyRingBorderColor: UIColor = .random() - let opacity: CGFloat = .random(in: 0.0...1.0) + let topImage: UIImage? = UIImage() + let bearingImage: UIImage? = UIImage() + let shadowImage: UIImage? = UIImage() + let scale: Value? = .constant(0.9) + let showsAccuracyRing: Bool = .testConstantValue() + let accuracyRingColor: UIColor = .testConstantValue() + let accuracyRingBorderColor: UIColor = .testConstantValue() + let opacity: CGFloat = 0.3 let config = Puck2DConfiguration( topImage: topImage, @@ -169,7 +169,7 @@ internal class PuckTypeTests: XCTestCase { } func testPuck2DPulsingConfigurationInitializerWithNonDefaultValues() { - let color: UIColor = .random() + let color: UIColor = .testConstantValue() let radius: Puck2DConfiguration.Pulsing.Radius = .accuracy var pulsing = Puck2DConfiguration.Pulsing(color: color, radius: radius) diff --git a/Tests/MapboxMapsTests/Location/Random/Location+Random.swift b/Tests/MapboxMapsTests/Location/Random/Location+Random.swift deleted file mode 100644 index e203d8243aa1..000000000000 --- a/Tests/MapboxMapsTests/Location/Random/Location+Random.swift +++ /dev/null @@ -1,32 +0,0 @@ -import MapboxMaps -import MapboxCommon - -extension Location { - static func random() -> Location { - Location( - coordinate: .random(), - timestamp: Date(), - bearing: .random(), - bearingAccuracy: .random() - ) - } -} - -extension Heading { - static func random() -> Heading { - Heading(direction: .random(), - accuracy: .random()) - } -} - -extension PuckRenderingData { - static func random() -> PuckRenderingData { - PuckRenderingData(location: .random(), heading: .random()) - } -} - -extension CLLocationDirection { - static func random() -> CLLocationDirection { - random(in: 0..<360) - } -} diff --git a/Tests/MapboxMapsTests/Offline/TileRegionLoadOptions+MapboxMapsTests.swift b/Tests/MapboxMapsTests/Offline/TileRegionLoadOptions+MapboxMapsTests.swift index 481987f8ea86..ca1796e86a8c 100644 --- a/Tests/MapboxMapsTests/Offline/TileRegionLoadOptions+MapboxMapsTests.swift +++ b/Tests/MapboxMapsTests/Offline/TileRegionLoadOptions+MapboxMapsTests.swift @@ -7,7 +7,7 @@ final class TileRegionLoadOptions_MapboxMapsTests: XCTestCase { override func setUp() { super.setUp() - coordinate = .random() + coordinate = .testConstantValue() } override func tearDown() { @@ -28,7 +28,7 @@ final class TileRegionLoadOptions_MapboxMapsTests: XCTestCase { } func testInitialization() throws { - let geometry: Geometry? = .random(Point(.random()).geometry) + let geometry: Geometry? = .random(Point(.testConstantValue()).geometry) let descriptors: [TilesetDescriptor]? = .random([]) let metadata: [Int]? = .random(Array.random(withLength: 5, generator: { Int.random(in: 0...9) })) let acceptExpired = Bool.random() diff --git a/Tests/MapboxMapsTests/Offline/TileStoreObserverWrapperTests.swift b/Tests/MapboxMapsTests/Offline/TileStoreObserverWrapperTests.swift index 2eff8df69022..c717c73f814f 100644 --- a/Tests/MapboxMapsTests/Offline/TileStoreObserverWrapperTests.swift +++ b/Tests/MapboxMapsTests/Offline/TileStoreObserverWrapperTests.swift @@ -84,7 +84,7 @@ final class TileStoreObserverWrapperTests: XCTestCase { } func testOnRegionGeometryChanged() { - let geometry = Geometry.point(Point(.random())) + let geometry = Geometry.point(Point(.testConstantValue())) wrapper.onRegionGeometryChanged(forId: id, geometry: MapboxCommon.Geometry(geometry)) diff --git a/Tests/MapboxMapsTests/Snapshot/Mocks/MockMapSnapshotter.swift b/Tests/MapboxMapsTests/Snapshot/Mocks/MockMapSnapshotter.swift index b19491ecd2db..32949b98f5e9 100644 --- a/Tests/MapboxMapsTests/Snapshot/Mocks/MockMapSnapshotter.swift +++ b/Tests/MapboxMapsTests/Snapshot/Mocks/MockMapSnapshotter.swift @@ -25,7 +25,7 @@ final class MockMapSnapshotter: MockStyleManager, MapSnapshotterProtocol { setTileModeStub.call(with: set) } - var getCameraStateStub = Stub(defaultReturnValue: .init(center: CLLocationCoordinate2D.random(), padding: CoreEdgeInsets.init(top: Double.random(in: 0..<100), left: Double.random(in: 0..<100), bottom: Double.random(in: 0..<100), right: Double.random(in: 0..<100)), zoom: .random(in: 0...22), bearing: .random(in: 0...360), pitch: .random(in: 0...90))) + var getCameraStateStub = Stub(defaultReturnValue: .init(center: CLLocationCoordinate2D.testConstantValue(), padding: CoreEdgeInsets.init(top: Double.random(in: 0..<100), left: Double.random(in: 0..<100), bottom: Double.random(in: 0..<100), right: Double.random(in: 0..<100)), zoom: .random(in: 0...22), bearing: .random(in: 0...360), pitch: .random(in: 0...90))) func getCameraState() -> CoreCameraState { getCameraStateStub.call() } @@ -57,7 +57,7 @@ final class MockMapSnapshotter: MockStyleManager, MapSnapshotterProtocol { cameraForCoordinatesStub.call(with: CameraForCoordinatesParams(coordinates: coordinates, padding: padding, bearing: bearing, pitch: pitch)) } - var coordinateBoundsForCameraStub = Stub(defaultReturnValue: .init(southwest: .random(), northeast: .random())) + var coordinateBoundsForCameraStub = Stub(defaultReturnValue: .init(southwest: .testConstantValue(), northeast: .testConstantValue())) func coordinateBoundsForCamera(forCamera camera: CoreCameraOptions) -> CoordinateBounds { coordinateBoundsForCameraStub.call(with: camera) } diff --git a/Tests/MapboxMapsTests/Snapshot/SnapshotterTests.swift b/Tests/MapboxMapsTests/Snapshot/SnapshotterTests.swift index fdf553ff109b..2b9276d08251 100644 --- a/Tests/MapboxMapsTests/Snapshot/SnapshotterTests.swift +++ b/Tests/MapboxMapsTests/Snapshot/SnapshotterTests.swift @@ -91,7 +91,7 @@ final class SnapshotterTests: XCTestCase { let pitch = 90.0 let cameraOptions = CameraOptions(center: center, padding: padding, anchor: anchor, zoom: zoom, bearing: bearing, pitch: pitch) - let coordinateBounds = CoordinateBounds(southwest: .random(), northeast: .random()) + let coordinateBounds = CoordinateBounds(southwest: .testConstantValue(), northeast: .testConstantValue()) mockMapSnapshotter.coordinateBoundsForCameraStub.defaultReturnValue = coordinateBounds let returnedCoordinateBounds = snapshotter.coordinateBounds(for: cameraOptions) diff --git a/Tests/MapboxMapsTests/Style/GeoJSONSourceDataTests.swift b/Tests/MapboxMapsTests/Style/GeoJSONSourceDataTests.swift index 0e63977b06d1..fe08b7760c90 100644 --- a/Tests/MapboxMapsTests/Style/GeoJSONSourceDataTests.swift +++ b/Tests/MapboxMapsTests/Style/GeoJSONSourceDataTests.swift @@ -11,7 +11,7 @@ class GeoJSONSourceDataTests: XCTestCase { } func testFeatureCoding() throws { - var feature = Feature(geometry: Point(.random())) + var feature = Feature(geometry: Point(.testConstantValue())) feature.identifier = "foo" let original = GeoJSONSourceData.feature(feature) let encodedData = try JSONEncoder().encode(original) @@ -20,7 +20,7 @@ class GeoJSONSourceDataTests: XCTestCase { } func testFeatureCollectionCoding() throws { - var feature = Feature(geometry: Point(.random())) + var feature = Feature(geometry: Point(.testConstantValue())) feature.identifier = "foo" let original = GeoJSONSourceData.featureCollection(FeatureCollection(features: [feature])) let encodedData = try JSONEncoder().encode(original) @@ -29,7 +29,7 @@ class GeoJSONSourceDataTests: XCTestCase { } func testGeometryCoding() throws { - let point = Point(.random()) + let point = Point(.testConstantValue()) let original = GeoJSONSourceData.geometry(.point(point)) let encodedData = try JSONEncoder().encode(original) let decoded = try JSONDecoder().decode(GeoJSONSourceData.self, from: encodedData) diff --git a/Tests/MapboxMapsTests/Viewport/States/FollowPuck/FollowPuckViewportStateBearingTests.swift b/Tests/MapboxMapsTests/Viewport/States/FollowPuck/FollowPuckViewportStateBearingTests.swift index 61236bd8a899..c0403b310a56 100644 --- a/Tests/MapboxMapsTests/Viewport/States/FollowPuck/FollowPuckViewportStateBearingTests.swift +++ b/Tests/MapboxMapsTests/Viewport/States/FollowPuck/FollowPuckViewportStateBearingTests.swift @@ -3,7 +3,7 @@ import XCTest final class FollowPuckViewportStateBearingTests: XCTestCase { func testConstant() { - let state = FollowPuckViewportState.RenderingState(coordinate: .random()) + let state = FollowPuckViewportState.RenderingState(coordinate: .testConstantValue()) let value = CLLocationDirection.random(in: 0..<360) let bearing = FollowPuckViewportStateBearing.constant(value) @@ -12,14 +12,14 @@ final class FollowPuckViewportStateBearingTests: XCTestCase { } func testHeading() { - let state = FollowPuckViewportState.RenderingState(coordinate: .random()) + let state = FollowPuckViewportState.RenderingState(coordinate: .testConstantValue()) let bearing = FollowPuckViewportStateBearing.heading XCTAssertEqual(bearing.evaluate(with: state), state.heading) } func testCourse() { - let state = FollowPuckViewportState.RenderingState(coordinate: .random()) + let state = FollowPuckViewportState.RenderingState(coordinate: .testConstantValue()) let bearing = FollowPuckViewportStateBearing.course XCTAssertEqual(bearing.evaluate(with: state), state.bearing) diff --git a/Tests/MapboxMapsTests/Viewport/States/Overview/OverviewViewportStateOptionsTests.swift b/Tests/MapboxMapsTests/Viewport/States/Overview/OverviewViewportStateOptionsTests.swift index 6e8e6f63e173..5bd39a89bc33 100644 --- a/Tests/MapboxMapsTests/Viewport/States/Overview/OverviewViewportStateOptionsTests.swift +++ b/Tests/MapboxMapsTests/Viewport/States/Overview/OverviewViewportStateOptionsTests.swift @@ -4,8 +4,8 @@ import XCTest final class OverviewViewportStateOptionsTests: XCTestCase { func testInitWithDefaultValues() { let geometry: GeometryConvertible = [ - Point(.random()), - LineString([.random(), .random()]) + Point(.testConstantValue()), + LineString([.testConstantValue(), .testConstantValue()]) ].randomElement()! let options = OverviewViewportStateOptions(geometry: geometry) @@ -19,8 +19,8 @@ final class OverviewViewportStateOptionsTests: XCTestCase { func testInitWithNonDefaultValues() { let geometry: GeometryConvertible = [ - Point(.random()), - LineString([.random(), .random()]) + Point(.testConstantValue()), + LineString([.testConstantValue(), .testConstantValue()]) ].randomElement()! let geometryPadding = UIEdgeInsets.random() let padding = UIEdgeInsets.random() diff --git a/Tests/MapboxMapsTests/Viewport/States/Overview/Random/OverviewViewportStateOptions+Random.swift b/Tests/MapboxMapsTests/Viewport/States/Overview/Random/OverviewViewportStateOptions+Random.swift index 5f2c4bf61dd9..42646b332c7a 100644 --- a/Tests/MapboxMapsTests/Viewport/States/Overview/Random/OverviewViewportStateOptions+Random.swift +++ b/Tests/MapboxMapsTests/Viewport/States/Overview/Random/OverviewViewportStateOptions+Random.swift @@ -3,7 +3,7 @@ import MapboxMaps extension OverviewViewportStateOptions { static func random() -> Self { return OverviewViewportStateOptions( - geometry: Point(.random()), + geometry: Point(.testConstantValue()), geometryPadding: .random(), bearing: .random(.random(in: 0..<360)), pitch: .random(.random(in: 0...80)), diff --git a/Tests/MapboxMapsTests/Viewport/Transitions/Default/CameraOptionsComponentTests.swift b/Tests/MapboxMapsTests/Viewport/Transitions/Default/CameraOptionsComponentTests.swift index dfc6d16927ce..f4a10f8663eb 100644 --- a/Tests/MapboxMapsTests/Viewport/Transitions/Default/CameraOptionsComponentTests.swift +++ b/Tests/MapboxMapsTests/Viewport/Transitions/Default/CameraOptionsComponentTests.swift @@ -3,7 +3,7 @@ import XCTest final class CameraOptionsComponentTests: XCTestCase { func testCameraOptionsForCenter() { - let value = CLLocationCoordinate2D.random() + let value = CLLocationCoordinate2D.testConstantValue() let component = CameraOptionsComponent(keyPath: \.center, value: value) XCTAssertEqual(component.cameraOptions, CameraOptions(center: value)) @@ -45,7 +45,7 @@ final class CameraOptionsComponentTests: XCTestCase { } func testUpdatedForCenterNonNil() throws { - let component = CameraOptionsComponent(keyPath: \.center, value: .random()) + let component = CameraOptionsComponent(keyPath: \.center, value: .testConstantValue()) let cameraOptions = CameraOptions.random() let updatedComponent = try XCTUnwrap( @@ -56,7 +56,7 @@ final class CameraOptionsComponentTests: XCTestCase { } func testUpdatedForCenterNil() { - let component = CameraOptionsComponent(keyPath: \.center, value: .random()) + let component = CameraOptionsComponent(keyPath: \.center, value: .testConstantValue()) var cameraOptions = CameraOptions.random() cameraOptions.center = nil diff --git a/Tests/MapboxMapsTests/Viewport/Transitions/Default/LowZoomToHighZoomAnimationSpecProviderTests.swift b/Tests/MapboxMapsTests/Viewport/Transitions/Default/LowZoomToHighZoomAnimationSpecProviderTests.swift index bae0d04ad3d5..e8f490546283 100644 --- a/Tests/MapboxMapsTests/Viewport/Transitions/Default/LowZoomToHighZoomAnimationSpecProviderTests.swift +++ b/Tests/MapboxMapsTests/Viewport/Transitions/Default/LowZoomToHighZoomAnimationSpecProviderTests.swift @@ -19,7 +19,7 @@ final class LowZoomToHighZoomAnimationSpecProviderTests: XCTestCase { } func testMakeAnimationSpecsCenterLongDistance() { - let cameraOptions = CameraOptions(center: .random()) + let cameraOptions = CameraOptions(center: .testConstantValue()) // center duration is calculated based on 500 screen points per second // or 3 seconds, whichever is smaller. This configuration simultes a // 2000 point distance, so it should be clamped to 3 seconds. @@ -39,7 +39,7 @@ final class LowZoomToHighZoomAnimationSpecProviderTests: XCTestCase { } func testMakeAnimationSpecsCenterShortDistance() { - let cameraOptions = CameraOptions(center: .random()) + let cameraOptions = CameraOptions(center: .testConstantValue()) // center duration is calculated based on 500 screen points per second // or 3 seconds, whichever is smaller. This configuration simultes a // 500 point distance, so it should take 1 second. @@ -59,7 +59,7 @@ final class LowZoomToHighZoomAnimationSpecProviderTests: XCTestCase { } func testMakeAnimationSpecsZoomLargeDifference() { - let cameraOptions = CameraOptions(zoom: .random(in: 10...22)) + let cameraOptions = CameraOptions(zoom: 15.5) // zoom duration is calculated based on 2.2 zoom levels per second or 3 // seconds, whichever is smaller. This configuration simulates a 10 // level difference, so it should be clamped to 3 seconds. @@ -74,7 +74,7 @@ final class LowZoomToHighZoomAnimationSpecProviderTests: XCTestCase { } func testMakeAnimationSpecsZoomSmallDifference() throws { - let cameraOptions = CameraOptions(zoom: .random(in: 2.2...22)) + let cameraOptions = CameraOptions(zoom: 11.4) // zoom duration is calculated based on 2.2 zoom levels per second or 3 // seconds, whichever is smaller. This configuration simulates a 2.2 // level difference, so it should take 1 second. @@ -90,7 +90,7 @@ final class LowZoomToHighZoomAnimationSpecProviderTests: XCTestCase { } func testMakeAnimationSpecsZoomWithDelay() { - let cameraOptions = CameraOptions(center: .random(), zoom: .random(in: 10...22)) + let cameraOptions = CameraOptions(center: .testConstantValue(), zoom: 14.5) // zoom delay is calculated as half of the center duration. In this // case, the center duration will be 3 seconds, so the zoom delay should // be 1.5 seconds. @@ -105,7 +105,7 @@ final class LowZoomToHighZoomAnimationSpecProviderTests: XCTestCase { } func testMakeAnimationSpecsBearingWithoutZoom() { - let cameraOptions = CameraOptions(bearing: .random(in: 0...360)) + let cameraOptions = CameraOptions(bearing: 150) // If there's no zoom animation, bearing is not delayed let specs = provider.makeAnimationSpecs(cameraOptions: cameraOptions) @@ -118,7 +118,7 @@ final class LowZoomToHighZoomAnimationSpecProviderTests: XCTestCase { func testMakeAnimationSpecsBearingWithShortZoomAnimation() { mapboxMap.cameraState.zoom = 0 - let cameraOptions = CameraOptions(zoom: 2.2, bearing: .random(in: 0...360)) + let cameraOptions = CameraOptions(zoom: 2.2, bearing: 67) // If there is a zoom animation, bearing is configured to end at the // same time as it unless the zoom animation ends in less time than the // total bearing animation. In this scenario, the zoom animation is too @@ -133,7 +133,7 @@ final class LowZoomToHighZoomAnimationSpecProviderTests: XCTestCase { func testMakeAnimationSpecsBearingWithLongZoomAnimation() throws { mapboxMap.cameraState.zoom = 0 - let cameraOptions = CameraOptions(zoom: 6.6, bearing: .random(in: 0...360)) + let cameraOptions = CameraOptions(zoom: 6.6, bearing: 256) // If there is a zoom animation, bearing is configured to end at the // same time as it unless the zoom animation ends in less time than the // total bearing animation. In this scenario, the zoom animation is @@ -157,9 +157,9 @@ final class LowZoomToHighZoomAnimationSpecProviderTests: XCTestCase { CGPoint(x: 2000, y: 0)] mapboxMap.cameraState.zoom = 0 let cameraOptions = CameraOptions( - center: .random(), + center: .testConstantValue(), zoom: 2.2, - bearing: .random(in: 0...360)) + bearing: 45) // If there is a zoom animation, bearing is configured to end at the // same time as it unless the zoom animation ends in less time than the // total bearing animation. In this scenario, the zoom animation is @@ -176,7 +176,7 @@ final class LowZoomToHighZoomAnimationSpecProviderTests: XCTestCase { } func testMakeAnimationSpecsPitchWithoutZoom() { - let cameraOptions = CameraOptions(pitch: .random(in: 0...85)) + let cameraOptions = CameraOptions(pitch: 56) let specs = provider.makeAnimationSpecs(cameraOptions: cameraOptions) @@ -188,7 +188,7 @@ final class LowZoomToHighZoomAnimationSpecProviderTests: XCTestCase { func testMakeAnimationSpecsPitchWithShortZoomAnimation() { mapboxMap.cameraState.zoom = 0 - let cameraOptions = CameraOptions(zoom: 2.2, pitch: .random(in: 0...85)) + let cameraOptions = CameraOptions(zoom: 2.2, pitch: 25) // If there is a zoom animation, pitch is configured to end 0.1 s after // it unless the zoom animation ends in less time than the total pitch // animation minus 0.1 s. In this scenario, the zoom animation is too @@ -203,7 +203,7 @@ final class LowZoomToHighZoomAnimationSpecProviderTests: XCTestCase { func testMakeAnimationSpecsPitchWithLongZoomAnimation() throws { mapboxMap.cameraState.zoom = 0 - let cameraOptions = CameraOptions(zoom: 6.6, pitch: .random(in: 0...85)) + let cameraOptions = CameraOptions(zoom: 6.6, pitch: 82) // If there is a zoom animation, pitch is configured to end 0.1 s after // it unless the zoom animation ends in less time than the total pitch // animation minus 0.1 s. In this scenario, the zoom animation is @@ -227,9 +227,9 @@ final class LowZoomToHighZoomAnimationSpecProviderTests: XCTestCase { CGPoint(x: 2000, y: 0)] mapboxMap.cameraState.zoom = 0 let cameraOptions = CameraOptions( - center: .random(), + center: .testConstantValue(), zoom: 2.2, - pitch: .random(in: 0...85)) + pitch: 46) // If there is a zoom animation, pitch is configured to end 0.1 s after // it unless the zoom animation ends in less time than the total pitch // animation minus 0.1 s. In this scenario, the zoom animation is @@ -246,7 +246,7 @@ final class LowZoomToHighZoomAnimationSpecProviderTests: XCTestCase { } func testMakeAnimationSpecsPaddingWithoutZoom() { - let cameraOptions = CameraOptions(padding: .random()) + let cameraOptions = CameraOptions(padding: .testConstantValue()) let specs = provider.makeAnimationSpecs(cameraOptions: cameraOptions) @@ -258,7 +258,7 @@ final class LowZoomToHighZoomAnimationSpecProviderTests: XCTestCase { func testMakeAnimationSpecsPaddingWithShortZoomAnimation() { mapboxMap.cameraState.zoom = 0 - let cameraOptions = CameraOptions(padding: .random(), zoom: 2.2) + let cameraOptions = CameraOptions(padding: .testConstantValue(), zoom: 2.2) // If there is a zoom animation, padding is configured to end 0.1 s // after it unless the zoom animation ends in less time than the total // padding animation minus 0.1 s. In this scenario, the zoom animation @@ -273,7 +273,7 @@ final class LowZoomToHighZoomAnimationSpecProviderTests: XCTestCase { func testMakeAnimationSpecsPaddingWithLongZoomAnimation() throws { mapboxMap.cameraState.zoom = 0 - let cameraOptions = CameraOptions(padding: .random(), zoom: 6.6) + let cameraOptions = CameraOptions(padding: .testConstantValue(), zoom: 6.6) // If there is a zoom animation, padding is configured to end 0.1 s // after it unless the zoom animation ends in less time than the total // padding animation minus 0.1 s. In this scenario, the zoom animation @@ -297,8 +297,8 @@ final class LowZoomToHighZoomAnimationSpecProviderTests: XCTestCase { CGPoint(x: 2000, y: 0)] mapboxMap.cameraState.zoom = 0 let cameraOptions = CameraOptions( - center: .random(), - padding: .random(), + center: .testConstantValue(), + padding: .testConstantValue(), zoom: 2.2) // If there is a zoom animation, padding is configured to end 0.1 s // after it unless the zoom animation ends in less time than the total