bugfixes, better MusicXML support and 1.1.0
This commit is contained in:
@@ -98,4 +98,49 @@ struct PatternTests {
|
||||
#expect(pat.next() == "mi")
|
||||
#expect(pat.next() == "do") // wraps
|
||||
}
|
||||
|
||||
@Test func offsetShiftsOnlyFirstPass() {
|
||||
// First pass opens at index 1 and runs short; later cycles run full.
|
||||
let pat: Pattern<Int> = Pattern.sequence([1, 2, 3], offset: 1)
|
||||
#expect(pat.next() == 2)
|
||||
#expect(pat.next() == 3)
|
||||
#expect(pat.next() == 1) // full cycle from index 0
|
||||
#expect(pat.next() == 2)
|
||||
#expect(pat.next() == 3)
|
||||
#expect(pat.next() == 1) // and again
|
||||
}
|
||||
|
||||
@Test func offsetResetReturnsToOffsetStart() {
|
||||
let pat: Pattern<Int> = Pattern.sequence([1, 2, 3], offset: 2)
|
||||
#expect(pat.next() == 3)
|
||||
#expect(pat.next() == 1)
|
||||
pat.reset()
|
||||
#expect(pat.next() == 3) // back to the offset start, not index 0
|
||||
}
|
||||
|
||||
@Test func offsetCountsShortFirstPassAsACycle() {
|
||||
// repeats: 2, offset: 1 → short pass [2,3] then one full [1,2,3].
|
||||
let pat: Pattern<Int> = Pattern.sequence([1, 2, 3], repeats: 2, offset: 1)
|
||||
#expect(pat.next() == 2)
|
||||
#expect(pat.next() == 3)
|
||||
#expect(pat.next() == 1)
|
||||
#expect(pat.next() == 2)
|
||||
#expect(pat.next() == 3)
|
||||
#expect(pat.next() == nil)
|
||||
#expect(pat.isExhausted)
|
||||
}
|
||||
|
||||
@Test func offsetWrapsOutOfRange() {
|
||||
// offset 4 on a 3-element list normalises to index 1.
|
||||
let pat: Pattern<Int> = Pattern.sequence([1, 2, 3], offset: 4)
|
||||
#expect(pat.next() == 2)
|
||||
// Negative offsets wrap too: -1 → index 2.
|
||||
let neg: Pattern<Int> = Pattern.sequence([1, 2, 3], offset: -1)
|
||||
#expect(neg.next() == 3)
|
||||
}
|
||||
|
||||
@Test func offsetOnEmptyValuesIsSafe() {
|
||||
let pat: Pattern<Int> = Pattern<Int>.sequence([], offset: 5)
|
||||
#expect(pat.next() == nil)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user