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

62 lines
1.7 KiB
Swift

// DemandBrownianTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
@Suite("DemandBrownian")
struct DemandBrownianTests {
@Test func walkStaysWithinBounds() {
let d: DemandBrownian = DemandBrownian(
low: -10.0,
high: 10.0,
step: 5.0,
length: 10_000,
seed: 99
)
while let v: Double = d.nextValue() {
#expect(v >= -10.0 && v <= 10.0)
}
}
@Test func startDefaultsToMidpoint() {
let d: DemandBrownian = DemandBrownian(
low: 0.0,
high: 100.0,
step: 0.0,
length: 1,
seed: 1
)
#expect(d.nextValue() == 50.0)
}
@Test func sameSeedSameStartProducesIdenticalWalk() {
let a: DemandBrownian = DemandBrownian(
low: -5.0, high: 5.0, step: 0.5, start: 0.0, length: 100, seed: 2024
)
let b: DemandBrownian = DemandBrownian(
low: -5.0, high: 5.0, step: 0.5, start: 0.0, length: 100, seed: 2024
)
for _ in 0..<100 {
#expect(a.nextValue() == b.nextValue())
}
}
@Test func resetRestoresStartPosition() {
let d: DemandBrownian = DemandBrownian(
low: -10.0, high: 10.0, step: 1.0, start: 7.0, length: -1, seed: 5
)
for _ in 0..<50 { _ = d.nextValue() }
d.reset()
if let v: Double = d.nextValue() {
#expect(v >= 6.0 && v <= 8.0)
} else {
Issue.record("Expected non-nil value after reset")
}
}
}