Skip to content

Commit

Permalink
Unit tests de-flaking
Browse files Browse the repository at this point in the history
  • Loading branch information
orchetect committed Oct 29, 2024
1 parent 2eee3c1 commit 62b3d9e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import Testing
import Numerics

@Suite struct OSCTimeTag_StaticConstructors_Tests {
#if os(macOS) || os(iOS)
let tolerance: TimeInterval = 0.001
#elseif os(tvOS) || os(watchOS)
// allow more time variance for CI pipeline to de-flake
let tolerance: TimeInterval = 0.01
#endif

// MARK: - Static Constructors

@Test func timeTagImmediate() {
Expand All @@ -35,7 +42,7 @@ import Numerics

let valTI = try #require((val as? OSCTimeTag)?.timeInterval(since: primeEpoch))
let nowTI = now.timeInterval(since: primeEpoch)
#expect(valTI.isApproximatelyEqual(to: nowTI, absoluteTolerance: 0.001))
#expect(valTI.isApproximatelyEqual(to: nowTI, absoluteTolerance: tolerance))
}

@Test func oscValue_timeTagTimeIntervalSinceNow() throws {
Expand All @@ -45,7 +52,7 @@ import Numerics
let valTI = try #require((val as? OSCTimeTag)?.timeInterval(since: primeEpoch))
let nowTI = now.timeInterval(since: primeEpoch)

#expect(valTI.isApproximatelyEqual(to: nowTI, absoluteTolerance: 0.001))
#expect(valTI.isApproximatelyEqual(to: nowTI, absoluteTolerance: tolerance))
}

@Test func oscValue_timeTagTimeIntervalSince1900() {
Expand Down
18 changes: 12 additions & 6 deletions Tests/OSCKitCoreTests/OSCTimeTag/OSCTimeTag Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import OSCKitCore
import Testing

@Suite struct OSCTimeTag_Tests {
#if os(macOS) || os(iOS)
let tolerance: TimeInterval = 0.001
#elseif os(tvOS) || os(watchOS)
// allow more time variance for CI pipeline to de-flake
let tolerance: TimeInterval = 0.01
#endif

@Test func init_RawValue() {
// ensure all raw values including 0 and 1 are allowed
#expect(OSCTimeTag(0).rawValue == 0)
Expand Down Expand Up @@ -40,8 +47,7 @@ import Testing
#expect(!tag.isImmediate)
#expect(!tag.isFuture)
#expect(tag.date < Date())
#expect(tag.timeIntervalSinceNow().isApproximatelyEqual(to: -10.0, absoluteTolerance: 0.001))

#expect(tag.timeIntervalSinceNow().isApproximatelyEqual(to: -10.0, absoluteTolerance: tolerance))
}

// MARK: - .init(timeIntervalSince1900:)
Expand Down Expand Up @@ -148,13 +154,13 @@ import Testing
@Test func immediate_date() {
let tag = OSCTimeTag.immediate()
let date = Date()
#expect(tag.date.timeIntervalSince(date).isApproximatelyEqual(to: 0.0, absoluteTolerance: 0.001))
#expect(tag.date.timeIntervalSince(date).isApproximatelyEqual(to: 0.0, absoluteTolerance: tolerance))
}

@Test func immediate_timeIntervalSinceNow() {
let tag = OSCTimeTag.immediate()
let captureSecondsFromNow = tag.timeIntervalSinceNow()
#expect(captureSecondsFromNow.isApproximatelyEqual(to: 0.0, absoluteTolerance: 0.001))
#expect(captureSecondsFromNow.isApproximatelyEqual(to: 0.0, absoluteTolerance: tolerance))
}

// MARK: - .now()
Expand Down Expand Up @@ -182,14 +188,14 @@ import Testing
@Test func now_date() {
let tag = OSCTimeTag.now()
let captureDate = tag.date
#expect(Date().timeIntervalSince(captureDate).isApproximatelyEqual(to: 0.0, absoluteTolerance: 0.001))
#expect(Date().timeIntervalSince(captureDate).isApproximatelyEqual(to: 0.0, absoluteTolerance: tolerance))

}

@Test func now_timeIntervalSinceNow() {
let tag = OSCTimeTag.now()
let captureSecondsFromNow = tag.timeIntervalSinceNow()
#expect(captureSecondsFromNow.isApproximatelyEqual(to: 0.0, absoluteTolerance: 0.001))
#expect(captureSecondsFromNow.isApproximatelyEqual(to: 0.0, absoluteTolerance: tolerance))
}
}

Expand Down

0 comments on commit 62b3d9e

Please sign in to comment.