Skip to content

Commit

Permalink
Merge pull request #47 from tharvik/test-sequencer-reset
Browse files Browse the repository at this point in the history
sequencer: add reset tests
  • Loading branch information
SamiPerttu authored Jul 14, 2024
2 parents 2109988 + 865afab commit d0cb5ef
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,3 +789,45 @@ impl AudioUnit for Sequencer {
core::mem::size_of::<Self>()
}
}

#[cfg(test)]
mod tests {
use hacker::sine_hz;

use super::*;

#[test]
fn reset_replays_events() {
let mut seq = Sequencer::new(true, 1);
seq.set_sample_rate(1.0);
seq.push(0.0, 1.0, Fade::Smooth, 0.0, 0.0, Box::new(sine_hz(440.0)));

let mut first = [0.0; 1];
seq.tick(&[], &mut first);

seq.reset();

let mut second = [0.0; 1];
seq.tick(&[], &mut second);

assert_eq!(first, second);
}

#[test]
fn reset_replays_events_with_backend() {
let mut front = Sequencer::new(true, 1);
front.set_sample_rate(1.0);
front.push(0.0, 1.0, Fade::Smooth, 0.0, 0.0, Box::new(sine_hz(440.0)));
let mut back = front.backend();

let mut first = [0.0; 1];
back.tick(&[], &mut first);

front.reset();

let mut second = [0.0; 1];
back.tick(&[], &mut second);

assert_eq!(first, second);
}
}

0 comments on commit d0cb5ef

Please sign in to comment.