1.0.0 release
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
// PatternUniformRandomTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
@Suite("Pattern.uniformRandom")
|
||||
struct PatternUniformRandomTests {
|
||||
|
||||
@Test func samplesStayWithinRange() {
|
||||
let pat: Pattern<Double> = Pattern.uniformRandom(low: -5.0, high: 5.0, length: 1_000, seed: 42)
|
||||
var count: Int = 0
|
||||
while let v: Double = pat.next() {
|
||||
#expect(v >= -5.0 && v <= 5.0)
|
||||
count += 1
|
||||
}
|
||||
#expect(count == 1_000)
|
||||
}
|
||||
|
||||
@Test func lengthExhaustsCorrectly() {
|
||||
let pat: Pattern<Double> = Pattern.uniformRandom(low: 0.0, high: 1.0, length: 5, seed: 1)
|
||||
for _ in 0..<5 { #expect(pat.next() != nil) }
|
||||
#expect(pat.next() == nil)
|
||||
#expect(pat.isExhausted)
|
||||
}
|
||||
|
||||
@Test func sameSeedProducesIdenticalSequence() {
|
||||
let a: Pattern<Double> = Pattern.uniformRandom(low: 0.0, high: 100.0, length: 50, seed: 12345)
|
||||
let b: Pattern<Double> = Pattern.uniformRandom(low: 0.0, high: 100.0, length: 50, seed: 12345)
|
||||
for _ in 0..<50 {
|
||||
#expect(a.next() == b.next())
|
||||
}
|
||||
}
|
||||
|
||||
@Test func infiniteLengthNeverExhausts() {
|
||||
let pat: Pattern<Double> = Pattern.uniformRandom(low: 0.0, high: 1.0, length: -1, seed: 7)
|
||||
for _ in 0..<1_000 { _ = pat.next() }
|
||||
#expect(!pat.isExhausted)
|
||||
}
|
||||
|
||||
@Test func resetClearsExhaustion() {
|
||||
let pat: Pattern<Double> = Pattern.uniformRandom(low: 0.0, high: 1.0, length: 3, seed: 42)
|
||||
for _ in 0..<3 { _ = pat.next() }
|
||||
#expect(pat.isExhausted)
|
||||
pat.reset()
|
||||
#expect(!pat.isExhausted)
|
||||
#expect(pat.next() != nil)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user