Files
Philippe Hauslerandkperryua 7969001299 Add a detailed proposal-like guide for AsyncSequence validation (#56)
* Add a detailed proposal like guide for MarbleDiagram

* Slight spacing change

Co-authored-by: kperryua <kperry@apple.com>

* Fix some pluralization agreement

Co-authored-by: kperryua <kperry@apple.com>

* Clarify the testing of merge and add a future direction for unordered groups

* rename the diagram system to a more general 'validate' based name

* Spelling fixes

* Grammar fixes for credits

Co-authored-by: kperryua <kperry@apple.com>
2022-02-22 11:03:27 -08:00

128 lines
2.9 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() {
validate {
"abcdefghijk|"
$0.inputs[0].throttle(for: .steps(0), clock: $0.clock)
"abcdefghijk|"
}
}
func test_rate_0_leading_edge() {
validate {
"abcdefghijk|"
$0.inputs[0].throttle(for: .steps(0), clock: $0.clock, latest: false)
"abcdefghijk|"
}
}
func test_rate_1() {
validate {
"abcdefghijk|"
$0.inputs[0].throttle(for: .steps(1), clock: $0.clock)
"abcdefghijk|"
}
}
func test_rate_1_leading_edge() {
validate {
"abcdefghijk|"
$0.inputs[0].throttle(for: .steps(1), clock: $0.clock, latest: false)
"abcdefghijk|"
}
}
func test_rate_2() {
validate {
"abcdefghijk|"
$0.inputs[0].throttle(for: .steps(2), clock: $0.clock)
"-b-d-f-h-j-|"
}
}
func test_rate_2_leading_edge() {
validate {
"abcdefghijk|"
$0.inputs[0].throttle(for: .steps(2), clock: $0.clock, latest: false)
"-a-c-e-g-i-|"
}
}
func test_rate_3() {
validate {
"abcdefghijk|"
$0.inputs[0].throttle(for: .steps(3), clock: $0.clock)
"--c--f--i--|"
}
}
func test_rate_3_leading_edge() {
validate {
"abcdefghijk|"
$0.inputs[0].throttle(for: .steps(3), clock: $0.clock, latest: false)
"--a--d--g--|"
}
}
func test_throwing() {
validate {
"abcdef^hijk|"
$0.inputs[0].throttle(for: .steps(2), clock: $0.clock)
"-b-d-f^"
}
}
func test_throwing_leading_edge() {
validate {
"abcdef^hijk|"
$0.inputs[0].throttle(for: .steps(2), clock: $0.clock, latest: false)
"-a-c-e^"
}
}
func test_emission_2_rate_1() {
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() {
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() {
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() {
validate {
"-a-b-c-d-e-f-g-h-i-j-k-|"
$0.inputs[0].throttle(for: .steps(3), clock: $0.clock)
"---b---d---f---h---j---|"
}
}
}