From d67f5efe484072c4cb441dd95e788a0ef17552c5 Mon Sep 17 00:00:00 2001 From: p6nj Date: Mon, 14 Oct 2024 12:45:07 -0400 Subject: [PATCH] inflate mixed and panic tests failing --- src/bng/score/utils/tests.rs | 91 ++++++++++++++++++++++++++++-------- 1 file changed, 72 insertions(+), 19 deletions(-) diff --git a/src/bng/score/utils/tests.rs b/src/bng/score/utils/tests.rs index 5c833a0..d705150 100644 --- a/src/bng/score/utils/tests.rs +++ b/src/bng/score/utils/tests.rs @@ -1,12 +1,22 @@ #[cfg(test)] mod inflate { use fasteval::Compiler; - use lex::UP; + use lex::{ON, UP}; use super::{super::*, inflate}; const FASTEVAL_INSTRUCTION: &str = "1-cos((PI*x)/2)"; + fn instruction() -> Instruction { + let parser = fasteval::Parser::new(); + let mut slab = fasteval::Slab::new(); + parser + .parse(FASTEVAL_INSTRUCTION, &mut slab.ps) + .unwrap() + .from(&slab.ps) + .compile(&slab.ps, &mut slab.cs) + } + #[test] fn inflate_flat() { assert_eq!( @@ -60,15 +70,6 @@ mod inflate { #[test] fn inflate_slope_l1() { - let instruction = || { - let parser = fasteval::Parser::new(); - let mut slab = fasteval::Slab::new(); - parser - .parse(FASTEVAL_INSTRUCTION, &mut slab.ps) - .unwrap() - .from(&slab.ps) - .compile(&slab.ps, &mut slab.cs) - }; assert_eq!( vec![Atom::Slope( SlopeModifier::Note, @@ -125,15 +126,6 @@ mod inflate { #[test] fn inflate_slope_l2() { - let instruction = || { - let parser = fasteval::Parser::new(); - let mut slab = fasteval::Slab::new(); - parser - .parse(FASTEVAL_INSTRUCTION, &mut slab.ps) - .unwrap() - .from(&slab.ps) - .compile(&slab.ps, &mut slab.cs) - }; assert_eq!( vec![Atom::Slope( SlopeModifier::Note, @@ -154,4 +146,65 @@ mod inflate { ]) ) } + + #[test] + fn mixed() { + assert_eq!( + vec![Atom::Slope( + SlopeModifier::Note, + instruction(), + vec![Atom::Slope( + SlopeModifier::Length, + instruction(), + vec![ + Atom::Note(2), + Atom::Tuple(vec![Atom::Rest, Atom::Note(6)]), + Atom::Note(3), + Atom::Loop( + unsafe { NonZeroU8::new_unchecked(9) }, + vec![Atom::QuickModifier(QuickModifier::Pizz(ON)), Atom::Note(0)] + ) + ] + )] + )], + inflate(vec![ + FlatAtom::SlopeStarts(SlopeModifier::Note, instruction()), + FlatAtom::SlopeStarts(SlopeModifier::Length, instruction()), + FlatAtom::Note(2), + FlatAtom::TupleStarts, + FlatAtom::Rest, + FlatAtom::Note(6), + FlatAtom::TupleEnds, + FlatAtom::Note(3), + FlatAtom::LoopStarts(unsafe { NonZeroU8::new_unchecked(9) }), + FlatAtom::QuickModifier(QuickModifier::Pizz(ON)), + FlatAtom::Note(0), + FlatAtom::LoopEnds, + FlatAtom::SlopeEnds, + FlatAtom::SlopeEnds + ]) + ) + } + + #[test] + #[should_panic] + fn mixed_panic() { + inflate(vec![ + FlatAtom::SlopeStarts(SlopeModifier::Note, instruction()), + FlatAtom::SlopeStarts(SlopeModifier::Length, instruction()), + FlatAtom::Note(2), + FlatAtom::TupleStarts, + FlatAtom::Rest, + FlatAtom::SlopeEnds, // mismatched slope end while in a tuple + FlatAtom::Note(6), + FlatAtom::TupleEnds, + FlatAtom::Note(3), + FlatAtom::LoopStarts(unsafe { NonZeroU8::new_unchecked(9) }), + FlatAtom::QuickModifier(QuickModifier::Pizz(ON)), + FlatAtom::Note(0), + FlatAtom::LoopEnds, + FlatAtom::SlopeEnds, + FlatAtom::SlopeEnds, + ]); + } }