65 lines
1.8 KiB
Swift
65 lines
1.8 KiB
Swift
// PatternRepeatingTests.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Testing
|
|
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
|
|
|
@Suite("Pattern.repeating")
|
|
struct PatternRepeatingTests {
|
|
|
|
@Test func replaysUpstreamCountTimes() {
|
|
let pat: Pattern<Int> = Pattern.repeating(
|
|
Pattern.sequence([1, 2, 3], repeats: 1),
|
|
count: 3
|
|
)
|
|
var collected: [Int] = []
|
|
while let v: Int = pat.next() { collected.append(v) }
|
|
#expect(collected == [1, 2, 3, 1, 2, 3, 1, 2, 3])
|
|
#expect(pat.isExhausted)
|
|
}
|
|
|
|
@Test func countZeroEmitsNothing() {
|
|
let pat: Pattern<Int> = Pattern.repeating(
|
|
Pattern.sequence([1, 2, 3], repeats: 1),
|
|
count: 0
|
|
)
|
|
#expect(pat.next() == nil)
|
|
#expect(pat.isExhausted)
|
|
}
|
|
|
|
@Test func countNegativeOneIsInfinite() {
|
|
let pat: Pattern<Int> = Pattern.repeating(
|
|
Pattern.sequence([1, 2], repeats: 1),
|
|
count: -1
|
|
)
|
|
for _ in 0..<1_000 { _ = pat.next() }
|
|
#expect(!pat.isExhausted)
|
|
}
|
|
|
|
@Test func emptyUpstreamLatchesExhausted() {
|
|
let pat: Pattern<Int> = Pattern.repeating(
|
|
Pattern.sequence([], repeats: 1),
|
|
count: 5
|
|
)
|
|
#expect(pat.next() == nil)
|
|
#expect(pat.isExhausted)
|
|
}
|
|
|
|
@Test func resetReplaysFromStart() {
|
|
let pat: Pattern<Int> = Pattern.repeating(
|
|
Pattern.sequence([1, 2], repeats: 1),
|
|
count: 2
|
|
)
|
|
var first: [Int] = []
|
|
while let v: Int = pat.next() { first.append(v) }
|
|
pat.reset()
|
|
var second: [Int] = []
|
|
while let v: Int = pat.next() { second.append(v) }
|
|
#expect(first == [1, 2, 1, 2])
|
|
#expect(second == first)
|
|
}
|
|
}
|