1.0.0 release
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
// PatternCauchyTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
@Suite("Pattern.cauchy")
|
||||
struct PatternCauchyTests {
|
||||
|
||||
@Test func producesFiniteValues() {
|
||||
let pat: Pattern<Double> = Pattern.cauchy(
|
||||
location: 0.0,
|
||||
scale: 1.0,
|
||||
length: 1_000,
|
||||
seed: 42
|
||||
)
|
||||
var count: Int = 0
|
||||
while let v: Double = pat.next() {
|
||||
#expect(v.isFinite)
|
||||
count += 1
|
||||
}
|
||||
#expect(count == 1_000)
|
||||
#expect(pat.isExhausted)
|
||||
}
|
||||
|
||||
@Test func medianIsApproximatelyLocation() {
|
||||
let n: Int = 10_001
|
||||
let pat: Pattern<Double> = Pattern.cauchy(
|
||||
location: 5.0,
|
||||
scale: 0.5,
|
||||
length: n,
|
||||
seed: 1234
|
||||
)
|
||||
var samples: [Double] = []
|
||||
samples.reserveCapacity(n)
|
||||
while let v: Double = pat.next() {
|
||||
samples.append(v)
|
||||
}
|
||||
samples.sort()
|
||||
let median: Double = samples[n / 2]
|
||||
// Cauchy has no defined mean but median = location. Tolerance ~ 0.05 at n=10001.
|
||||
#expect(abs(median - 5.0) < 0.1)
|
||||
}
|
||||
|
||||
@Test func sameSeedProducesIdenticalSequence() {
|
||||
let a: Pattern<Double> = Pattern.cauchy(location: 0.0, scale: 1.0, length: 50, seed: 99)
|
||||
let b: Pattern<Double> = Pattern.cauchy(location: 0.0, scale: 1.0, length: 50, seed: 99)
|
||||
for _ in 0..<50 {
|
||||
#expect(a.next() == b.next())
|
||||
}
|
||||
}
|
||||
|
||||
@Test func resetClearsExhaustion() {
|
||||
let pat: Pattern<Double> = Pattern.cauchy(location: 0.0, scale: 1.0, length: 3, seed: 21)
|
||||
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