Files
Lyrebird/Tests/LyrebirdTests/Buffers/RTScratchBufferTests.swift
T
josh 844dc4d9cd v2.1.0 release: Swift 6.4 modernization
Typed throws across the closed-error-set APIs (OSC, MIDI, engine add/schedule,
bus/config/parameter, and the WAV/RF64/Spectral file codecs — source-compatible
narrowing, new .ioFailure cases), plus internal hardening: NSLock-guarded
scheduling/MIDI state moved to Mutex<State>, and the Spectral/FFT scratch owners
moved to a ~Copyable RTScratchBuffer RAII buffer. No API or behavioral change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-24 19:54:59 -07:00

61 lines
1.8 KiB
Swift

// RTScratchBufferTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
@Suite("RTScratchBuffer")
struct RTScratchBufferTests {
@Test("init allocates the requested count, zero-filled")
func initZeroFills() {
let buf: RTScratchBuffer<Float> = RTScratchBuffer<Float>(count: 8)
#expect(buf.count == 8)
for i: Int in 0..<8 {
#expect(buf[i] == 0)
}
}
@Test("init(count:repeating:) fills with the given value")
func initRepeatingFills() {
let buf: RTScratchBuffer<Float> = RTScratchBuffer<Float>(count: 5, repeating: 1)
#expect(buf.count == 5)
for i: Int in 0..<5 {
#expect(buf[i] == 1)
}
}
@Test("subscript round-trips writes")
func subscriptRoundTrip() {
let buf: RTScratchBuffer<Double> = RTScratchBuffer<Double>(count: 4)
buf[0] = 1.5
buf[3] = -2.25
#expect(buf[0] == 1.5)
#expect(buf[1] == 0)
#expect(buf[3] == -2.25)
}
@Test("baseAddress aliases the same storage as subscript")
func baseAddressAliasesStorage() {
let buf: RTScratchBuffer<Float> = RTScratchBuffer<Float>(count: 3)
buf[1] = 42
#expect(buf.baseAddress[1] == 42)
buf.baseAddress[2] = 7
#expect(buf[2] == 7)
}
@Test("buffers of the same element type own distinct allocations")
func distinctAllocations() {
let a: RTScratchBuffer<Float> = RTScratchBuffer<Float>(count: 2)
let b: RTScratchBuffer<Float> = RTScratchBuffer<Float>(count: 2)
a[0] = 100
b[0] = 200
#expect(a[0] == 100)
#expect(b[0] == 200)
#expect(a.baseAddress != b.baseAddress)
}
}