49 lines
1.4 KiB
Swift
49 lines
1.4 KiB
Swift
// PatternRoundTests.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Testing
|
|
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
|
|
|
@MainActor
|
|
@Suite("Pattern.round")
|
|
struct PatternRoundTests {
|
|
|
|
@Test func roundsToStepGrid() {
|
|
let pat: Pattern<Double> = Pattern.round(
|
|
Pattern.sequence([0.0, 1.4, 1.5, 2.7, 10.0], repeats: 1),
|
|
step: 1.0
|
|
)
|
|
#expect(pat.next() == 0.0)
|
|
#expect(pat.next() == 1.0)
|
|
#expect(pat.next() == 2.0) // 1.5 → 2.0 under .toNearestOrAwayFromZero
|
|
#expect(pat.next() == 3.0)
|
|
#expect(pat.next() == 10.0)
|
|
}
|
|
|
|
@Test func roundsToFractionalStep() {
|
|
let pat: Pattern<Double> = Pattern.round(
|
|
Pattern.sequence([0.1, 0.24, 0.26, 0.5], repeats: 1),
|
|
step: 0.25
|
|
)
|
|
#expect(pat.next() == 0.0)
|
|
#expect(pat.next() == 0.25)
|
|
#expect(pat.next() == 0.25)
|
|
#expect(pat.next() == 0.5)
|
|
}
|
|
|
|
@Test func tiesAwayFromZeroMatchSCPround() {
|
|
// SC Pround uses round-half-away-from-zero, not banker's rounding.
|
|
// 2.5 → 3.0 (away), 0.5 → 1.0 (away), -1.5 → -2.0 (away).
|
|
let pat: Pattern<Double> = Pattern.round(
|
|
Pattern.sequence([0.5, 2.5, -1.5], repeats: 1),
|
|
step: 1.0
|
|
)
|
|
#expect(pat.next() == 1.0)
|
|
#expect(pat.next() == 3.0)
|
|
#expect(pat.next() == -2.0)
|
|
}
|
|
}
|