mirror of
https://github.com/apple/swift-async-algorithms
synced 2026-11-24 04:17:52 +00:00
* Remove the disable of availability and mark methods as available to clock/instant/duration * Rework availability to be more permissive for tests * Use hand coded values instead of defines (only available via Darwin versions of Dispatch) * Adjust additional test availability * Correct debounce test availability guard * Update build instructions to indicate Xcode requirements * Ensure the clock property of the validation diagram is only available for targets that can support it
142 lines
5.0 KiB
Swift
142 lines
5.0 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Async Algorithms open source project
|
|
//
|
|
// Copyright (c) 2022 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import XCTest
|
|
import AsyncAlgorithms
|
|
|
|
final class TestThrottle: XCTestCase {
|
|
func test_rate_0() throws {
|
|
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
|
|
validate {
|
|
"abcdefghijk|"
|
|
$0.inputs[0].throttle(for: .steps(0), clock: $0.clock)
|
|
"abcdefghijk|"
|
|
}
|
|
}
|
|
|
|
func test_rate_0_leading_edge() throws {
|
|
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
|
|
validate {
|
|
"abcdefghijk|"
|
|
$0.inputs[0].throttle(for: .steps(0), clock: $0.clock, latest: false)
|
|
"abcdefghijk|"
|
|
}
|
|
}
|
|
|
|
func test_rate_1() throws {
|
|
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
|
|
validate {
|
|
"abcdefghijk|"
|
|
$0.inputs[0].throttle(for: .steps(1), clock: $0.clock)
|
|
"abcdefghijk|"
|
|
}
|
|
}
|
|
|
|
func test_rate_1_leading_edge() throws {
|
|
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
|
|
validate {
|
|
"abcdefghijk|"
|
|
$0.inputs[0].throttle(for: .steps(1), clock: $0.clock, latest: false)
|
|
"abcdefghijk|"
|
|
}
|
|
}
|
|
|
|
func test_rate_2() throws {
|
|
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
|
|
validate {
|
|
"abcdefghijk|"
|
|
$0.inputs[0].throttle(for: .steps(2), clock: $0.clock)
|
|
"a-c-e-g-i-k|"
|
|
}
|
|
}
|
|
|
|
func test_rate_2_leading_edge() throws {
|
|
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
|
|
validate {
|
|
"abcdefghijk|"
|
|
$0.inputs[0].throttle(for: .steps(2), clock: $0.clock, latest: false)
|
|
"a-b-d-f-h-j|"
|
|
}
|
|
}
|
|
|
|
func test_rate_3() throws {
|
|
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
|
|
validate {
|
|
"abcdefghijk|"
|
|
$0.inputs[0].throttle(for: .steps(3), clock: $0.clock)
|
|
"a--d--g--j-|"
|
|
}
|
|
}
|
|
|
|
func test_rate_3_leading_edge() throws {
|
|
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
|
|
validate {
|
|
"abcdefghijk|"
|
|
$0.inputs[0].throttle(for: .steps(3), clock: $0.clock, latest: false)
|
|
"a--b--e--h-|"
|
|
}
|
|
}
|
|
|
|
func test_throwing() throws {
|
|
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
|
|
validate {
|
|
"abcdef^hijk|"
|
|
$0.inputs[0].throttle(for: .steps(2), clock: $0.clock)
|
|
"a-c-e-^"
|
|
}
|
|
}
|
|
|
|
func test_throwing_leading_edge() throws {
|
|
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
|
|
validate {
|
|
"abcdef^hijk|"
|
|
$0.inputs[0].throttle(for: .steps(2), clock: $0.clock, latest: false)
|
|
"a-b-d-^"
|
|
}
|
|
}
|
|
|
|
func test_emission_2_rate_1() throws {
|
|
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
|
|
validate {
|
|
"-a-b-c-d-e-f-g-h-i-j-k-|"
|
|
$0.inputs[0].throttle(for: .steps(1), clock: $0.clock)
|
|
"-a-b-c-d-e-f-g-h-i-j-k-|"
|
|
}
|
|
}
|
|
|
|
func test_emission_2_rate_2() throws {
|
|
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
|
|
validate {
|
|
"-a-b-c-d-e-f-g-h-i-j-k-|"
|
|
$0.inputs[0].throttle(for: .steps(2), clock: $0.clock)
|
|
"-a-b-c-d-e-f-g-h-i-j-k-|"
|
|
}
|
|
}
|
|
|
|
func test_emission_3_rate_2() throws {
|
|
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
|
|
validate {
|
|
"--a--b--c--d--e--f--g|"
|
|
$0.inputs[0].throttle(for: .steps(2), clock: $0.clock)
|
|
"--a--b--c--d--e--f--g|"
|
|
}
|
|
}
|
|
|
|
func test_emission_2_rate_3() throws {
|
|
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
|
|
validate {
|
|
"-a-b-c-d-e-f-g-h-i-j-k-|"
|
|
$0.inputs[0].throttle(for: .steps(3), clock: $0.clock)
|
|
"-a---c---e---g---i---k-|"
|
|
}
|
|
}
|
|
}
|