From 0973ac1666a6ee3b606a537742abe506719fd156 Mon Sep 17 00:00:00 2001 From: tom barrett Date: Sat, 2 Mar 2019 11:01:02 -0600 Subject: engines tests --- tests/tests.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'tests') diff --git a/tests/tests.rs b/tests/tests.rs index 141cc41..ddbbaf7 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -173,4 +173,46 @@ mod test { assert!(masses.len() == 2); assert!(ship.item_count(ItemType::Iron) == 0); } + + #[test] + fn test_engines() { + let (mut ship, mut masses) = setup(); + setup_ship_target(&mut ship, &mut masses); + + let mut astroid = masses.remove("astroid").unwrap(); + astroid.velocity = Vector::new((constants::SHIP_ENGINES_ACCELERATION * 2.0, 0.0, 0.0)); + astroid.process(&mut masses); + masses.insert(String::from("astroid"), astroid); + + ship.give_received_data(ModuleType::Engines, String::from("c")); + ship.process(&mut masses); + assert!(ship.velocity.x == constants::SHIP_ENGINES_ACCELERATION); + + ship.process(&mut masses); + assert!(ship.velocity.x == constants::SHIP_ENGINES_ACCELERATION * 2.0); + + ship.process(&mut masses); + assert!(ship.velocity.x == constants::SHIP_ENGINES_ACCELERATION * 2.0); + + ship.give_received_data(ModuleType::Engines, String::from("s")); + ship.process(&mut masses); + assert!(ship.velocity.x == constants::SHIP_ENGINES_ACCELERATION); + + ship.process(&mut masses); + assert!(ship.velocity.x == 0.0); + + ship.process(&mut masses); + assert!(ship.velocity.x == 0.0); + + ship.give_received_data(ModuleType::Engines, String::from("t")); + ship.process(&mut masses); + assert!(ship.velocity.x == constants::SHIP_ENGINES_ACCELERATION * -1.0); + + ship.process(&mut masses); + assert!(ship.velocity.x == constants::SHIP_ENGINES_ACCELERATION * -1.0); + + ship.give_received_data(ModuleType::Engines, String::from("t")); + ship.process(&mut masses); + assert!(ship.velocity.x == constants::SHIP_ENGINES_ACCELERATION * -2.0); + } } -- cgit v1.2.3