Skip to content

Commit

Permalink
Add tests for Hold
Browse files Browse the repository at this point in the history
  • Loading branch information
Shatur committed Oct 16, 2024
1 parent 041b727 commit 7275ed4
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/input_context/input_condition/hold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}

0 comments on commit 7275ed4

Please sign in to comment.