57 lines
1.5 KiB
Swift
57 lines
1.5 KiB
Swift
// PatternDropTests.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Testing
|
|
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
|
|
|
@MainActor
|
|
@Suite("Pattern.drop")
|
|
struct PatternDropTests {
|
|
|
|
@Test func skipsFirstCountValues() {
|
|
let pat: Pattern<Int> = Pattern.drop(
|
|
Pattern.sequence([1, 2, 3, 4, 5], repeats: 1),
|
|
count: 2
|
|
)
|
|
#expect(pat.next() == 3)
|
|
#expect(pat.next() == 4)
|
|
#expect(pat.next() == 5)
|
|
#expect(pat.next() == nil)
|
|
#expect(pat.isExhausted)
|
|
}
|
|
|
|
@Test func countZeroPassesThroughUnchanged() {
|
|
let pat: Pattern<Int> = Pattern.drop(
|
|
Pattern.sequence([7, 8, 9], repeats: 1),
|
|
count: 0
|
|
)
|
|
#expect(pat.next() == 7)
|
|
#expect(pat.next() == 8)
|
|
#expect(pat.next() == 9)
|
|
#expect(pat.next() == nil)
|
|
}
|
|
|
|
@Test func countExceedsUpstreamExhaustsImmediately() {
|
|
let pat: Pattern<Int> = Pattern.drop(
|
|
Pattern.sequence([1, 2, 3], repeats: 1),
|
|
count: 10
|
|
)
|
|
#expect(pat.next() == nil)
|
|
}
|
|
|
|
@Test func resetRestoresDropsRemaining() {
|
|
let pat: Pattern<Int> = Pattern.drop(
|
|
Pattern.sequence([1, 2, 3, 4], repeats: -1),
|
|
count: 2
|
|
)
|
|
_ = pat.next(); _ = pat.next() // emits 3, 4
|
|
pat.reset()
|
|
// After reset: drop 2 again then emit
|
|
#expect(pat.next() == 3)
|
|
#expect(pat.next() == 4)
|
|
}
|
|
}
|