69 lines
2.3 KiB
Swift
69 lines
2.3 KiB
Swift
// ScratchModelMemoryTests.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#if os(macOS)
|
|
import Testing
|
|
import LyrebirdSynth
|
|
@testable import LyrebirdLiveCompile
|
|
@testable import LyrebirdLiveCompileUI
|
|
|
|
@Suite("LyrebirdScratchModel snippet memory")
|
|
@MainActor
|
|
struct ScratchModelMemoryTests {
|
|
|
|
private func makeModel() -> LyrebirdScratchModel {
|
|
let engine: SynthesisEngine = SynthesisEngine(
|
|
blockSize: 64,
|
|
controlBlockSize: 16,
|
|
sampleRate: 48_000,
|
|
numOutputChannels: 2,
|
|
numInputChannels: 0,
|
|
numAudioBuses: 16,
|
|
numControlBuses: 16,
|
|
eventQueueCapacity: lyrebirdDefaultEventQueueCapacity,
|
|
driver: OfflineDriver()
|
|
)
|
|
return LyrebirdScratchModel(session: LiveSession(engine: engine))
|
|
}
|
|
|
|
@Test func freshModelMirrorsZeroMappedSnippets() {
|
|
let model: LyrebirdScratchModel = makeModel()
|
|
#expect(model.loadedSnippetCount == 0)
|
|
#expect(model.snippetMemoryHint == nil)
|
|
}
|
|
|
|
@Test func hintIsNilBelowThreshold() {
|
|
let below: Int = LyrebirdScratchModel.snippetRestartThreshold - 1
|
|
#expect(LyrebirdScratchModel.snippetMemoryHint(count: 0) == nil)
|
|
#expect(LyrebirdScratchModel.snippetMemoryHint(count: below) == nil)
|
|
}
|
|
|
|
@Test func hintAppearsAtAndAboveThreshold() {
|
|
let at: Int = LyrebirdScratchModel.snippetRestartThreshold
|
|
let atHint: String? = LyrebirdScratchModel.snippetMemoryHint(count: at)
|
|
#expect(atHint != nil)
|
|
#expect(atHint?.contains("\(at)") == true)
|
|
#expect(LyrebirdScratchModel.snippetMemoryHint(count: at + 100) != nil)
|
|
}
|
|
|
|
@Test func clearTrackedRefreshesSnippetMirror() {
|
|
// resetAll (behind clearTracked) does not reclaim dylibs, so the mirror
|
|
// stays in sync with the session — 0 on a fresh session.
|
|
let model: LyrebirdScratchModel = makeModel()
|
|
model.clearTracked()
|
|
#expect(model.loadedSnippetCount == 0)
|
|
}
|
|
|
|
@Test func hintMentionsRestartAndDSLAlternative() {
|
|
let hint: String = LyrebirdScratchModel.snippetMemoryHint(
|
|
count: LyrebirdScratchModel.snippetRestartThreshold) ?? ""
|
|
#expect(hint.lowercased().contains("restart"))
|
|
#expect(hint.contains("Graph DSL"))
|
|
}
|
|
}
|
|
|
|
#endif
|