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

61 lines
2.3 KiB
Swift

// HenonSteppedControlTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Foundation
import Testing
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
// MARK: - HenonSteppedControlTests
@MainActor
@Suite("HenonStepped.Control")
struct HenonSteppedControlTests {
let engine: SynthesisEngine
let sr: Double = 44100
init() throws {
engine = makeTestEngine(blockSize: 64, sampleRate: 44100)
try engine.start()
}
@Test func finiteBoundedOutput() {
let henon: HenonStepped.Control = HenonStepped.Control(freq: 200.0)
let samples: [Double] = collectBlocks(henon, engine: engine, blocks: 40)
#expect(samples.allSatisfy { $0.isFinite })
#expect(samples.allSatisfy { abs($0) < 2.0 })
}
@Test func freqZeroRampsToPrimedValue() {
// dphase = 0 → no iteration past priming; .none holds h0 = -0.4 (2nd Hénon
// iterate for a=1.4, b=0.3, x0=x1=0). The block ramps 0 → -0.4, so the last
// sample equals the target exactly.
let henon: HenonStepped.Control = HenonStepped.Control(freq: 0.0)
let g: SynthGraph = makeSynthGraph(engine: engine)
let s: [[Double]] = henon.calculatedSamples(graph: g, count: engine.blockSize)
#expect(abs(s[0][engine.blockSize - 1] - (-0.4)) < 1e-12)
}
@Test func twoInstancesProduceIdenticalOutput() throws {
let h1: HenonStepped.Control = HenonStepped.Control(freq: 500.0)
let s1: [Double] = collectBlocks(h1, engine: engine, blocks: 20)
let engine2: SynthesisEngine = makeTestEngine(blockSize: 64, sampleRate: sr)
try engine2.start()
let h2: HenonStepped.Control = HenonStepped.Control(freq: 500.0)
let s2: [Double] = collectBlocks(h2, engine: engine2, blocks: 20)
#expect(s1 == s2)
}
@Test func participatesInFanOutCache() {
let henon: HenonStepped.Control = HenonStepped.Control(freq: 500.0)
let g: SynthGraph = makeSynthGraph(engine: engine)
let r1: [[Double]] = henon.calculatedSamples(graph: g, count: engine.blockSize)
let r2: [[Double]] = henon.calculatedSamples(graph: g, count: engine.blockSize)
#expect(r1[0].prefix(engine.blockSize).elementsEqual(r2[0].prefix(engine.blockSize)))
}
}