// DemandUniformRandomTests.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth @Suite("DemandUniformRandom") struct DemandUniformRandomTests { @Test func samplesStayWithinRange() { let d: DemandUniformRandom = DemandUniformRandom( low: -5.0, high: 5.0, length: 1_000, seed: 42 ) var count: Int = 0 while let v: Double = d.nextValue() { #expect(v >= -5.0 && v <= 5.0) count += 1 } #expect(count == 1_000) } @Test func sameSeedProducesIdenticalSequence() { let a: DemandUniformRandom = DemandUniformRandom(low: 0.0, high: 1.0, length: 50, seed: 99) let b: DemandUniformRandom = DemandUniformRandom(low: 0.0, high: 1.0, length: 50, seed: 99) for _ in 0..<50 { #expect(a.nextValue() == b.nextValue()) } } @Test func resetClearsExhaustion() { let d: DemandUniformRandom = DemandUniformRandom(low: 0.0, high: 1.0, length: 3, seed: 7) for _ in 0..<3 { _ = d.nextValue() } #expect(d.isExhausted) d.reset() #expect(!d.isExhausted) #expect(d.nextValue() != nil) } }