From 66b42e2aa0adc2b08085028f4d24836ecba381ff Mon Sep 17 00:00:00 2001 From: p6nj Date: Mon, 14 Oct 2024 11:17:44 -0400 Subject: [PATCH] inflate passing L1 tests --- src/bng/score.rs | 10 +++++----- src/bng/score/utils.rs | 13 +++++++++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/bng/score.rs b/src/bng/score.rs index bbed848..57a47d1 100644 --- a/src/bng/score.rs +++ b/src/bng/score.rs @@ -8,7 +8,7 @@ use strum::EnumDiscriminants; mod lex; mod utils; -#[cfg_attr(test, derive(Debug, PartialEq))] +#[cfg_attr(debug_assertions, derive(Debug, PartialEq))] pub(super) enum Atom { Note(u8), Rest, @@ -21,7 +21,7 @@ pub(super) enum Atom { Comment, } -#[cfg_attr(test, derive(Debug, PartialEq))] +#[cfg_attr(debug_assertions, derive(Debug, PartialEq))] pub(super) enum FlatAtom { Note(u8), Rest, @@ -53,7 +53,7 @@ impl Clone for FlatAtom { } #[derive(Clone)] -#[cfg_attr(test, derive(Debug, PartialEq))] +#[cfg_attr(debug_assertions, derive(Debug, PartialEq))] pub(super) enum Modifier { Volume(u8), Octave(u8), @@ -68,7 +68,7 @@ impl Default for Modifier { } #[derive(QuickModifierParser, Clone)] -#[cfg_attr(test, derive(Debug, PartialEq))] +#[cfg_attr(debug_assertions, derive(Debug, PartialEq))] pub(super) enum QuickModifier { Volume(bool), Octave(bool), @@ -77,7 +77,7 @@ pub(super) enum QuickModifier { } #[derive(Clone, Copy, SlopeModifierParser)] -#[cfg_attr(test, derive(Debug, PartialEq))] +#[cfg_attr(debug_assertions, derive(Debug, PartialEq))] pub(super) enum SlopeModifier { Note, Volume, diff --git a/src/bng/score/utils.rs b/src/bng/score/utils.rs index b89e997..4229a60 100644 --- a/src/bng/score/utils.rs +++ b/src/bng/score/utils.rs @@ -6,6 +6,7 @@ mod tests; // TODO: replace panics with custom error type fn inflate(mut flat_atoms: Vec) -> Vec { #[derive(EnumDiscriminants)] + #[cfg_attr(debug_assertions, derive(Debug))] enum CurrentStack { Loop(NonZeroU8), Tuple, @@ -17,6 +18,14 @@ fn inflate(mut flat_atoms: Vec) -> Vec { let mut slope_stack: Vec> = Vec::new(); let mut stack_history: Vec = Vec::new(); for mut atom in flat_atoms.into_iter() { + // #[cfg(test)] + // { + // dbg!(&atom); + // dbg!(&loop_stack); + // dbg!(&tuple_stack); + // dbg!(&slope_stack); + // dbg!(&stack_history); + // } if let Some(stack) = stack_history.last() { match CurrentStackDiscriminants::from(stack) { CurrentStackDiscriminants::Loop => match atom { @@ -92,7 +101,7 @@ fn inflate(mut flat_atoms: Vec) -> Vec { stack_history.push(CurrentStack::Tuple); } FlatAtom::TupleEnds => { - let popped = loop_stack.pop().unwrap(); + let popped = tuple_stack.pop().unwrap(); if stack_history.len() > 1 { match CurrentStackDiscriminants::from( stack_history.get(stack_history.len() - 2).unwrap(), @@ -140,7 +149,7 @@ fn inflate(mut flat_atoms: Vec) -> Vec { stack_history.push(CurrentStack::Slope(s, i)); } FlatAtom::SlopeEnds => { - let popped = loop_stack.pop().unwrap(); + let popped = slope_stack.pop().unwrap(); if stack_history.len() > 1 { match CurrentStackDiscriminants::from( stack_history.get(stack_history.len() - 2).unwrap(),