1.0.0 release
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
// DemandStutterTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
@Suite("DemandStutter")
|
||||
struct DemandStutterTests {
|
||||
|
||||
@Test func repeatsEachValueByCount() {
|
||||
let d: DemandStutter = DemandStutter(
|
||||
demand: DemandSequence(values: [10.0, 20.0, 30.0], repeats: 1),
|
||||
count: 2
|
||||
)
|
||||
var collected: [Double] = []
|
||||
while let v: Double = d.nextValue() { collected.append(v) }
|
||||
#expect(collected == [10.0, 10.0, 20.0, 20.0, 30.0, 30.0])
|
||||
#expect(d.isExhausted)
|
||||
}
|
||||
|
||||
@Test func countOneIsPassThrough() {
|
||||
let d: DemandStutter = DemandStutter(
|
||||
demand: DemandSequence(values: [1.0, 2.0, 3.0], repeats: 1),
|
||||
count: 1
|
||||
)
|
||||
var collected: [Double] = []
|
||||
while let v: Double = d.nextValue() { collected.append(v) }
|
||||
#expect(collected == [1.0, 2.0, 3.0])
|
||||
}
|
||||
|
||||
@Test func upstreamExhaustionLatchesEngine() {
|
||||
let d: DemandStutter = DemandStutter(
|
||||
demand: DemandSequence(values: [5.0], repeats: 1),
|
||||
count: 3
|
||||
)
|
||||
#expect(d.nextValue() == 5.0)
|
||||
#expect(d.nextValue() == 5.0)
|
||||
#expect(d.nextValue() == 5.0)
|
||||
#expect(d.nextValue() == nil)
|
||||
#expect(d.isExhausted)
|
||||
}
|
||||
|
||||
@Test func resetRestartsUpstreamAndCount() {
|
||||
let d: DemandStutter = DemandStutter(
|
||||
demand: DemandSequence(values: [7.0, 8.0], repeats: 1),
|
||||
count: 2
|
||||
)
|
||||
while d.nextValue() != nil {} // drain to trigger latch
|
||||
#expect(d.isExhausted)
|
||||
d.reset()
|
||||
#expect(!d.isExhausted)
|
||||
#expect(d.nextValue() == 7.0)
|
||||
#expect(d.nextValue() == 7.0)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user