diff --git a/src/input_context/input_condition/hold.rs b/src/input_context/input_condition/hold.rs index 712f999..cb91910 100644 --- a/src/input_context/input_condition/hold.rs +++ b/src/input_context/input_condition/hold.rs @@ -89,3 +89,52 @@ impl InputCondition for Hold { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn hold() { + let world = World::new(); + let actions_data = ActionsData::default(); + + let mut hold = Hold::new(1.0); + assert_eq!( + hold.evaluate(&world, &actions_data, 0.0, 1.0.into()), + ActionState::Ongoing, + ); + assert_eq!( + hold.evaluate(&world, &actions_data, 1.0, 1.0.into()), + ActionState::Fired, + ); + assert_eq!( + hold.evaluate(&world, &actions_data, 1.0, 1.0.into()), + ActionState::Fired, + ); + assert_eq!( + hold.evaluate(&world, &actions_data, 1.0, 0.0.into()), + ActionState::None, + ); + assert_eq!( + hold.evaluate(&world, &actions_data, 0.0, 1.0.into()), + ActionState::Ongoing, + ); + } + + #[test] + fn one_shot() { + let world = World::new(); + let actions_data = ActionsData::default(); + + let mut hold = Hold::new(1.0).one_shot(true); + assert_eq!( + hold.evaluate(&world, &actions_data, 1.0, 1.0.into()), + ActionState::Fired, + ); + assert_eq!( + hold.evaluate(&world, &actions_data, 1.0, 1.0.into()), + ActionState::None, + ); + } +}