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

39 lines
1.4 KiB
Swift

// ChaoticInterpolateTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Foundation
import Testing
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
// MARK: - ChaoticInterpolateTests
@Suite("chaoticInterpolate")
struct ChaoticInterpolateTests {
let hM1: Double = -0.5
let h0: Double = 0.2
let h1: Double = 0.9
let h2: Double = -0.3
@Test func noneHoldsSegmentStart() {
#expect(chaoticInterpolate(.none, phase: 0.0, hM1: hM1, h0: h0, h1: h1, h2: h2) == h0)
#expect(chaoticInterpolate(.none, phase: 0.99, hM1: hM1, h0: h0, h1: h1, h2: h2) == h0)
}
@Test func linearEndpointsAndMidpoint() {
#expect(abs(chaoticInterpolate(.linear, phase: 0.0, hM1: hM1, h0: h0, h1: h1, h2: h2) - h0) < 1e-15)
#expect(abs(chaoticInterpolate(.linear, phase: 1.0, hM1: hM1, h0: h0, h1: h1, h2: h2) - h1) < 1e-15)
let mid: Double = chaoticInterpolate(.linear, phase: 0.5, hM1: hM1, h0: h0, h1: h1, h2: h2)
#expect(abs(mid - 0.5 * (h0 + h1)) < 1e-15)
}
@Test func cubicPassesThroughSegmentEndpoints() {
// The 4-point cubic kernel passes through h0 at t=0 and h1 at t=1.
#expect(abs(chaoticInterpolate(.cubic, phase: 0.0, hM1: hM1, h0: h0, h1: h1, h2: h2) - h0) < 1e-12)
#expect(abs(chaoticInterpolate(.cubic, phase: 1.0, hM1: hM1, h0: h0, h1: h1, h2: h2) - h1) < 1e-12)
}
}