From 967535d771134bfbe5c058cfb97ce43afda75192 Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Sat, 10 Jul 2021 21:16:14 +0200 Subject: [PATCH] Implemented test for modulation amounts --- src/matrix_repr.rs | 4 +-- tests/modamt.rs | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/src/matrix_repr.rs b/src/matrix_repr.rs index 08aaebb..849f454 100644 --- a/src/matrix_repr.rs +++ b/src/matrix_repr.rs @@ -674,11 +674,11 @@ mod tests { .input(None, Some(0), None) .out(None, None, Some(0))); matrix.set_param_modamt( - sin.inp_param("det").unwrap(), Some(-0.6)); + sin.inp_param("det").unwrap(), Some(-0.6)).unwrap(); matrix.sync().unwrap(); matrix.set_param_modamt( - sin.inp_param("freq").unwrap(), Some(0.6)); + sin.inp_param("freq").unwrap(), Some(0.6)).unwrap(); matrix.to_repr() }; diff --git a/tests/modamt.rs b/tests/modamt.rs index 91dd749..058cd6c 100644 --- a/tests/modamt.rs +++ b/tests/modamt.rs @@ -44,3 +44,92 @@ fn check_param_mod_amt_with_input() { let rms = run_and_get_first_rms_mimax(&mut node_exec, 50.0); assert_rmsmima!(rms, (0.4992, -1.0, 1.0)); } + +#[test] +fn check_param_mod_amt_set() { + let (node_conf, mut node_exec) = new_node_engine(); + let mut matrix = Matrix::new(node_conf, 3, 3); + + let tst = NodeId::Test(0); + let amp = NodeId::Amp(0); + let out = NodeId::Out(0); + matrix.place(0, 0, Cell::empty(tst) + .out(None, None, tst.out("sig"))); + matrix.place(0, 1, Cell::empty(amp) + .input(amp.inp("inp"), None, None) + .out(None, None, amp.out("sig"))); + matrix.place(0, 2, Cell::empty(out) + .input(out.inp("ch1"), None, None)); + pset_n(&mut matrix, tst, "p", 1.0); + matrix.sync().unwrap(); + + // Run with no modulation + let rms = run_and_get_first_rms_mimax(&mut node_exec, 50.0); + assert_rmsmima!(rms, (1.0, 1.0, 1.0)); + + // Enable modulation + matrix.set_param_modamt( + amp.inp_param("inp").unwrap(), Some(0.2)).unwrap(); + + let rms = run_and_get_first_rms_mimax(&mut node_exec, 50.0); + assert_rmsmima!(rms, (0.04, 0.2, 0.2)); + + // Change modulation + matrix.set_param_modamt( + amp.inp_param("inp").unwrap(), Some(0.1)).unwrap(); + + let rms = run_and_get_first_rms_mimax(&mut node_exec, 50.0); + assert_rmsmima!(rms, (0.01, 0.1, 0.1)); + + // Remove modulation + matrix.set_param_modamt( + amp.inp_param("inp").unwrap(), None).unwrap(); + + let rms = run_and_get_first_rms_mimax(&mut node_exec, 50.0); + assert_rmsmima!(rms, (1.0, 1.0, 1.0)); +} + + +#[test] +fn check_param_mod_amt_set_bipol() { + let (node_conf, mut node_exec) = new_node_engine(); + let mut matrix = Matrix::new(node_conf, 3, 3); + + let tst = NodeId::Test(0); + let amp = NodeId::Amp(0); + let out = NodeId::Out(0); + matrix.place(0, 0, Cell::empty(tst) + .out(None, None, tst.out("sig"))); + matrix.place(0, 1, Cell::empty(amp) + .input(amp.inp("inp"), None, None) + .out(None, None, amp.out("sig"))); + matrix.place(0, 2, Cell::empty(out) + .input(out.inp("ch1"), None, None)); + pset_n(&mut matrix, tst, "p", -1.0); + matrix.sync().unwrap(); + + // Run with no modulation + let rms = run_and_get_first_rms_mimax(&mut node_exec, 50.0); + assert_rmsmima!(rms, (1.0, -1.0, -1.0)); + + // Enable modulation + matrix.set_param_modamt( + amp.inp_param("inp").unwrap(), Some(0.2)).unwrap(); + + let rms = run_and_get_first_rms_mimax(&mut node_exec, 50.0); + assert_rmsmima!(rms, (0.04, -0.2, -0.2)); + + // Change modulation + matrix.set_param_modamt( + amp.inp_param("inp").unwrap(), Some(0.1)).unwrap(); + + let rms = run_and_get_first_rms_mimax(&mut node_exec, 50.0); + assert_rmsmima!(rms, (0.01, -0.1, -0.1)); + + // Remove modulation + matrix.set_param_modamt( + amp.inp_param("inp").unwrap(), None).unwrap(); + + let rms = run_and_get_first_rms_mimax(&mut node_exec, 50.0); + assert_rmsmima!(rms, (1.0, -1.0, -1.0)); +}