// LineTests.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth @Suite("Line") struct LineTests { // sampleRate == blockSize → 1 audio block per second of duration. Makes durations // expressible in whole blocks for clean assertions on done dispatch. private func makeEngine() -> SynthesisEngine { makeTestEngine(blockSize: 64, sampleRate: 64) } // MARK: - Rate / channel count @Test func rateIsControl() { let gen: Line.Control = Line.Control(start: 0.0, end: 1.0, dur: 1.0) #expect(gen.rate == .control) #expect(gen.outputChannelCount == 1) } // MARK: - Linear interpolation reaches end at duration @Test func reachesEndAtDuration() throws { let engine: SynthesisEngine = makeEngine() try engine.start() let line: Line.Control = Line.Control(start: 0.0, end: 1.0, dur: 4.0) let samples: [Double] = collectBlocks(line, engine: engine, blocks: 4) let lastSample: Double = samples.last ?? 0.0 #expect(abs(lastSample - 1.0) < 1e-9) engine.stop() } // MARK: - Monotonic increasing for ascending ramp @Test func monotonicIncreasing() throws { let engine: SynthesisEngine = makeEngine() try engine.start() let line: Line.Control = Line.Control(start: 0.0, end: 1.0, dur: 4.0) let samples: [Double] = collectBlocks(line, engine: engine, blocks: 4) for i: Int in 1..= samples[i - 1] - 1e-12, "non-monotonic at i=\(i): \(samples[i-1]) → \(samples[i])") } engine.stop() } // MARK: - Negative ramp @Test func negativeRampDescends() throws { let engine: SynthesisEngine = makeEngine() try engine.start() let line: Line.Control = Line.Control(start: 1.0, end: -1.0, dur: 4.0) let samples: [Double] = collectBlocks(line, engine: engine, blocks: 4) let lastSample: Double = samples.last ?? 0.0 #expect(abs(lastSample - (-1.0)) < 1e-9) for i: Int in 1..