Files
Lyrebird/Tests/LyrebirdTests/DemandConcatenateTests.swift
T
2026-06-01 18:27:40 -07:00

57 lines
1.9 KiB
Swift

// DemandConcatenateTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
@Suite("DemandConcatenate")
struct DemandConcatenateTests {
@Test func playsEachInTurn() {
let d: DemandConcatenate = DemandConcatenate(demands: [
DemandSequence(values: [1.0, 2.0], repeats: 1),
DemandSequence(values: [10.0, 20.0, 30.0], repeats: 1),
DemandSequence(values: [100.0], repeats: 1)
])
var collected: [Double] = []
while let v: Double = d.nextValue() { collected.append(v) }
#expect(collected == [1.0, 2.0, 10.0, 20.0, 30.0, 100.0])
#expect(d.isExhausted)
}
@Test func emptyListExhaustsImmediately() {
let d: DemandConcatenate = DemandConcatenate(demands: [])
#expect(d.nextValue() == nil)
#expect(d.isExhausted)
}
@Test func skipsExhaustedSubSources() {
let d: DemandConcatenate = DemandConcatenate(demands: [
DemandSequence(values: [], repeats: 1),
DemandSequence(values: [5.0], repeats: 1),
DemandSequence(values: [], repeats: 1),
DemandSequence(values: [10.0], repeats: 1)
])
var collected: [Double] = []
while let v: Double = d.nextValue() { collected.append(v) }
#expect(collected == [5.0, 10.0])
}
@Test func resetReplaysAll() {
let d: DemandConcatenate = DemandConcatenate(demands: [
DemandSequence(values: [1.0, 2.0], repeats: 1),
DemandSequence(values: [3.0, 4.0], repeats: 1)
])
var first: [Double] = []
while let v: Double = d.nextValue() { first.append(v) }
#expect(first == [1.0, 2.0, 3.0, 4.0])
d.reset()
var second: [Double] = []
while let v: Double = d.nextValue() { second.append(v) }
#expect(second == first)
}
}