Files
Lyrebird/Tests/LyrebirdTests/Generators/BusIO/ReplaceOutControlGeneratorTests.swift
T
2026-06-21 11:45:58 -07:00

48 lines
1.7 KiB
Swift

// ReplaceOutControlGeneratorTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
@MainActor
@Suite("ReplaceOut.Control")
struct ReplaceOutControlGeneratorTests {
let engine: SynthesisEngine = makeTestEngine(blockSize: 16)
init() throws {
try engine.start()
}
@Test func rateIsControl() {
let gen: ReplaceOut.Control = ReplaceOut.Control(bus: 0, source: 0.3 as Double)
#expect(gen.rate == .control)
}
@Test func overwritesControlBus() {
let gen: ReplaceOut.Control = ReplaceOut.Control(bus: 0, source: 0.3 as Double)
let graph: SynthGraph = makeSynthGraph(engine: engine)
_ = gen.calculatedSamples(graph: graph, count: 8)
#expect(abs(engine.controlBuses[0] - 0.3) < 1e-6)
}
@Test func wipesPriorAdditiveControlWrite() {
let outGen: Out.Control = Out.Control(bus: 0, source: 0.4 as Double)
let repGen: ReplaceOut.Control = ReplaceOut.Control(bus: 0, source: 0.9 as Double)
let graph: SynthGraph = makeSynthGraph(engine: engine)
_ = outGen.calculatedSamples(graph: graph, count: 8)
_ = repGen.calculatedSamples(graph: graph, count: 8)
#expect(abs(engine.controlBuses[0] - 0.9) < 1e-6)
}
@Test func writesToCorrectBus() {
let gen: ReplaceOut.Control = ReplaceOut.Control(bus: 5, source: 1.2 as Double)
let graph: SynthGraph = makeSynthGraph(engine: engine)
_ = gen.calculatedSamples(graph: graph, count: 8)
#expect(abs(engine.controlBuses[5] - 1.2) < 1e-6)
#expect(engine.controlBuses[0] == 0.0)
}
}