From ce9adc4cc1b4b30322dc30ee85c42ee1451ffbf9 Mon Sep 17 00:00:00 2001 From: tom barrett Date: Thu, 21 Feb 2019 11:20:16 -0600 Subject: redid engines, finished simple construction tests, setup recv using less parameters --- tests/tests.rs | 75 +++++++++++++++++++++++----------------------------------- 1 file changed, 29 insertions(+), 46 deletions(-) (limited to 'tests') diff --git a/tests/tests.rs b/tests/tests.rs index 53c314a..141cc41 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -8,7 +8,7 @@ mod test { use space::constants; use space::item::{Item, ItemType}; - use space::mass::{Mass, MassType}; + use space::mass::Mass; use space::math::Vector; use space::modules::construction; use space::modules::mining; @@ -28,7 +28,7 @@ mod test { } fn setup_ship_target(ship: &mut Mass, masses: &mut HashMap) { - ship.give_received_data(ModuleType::Navigation, String::from("astroid"), &masses); + ship.give_received_data(ModuleType::Navigation, String::from("astroid")); ship.process(masses); sleep(Duration::from_secs(constants::SHIP_NAVIGATION_TIME + 1)); ship.process(masses); @@ -38,7 +38,7 @@ mod test { fn test_navigation_range() { let (mut ship, mut masses) = setup(); - ship.give_received_data(ModuleType::Navigation, String::from("astroid"), &masses); + ship.give_received_data(ModuleType::Navigation, String::from("astroid")); ship.process(&mut masses); let data = ship.get_client_data(ModuleType::Navigation, &masses); let navigation_data: navigation::ClientData = serde_json::from_str(&data).unwrap(); @@ -74,7 +74,7 @@ mod test { let (mut ship, mut masses) = setup(); setup_ship_target(&mut ship, &mut masses); - ship.give_received_data(ModuleType::Mining, String::from("F"), &masses); + ship.give_received_data(ModuleType::Mining, String::from("F")); ship.process(&mut masses); let data = ship.get_client_data(ModuleType::Mining, &masses); let mining_data: mining::ClientData = serde_json::from_str(&data).unwrap(); @@ -93,7 +93,7 @@ mod test { let (mut ship, mut masses) = setup(); setup_ship_target(&mut ship, &mut masses); - ship.give_received_data(ModuleType::Mining, String::from("F"), &masses); + ship.give_received_data(ModuleType::Mining, String::from("F")); ship.process(&mut masses); sleep(Duration::from_secs(constants::SHIP_MINING_TIME + 1)); ship.process(&mut masses); @@ -113,7 +113,7 @@ mod test { ship.give_item(Item::new(ItemType::CrudeMinerals)); } - ship.give_received_data(ModuleType::Mining, String::from("F"), &masses); + ship.give_received_data(ModuleType::Mining, String::from("F")); ship.process(&mut masses); sleep(Duration::from_secs(constants::SHIP_MINING_TIME + 1)); assert!(masses.len() == 1); @@ -126,7 +126,7 @@ mod test { let (mut ship, mut masses) = setup(); setup_ship_target(&mut ship, &mut masses); - ship.give_received_data(ModuleType::Refinery, String::from("R"), &masses); + ship.give_received_data(ModuleType::Refinery, String::from("R")); ship.process(&mut masses); let data = ship.get_client_data(ModuleType::Refinery, &masses); let mining_data: refinery::ClientData = serde_json::from_str(&data).unwrap(); @@ -134,7 +134,7 @@ mod test { ship.give_item(Item::new(ItemType::CrudeMinerals)); - ship.give_received_data(ModuleType::Refinery, String::from("R"), &masses); + ship.give_received_data(ModuleType::Refinery, String::from("R")); ship.process(&mut masses); let data = ship.get_client_data(ModuleType::Refinery, &masses); let mining_data: refinery::ClientData = serde_json::from_str(&data).unwrap(); @@ -150,44 +150,27 @@ mod test { fn test_construction() { let (mut ship, mut masses) = setup(); - if let MassType::Ship { - ref mut storage, - ref mut construction, - .. - } = ship.mass_type - { - construction.give_received_data(String::from("c")); - construction.process( - ship.velocity.clone(), - ship.position.clone(), - &mut masses, - storage, - ); - assert!(construction.status == construction::Status::None); - - for _ in 0..5 { - storage.give_item(Item::new(ItemType::Iron)); - } - - construction.give_received_data(String::from("c")); - construction.process( - ship.velocity.clone(), - ship.position.clone(), - &mut masses, - storage, - ); - assert!(construction.status == construction::Status::Constructing); - assert!(masses.len() == 1); - - sleep(Duration::from_secs(constants::SHIP_CONSTRUCTION_TIME + 1)); - construction.process( - ship.velocity.clone(), - ship.position.clone(), - &mut masses, - storage, - ); - assert!(masses.len() == 2); - assert!(storage.items.len() == 0); + ship.give_received_data(ModuleType::Construction, String::from("c")); + ship.process(&mut masses); + let data = ship.get_client_data(ModuleType::Construction, &masses); + let construction_data: construction::ClientData = serde_json::from_str(&data).unwrap(); + assert!(construction_data.status == construction::Status::None); + + for _ in 0..5 { + ship.give_item(Item::new(ItemType::Iron)); } + + ship.give_received_data(ModuleType::Construction, String::from("c")); + ship.process(&mut masses); + + let data = ship.get_client_data(ModuleType::Construction, &masses); + let construction_data: construction::ClientData = serde_json::from_str(&data).unwrap(); + assert!(construction_data.status == construction::Status::Constructing); + assert!(masses.len() == 1); + + sleep(Duration::from_secs(constants::SHIP_CONSTRUCTION_TIME + 1)); + ship.process(&mut masses); + assert!(masses.len() == 2); + assert!(ship.item_count(ItemType::Iron) == 0); } } -- cgit v1.2.3