Add equivalence tests for next() and next_step()
This commit is contained in:
parent
9f990cc3b9
commit
bb6e9c237f
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2583,6 +2583,7 @@ name = "nih_plug"
|
|||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"approx 0.5.1",
|
||||
"assert_no_alloc",
|
||||
"atomic_float",
|
||||
"atomic_refcell",
|
||||
|
|
|
@ -108,6 +108,9 @@ vst3-sys = { git = "https://github.com/robbert-vdh/vst3-sys.git", branch = "fix/
|
|||
# Used for the `zstd` feature
|
||||
zstd = { version = "0.11.2", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
approx = "0.5.1"
|
||||
|
||||
[target.'cfg(all(target_family = "unix", not(target_os = "macos")))'.dependencies]
|
||||
libc = "0.2.124"
|
||||
|
||||
|
|
|
@ -371,6 +371,58 @@ impl Smoothable for i32 {
|
|||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Applying `next()` `n` times should be the same as `next_step()` for `n` steps.
|
||||
#[test]
|
||||
fn linear_f32_next_equivalance() {
|
||||
let style = SmoothingStyle::Linear(100.0);
|
||||
|
||||
let mut current = 0.4;
|
||||
let target = 0.8;
|
||||
let steps = 15;
|
||||
let step_size = style.step_size(current, target, steps);
|
||||
|
||||
let expected_result = style.next_step(current, target, step_size, steps);
|
||||
for _ in 0..steps {
|
||||
current = style.next(current, target, step_size);
|
||||
}
|
||||
|
||||
approx::assert_relative_eq!(current, expected_result, epsilon = 1e-5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn logarithmic_f32_next_equivalance() {
|
||||
let style = SmoothingStyle::Logarithmic(100.0);
|
||||
|
||||
let mut current = 0.4;
|
||||
let target = 0.8;
|
||||
let steps = 15;
|
||||
let step_size = style.step_size(current, target, steps);
|
||||
|
||||
let expected_result = style.next_step(current, target, step_size, steps);
|
||||
for _ in 0..steps {
|
||||
current = style.next(current, target, step_size);
|
||||
}
|
||||
|
||||
approx::assert_relative_eq!(current, expected_result, epsilon = 1e-5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exponential_f32_next_equivalance() {
|
||||
let style = SmoothingStyle::Exponential(100.0);
|
||||
|
||||
let mut current = 0.4;
|
||||
let target = 0.8;
|
||||
let steps = 15;
|
||||
let step_size = style.step_size(current, target, steps);
|
||||
|
||||
let expected_result = style.next_step(current, target, step_size, steps);
|
||||
for _ in 0..steps {
|
||||
current = style.next(current, target, step_size);
|
||||
}
|
||||
|
||||
approx::assert_relative_eq!(current, expected_result, epsilon = 1e-5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn linear_f32_smoothing() {
|
||||
let mut smoother: Smoother<f32> = Smoother::new(SmoothingStyle::Linear(100.0));
|
||||
|
|
Loading…
Reference in a new issue