From a25bd755947b1b31338338b76a0356e85169d171 Mon Sep 17 00:00:00 2001 From: Paul Heinrich Date: Mon, 18 Dec 2023 13:32:28 +0100 Subject: [PATCH] moved test cases --- .../no_updates/expected_events.pbf | Bin 1389 -> 0 bytes .../with_updates/expected_events.pbf | Bin 2650 -> 0 bytes tests/equil_it.rs | 38 - tests/event_test_utils.rs | 197 -- .../resources}/3-links/1-agent-full-leg.binpb | Bin .../resources}/3-links/3-links-config-1.yml | 8 +- .../resources}/3-links/3-links-config-2.yml | 8 +- .../resources}/3-links/3-links-network.binpb | Bin tests/resources/3-links/expected_events.xml | 23 + {assets => tests/resources}/3-links/ids.binpb | Bin .../resources}/3-links/vehicles.binpb | Bin .../adhoc_routing/no_updates/agents.binpb | Bin .../adhoc_routing/no_updates/config-1.yml | 8 +- .../adhoc_routing/no_updates/config-2.yml | 8 +- .../no_updates/expected_events.xml | 0 .../adhoc_routing/no_updates/ids.binpb | Bin .../adhoc_routing/no_updates/network.binpb | Bin .../no_updates/output_events.xml | 73 - .../adhoc_routing/no_updates/vehicles.binpb | Bin .../adhoc_routing/with_updates/agents.binpb | Bin .../adhoc_routing/with_updates/config-1.yml | 8 +- .../adhoc_routing/with_updates/config-2.yml | 8 +- .../with_updates/expected_events.xml | 0 .../adhoc_routing/with_updates/ids.binpb | Bin .../adhoc_routing/with_updates/network.binpb | Bin .../with_updates/output_events.xml | 147 - .../adhoc_routing/with_updates/vehicles.binpb | Bin tests/resources/equil/output_events.xml | 2609 ----------------- .../three_link/full_legs/output_events.xml | 19 - .../multiple_agents/no_jam/output_events.xml | 33 - .../with_jam/output_events.xml | 33 - tests/resources/three_link/output_events.xml | 13 - tests/test_3_links.rs | 31 + tests/test_adhoc_routing.rs | 63 + tests/test_simulation.rs | 135 +- tests/three_link_it.rs | 115 - 36 files changed, 147 insertions(+), 3430 deletions(-) delete mode 100644 assets/adhoc_routing/no_updates/expected_events.pbf delete mode 100644 assets/adhoc_routing/with_updates/expected_events.pbf delete mode 100644 tests/equil_it.rs delete mode 100644 tests/event_test_utils.rs rename {assets => tests/resources}/3-links/1-agent-full-leg.binpb (100%) rename {assets => tests/resources}/3-links/3-links-config-1.yml (61%) rename {assets => tests/resources}/3-links/3-links-config-2.yml (60%) rename {assets => tests/resources}/3-links/3-links-network.binpb (100%) create mode 100644 tests/resources/3-links/expected_events.xml rename {assets => tests/resources}/3-links/ids.binpb (100%) rename {assets => tests/resources}/3-links/vehicles.binpb (100%) rename {assets => tests/resources}/adhoc_routing/no_updates/agents.binpb (100%) rename {assets => tests/resources}/adhoc_routing/no_updates/config-1.yml (56%) rename {assets => tests/resources}/adhoc_routing/no_updates/config-2.yml (56%) rename {assets => tests/resources}/adhoc_routing/no_updates/expected_events.xml (100%) rename {assets => tests/resources}/adhoc_routing/no_updates/ids.binpb (100%) rename {assets => tests/resources}/adhoc_routing/no_updates/network.binpb (100%) delete mode 100644 tests/resources/adhoc_routing/no_updates/output_events.xml rename {assets => tests/resources}/adhoc_routing/no_updates/vehicles.binpb (100%) rename {assets => tests/resources}/adhoc_routing/with_updates/agents.binpb (100%) rename {assets => tests/resources}/adhoc_routing/with_updates/config-1.yml (56%) rename {assets => tests/resources}/adhoc_routing/with_updates/config-2.yml (56%) rename {assets => tests/resources}/adhoc_routing/with_updates/expected_events.xml (100%) rename {assets => tests/resources}/adhoc_routing/with_updates/ids.binpb (100%) rename {assets => tests/resources}/adhoc_routing/with_updates/network.binpb (100%) delete mode 100644 tests/resources/adhoc_routing/with_updates/output_events.xml rename {assets => tests/resources}/adhoc_routing/with_updates/vehicles.binpb (100%) delete mode 100644 tests/resources/equil/output_events.xml delete mode 100644 tests/resources/three_link/full_legs/output_events.xml delete mode 100644 tests/resources/three_link/multiple_agents/no_jam/output_events.xml delete mode 100644 tests/resources/three_link/multiple_agents/with_jam/output_events.xml delete mode 100644 tests/resources/three_link/output_events.xml create mode 100644 tests/test_3_links.rs create mode 100644 tests/test_adhoc_routing.rs delete mode 100644 tests/three_link_it.rs diff --git a/assets/adhoc_routing/no_updates/expected_events.pbf b/assets/adhoc_routing/no_updates/expected_events.pbf deleted file mode 100644 index bbca29f44baefd0b218cafc9622dca6158c72502..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1389 zcmZvc&ubG=5XY0Zo0r)%q%SWU3wzKuwp0_;Bv^fV6mnU3;hr5L7~-) zZN2#8BKlA0P0^cr)03b_JqUVH{LW;vw7Z+r%y+&s@6Bf)nWeqISsR$36clf4-Wsg7 zJDq0pe3QC5aJTy#H2gMX^Vh}&>V=MqEeF$U{n70DaBDE?uWhYw4j1SE zU8gERvXt-U0ta^0&XnjGT%_t5x27m(=o8X{TSv@-Hnj6E6f_I&S-KD5v|7%1y}WT{ zPSsWr#V@c(58#}u25H4Ym(U{Xb?6Yjc5=N!FY@@-!d@DTM*ZRS+pF!13}~KS-BI== z&{6g{I!uQo(=XE-n3gIlWy;3zVgAI04G_jRI7e^MyNC@^ie5Jll`-nJOIhPs`T%zk z?2MypBKh!b5U$WicspqjioGMg6V{ie1nB*{A!wBZttOx!!z7?p3h2$s&VR z5ol$!rI&CEXw6J>Mgue?0ga4B&EoF8P(;R}YjleaAPQ)VV$dpl#SEI`BlRJ)@&tXx{xk|rbyu=^WDL?=9@X_|y zx$sYc&xw4z6DRSVTJ#6~4Sqan<*BYG`s8&x#`EdLUPRa%6NdPCB5EU|YrGbHgD8a2 p$Aq0DggK7ira|A)A%xS)lfgeN_ac?;R8Ac-}d&va$cv z+L_gjl@n)9t*=eX17v+Xk%ys?UYuLlO?PNap28(&b|^YvWZ20rwxiK3))b7BJO6pX zP_RxOm4c-ZeJal&95hQqt^SCM^ud$q1XlHmX5=}XpG@XW!O@-|MbEn^f5X=e&pX<$ zJXxB;KDN5Cv9fmZyW`z2NNh^(oipi2U@61zv&7RO>C>0xF-(Uij*ZK3jVGR8x^Mz4 z>nE6#C&-<_2^xZ}-Uw83O}Y_K+Eo68yA7DmCI?i?lGi8%gC7Cmp6yoy-`h5GDqbnco&<V!KCy}1AXrzebYeycjPMlFi85QqHkQ1%3p9R{iL9uWbz7< zr>|n{AU^osi`dbbP`vqr7qO#gDc&kY?248o3vvgdwgfL_OUyt^xDH#gjSOu`QsqP2fm>VBDq7OQ>_hS`Q89L{DS3R^mmP&=do;_k1Cy2=HI(gLEIVw$vOHrh?{OGp z*~O*eJ&s(Pw-r?tqk%*GgIqmCyEsHUlYb%kL#SvR#9yvdBc#b7kjdRr#I6{j)|c`G z;t{?Ec@!;v;f}+?fwBVw#dSDPzan1;swvEYqV5OkIlMYh^=5ORDjx@mo7zBS^7>u< zS}OP~$Xked1+Zhq(LlvqhZXOY6*q-hF?C<@`5%47^**!W%EyYisZ~5B53l-Jio;oo z%Pa5)Ogc+(!z_6hXDJTOGAB=wt5+Zla+Zp}wVb8cbyC@dTc@W}Oiw41H<0}FsAwF- zi`Tq}T`?07uau%K#K?6Pe*<2fmpU2JuY9D> zO+bI=XHP!~>HGg)mgNOZN43d6QeSi{|;sXS?(oYNeD0>f* zr>~-M5O3b7=&NWc-YP}xm>#(lpMQu-AI~TKWPm=`A^mM+DE+1|=~FL1|L`jPIvLWh Ke5B7!jsE{Sxd*}k diff --git a/tests/equil_it.rs b/tests/equil_it.rs deleted file mode 100644 index dc9cef4c..00000000 --- a/tests/equil_it.rs +++ /dev/null @@ -1,38 +0,0 @@ -use serial_test::serial; - -use crate::event_test_utils::{compare_events, run_mpi_simulation_and_convert_events}; - -mod event_test_utils; - -#[test] -#[serial] -#[ignore] -fn test_equil_1() { - test_equil(1) -} - -#[test] -#[serial] -#[ignore] -fn test_equil_2() { - test_equil(2) -} - -#[test] -#[serial] -#[ignore] -fn test_equil_4() { - test_equil(4) -} - -fn test_equil(parts: usize) { - let output_dir = format!("test_output/mpi_test/equil_scenario/{}/", parts); - run_mpi_simulation_and_convert_events( - parts, - "assets/equil/equil-network.xml", - "assets/equil/equil-plans.xml.gz", - output_dir.as_str(), - None, - ); - compare_events(output_dir.as_str(), "tests/resources/equil") -} diff --git a/tests/event_test_utils.rs b/tests/event_test_utils.rs deleted file mode 100644 index 4a489d26..00000000 --- a/tests/event_test_utils.rs +++ /dev/null @@ -1,197 +0,0 @@ -use std::process::Command; -use std::str::FromStr; -use std::time::Duration; -use std::usize; - -use serde::{de, Deserialize, Deserializer, Serialize}; -use wait_timeout::ChildExt; - -use rust_q_sim::simulation::io::xml; - -#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)] -pub struct Events { - #[serde(rename = "event", default)] - events: Vec, -} - -#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)] -#[serde(tag = "type")] -enum SimEvent { - #[serde(rename = "actend")] - ActivityEnd(Activity), - #[serde(rename = "departure")] - Departure(ArrivalDeparture), - #[serde(rename = "PersonEntersVehicle")] - PersonEntersVehicle(PersonVehicleInteraction), - #[serde(rename = "left link")] - LeftLink(LinkInteraction), - #[serde(rename = "entered link")] - EnteredLink(LinkInteraction), - #[serde(rename = "PersonLeavesVehicle")] - PersonLeavesVehicle(PersonVehicleInteraction), - #[serde(rename = "arrival")] - Arrival(ArrivalDeparture), - #[serde(rename = "actstart")] - ActivityStart(Activity), - #[serde(rename = "travelled")] - Travelled(Travelled), -} - -#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)] -struct Activity { - #[serde(deserialize_with = "str_to_u64")] - time: u64, - #[serde(deserialize_with = "str_to_u64")] - person: u64, - #[serde(deserialize_with = "str_to_u64")] - link: u64, - #[serde(rename = "actType")] - act_type: String, -} - -#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)] -struct ArrivalDeparture { - #[serde(deserialize_with = "str_to_u64")] - time: u64, - #[serde(deserialize_with = "str_to_u64")] - person: u64, - #[serde(deserialize_with = "str_to_u64")] - link: u64, - #[serde(rename = "legMode")] - leg_mode: String, -} - -#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)] -struct PersonVehicleInteraction { - #[serde(deserialize_with = "str_to_u64")] - time: u64, - #[serde(deserialize_with = "str_to_u64")] - person: u64, - #[serde(deserialize_with = "str_to_u64")] - vehicle: u64, -} - -#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)] -struct LinkInteraction { - #[serde(deserialize_with = "str_to_u64")] - time: u64, - #[serde(deserialize_with = "str_to_u64")] - link: u64, - #[serde(deserialize_with = "str_to_u64")] - vehicle: u64, -} - -#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)] -struct Travelled { - #[serde(deserialize_with = "str_to_u64")] - person: u64, - #[serde(deserialize_with = "str_to_f32")] - distance: f32, - mode: String, -} - -fn str_to_u64<'de, D>(deserializer: D) -> Result -where - D: Deserializer<'de>, -{ - let s = String::deserialize(deserializer)?; - u64::from_str(&s).map_err(de::Error::custom) -} - -fn str_to_f32<'de, D>(deserializer: D) -> Result -where - D: Deserializer<'de>, -{ - let s = String::deserialize(deserializer)?; - f32::from_str(&s).map_err(de::Error::custom) -} - -pub fn run_mpi_simulation_and_convert_events( - number_of_parts: usize, - network_file: &str, - population_file: &str, - output_dir: &str, - vehicle_definitions_file: Option<&str>, -) { - let mut command = Command::new("cargo"); - command - .arg("mpirun") - .arg("-n") - .arg(format!("{}", number_of_parts)) - .arg("--bin") - .arg("mpi_qsim") - .arg("--") - .arg("--network-file") - .arg(network_file) - .arg("--population-file") - .arg(population_file) - .arg("--output-dir") - .arg(output_dir); - - if let Some(vehicle_definitions) = vehicle_definitions_file { - command - .arg("--vehicle-definitions-file") - .arg(vehicle_definitions); - } - - let mut child = command.spawn().unwrap(); - - let simulation_status = match child.wait_timeout(Duration::from_secs(15)).unwrap() { - None => { - child.kill().unwrap(); - child.wait().unwrap().code() - } - Some(status) => status.code(), - }; - - assert_eq!( - simulation_status, - Some(0), - "The Simulation did not finish and was killed." - ); - - let event_converison_status = Command::new("cargo") - .arg("run") - .arg("--bin") - .arg("proto2xml") - .arg("--") - .arg("--num-parts") - .arg(format!("{}", number_of_parts)) - .arg("--path") - .arg(output_dir.to_owned() + "events") - .status() - .unwrap(); - - assert_eq!(event_converison_status.code(), Some(0)); -} - -pub fn compare_events(output_dir: &str, path_to_expected_scenario_files: &str) { - let mut expected_output_events: Events = xml::read_from_file( - (String::from(path_to_expected_scenario_files) + "/output_events.xml").as_ref(), - ); - - let actual_output_events: Events = - xml::read_from_file((output_dir.to_owned() + "/events.xml").as_ref()); - - for actual_event in actual_output_events.events { - expected_output_events.events.remove( - expected_output_events - .events - .iter() - .position(|expected_event| *expected_event == actual_event) - .expect( - format!( - "Event {:?} was not expected to be in the output", - actual_event - ) - .as_str(), - ), - ); - } - - assert!( - expected_output_events.events.is_empty(), - "The following events are missing in the actual output: {:#?}", - expected_output_events.events - ); -} diff --git a/assets/3-links/1-agent-full-leg.binpb b/tests/resources/3-links/1-agent-full-leg.binpb similarity index 100% rename from assets/3-links/1-agent-full-leg.binpb rename to tests/resources/3-links/1-agent-full-leg.binpb diff --git a/assets/3-links/3-links-config-1.yml b/tests/resources/3-links/3-links-config-1.yml similarity index 61% rename from assets/3-links/3-links-config-1.yml rename to tests/resources/3-links/3-links-config-1.yml index ac39d517..1404f384 100644 --- a/assets/3-links/3-links-config-1.yml +++ b/tests/resources/3-links/3-links-config-1.yml @@ -1,10 +1,10 @@ modules: protofiles: type: ProtoFiles - network: ./assets/3-links/3-links-network.binpb - population: ./assets/3-links/1-agent-full-leg.binpb - vehicles: ./assets/3-links/vehicles.binpb - ids: ./assets/3-links/ids.binpb + network: ./tests/resources/3-links/3-links-network.binpb + population: ./tests/resources/3-links/1-agent-full-leg.binpb + vehicles: ./tests/resources/3-links/vehicles.binpb + ids: ./tests/resources/3-links/ids.binpb partitioning: type: Partitioning num_parts: 1 diff --git a/assets/3-links/3-links-config-2.yml b/tests/resources/3-links/3-links-config-2.yml similarity index 60% rename from assets/3-links/3-links-config-2.yml rename to tests/resources/3-links/3-links-config-2.yml index eba3ce8a..dd803ebe 100644 --- a/assets/3-links/3-links-config-2.yml +++ b/tests/resources/3-links/3-links-config-2.yml @@ -1,10 +1,10 @@ modules: protofiles: type: ProtoFiles - network: ./assets/3-links/3-links-network.binpb - population: ./assets/3-links/1-agent-full-leg.binpb - vehicles: ./assets/3-links/vehicles.binpb - ids: ./assets/3-links/ids.binpb + network: ./tests/resources/3-links/3-links-network.binpb + population: ./tests/resources/3-links/1-agent-full-leg.binpb + vehicles: ./tests/resources/3-links/vehicles.binpb + ids: ./tests/resources/3-links/ids.binpb partitioning: type: Partitioning num_parts: 2 diff --git a/assets/3-links/3-links-network.binpb b/tests/resources/3-links/3-links-network.binpb similarity index 100% rename from assets/3-links/3-links-network.binpb rename to tests/resources/3-links/3-links-network.binpb diff --git a/tests/resources/3-links/expected_events.xml b/tests/resources/3-links/expected_events.xml new file mode 100644 index 00000000..ee54a5de --- /dev/null +++ b/tests/resources/3-links/expected_events.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/assets/3-links/ids.binpb b/tests/resources/3-links/ids.binpb similarity index 100% rename from assets/3-links/ids.binpb rename to tests/resources/3-links/ids.binpb diff --git a/assets/3-links/vehicles.binpb b/tests/resources/3-links/vehicles.binpb similarity index 100% rename from assets/3-links/vehicles.binpb rename to tests/resources/3-links/vehicles.binpb diff --git a/assets/adhoc_routing/no_updates/agents.binpb b/tests/resources/adhoc_routing/no_updates/agents.binpb similarity index 100% rename from assets/adhoc_routing/no_updates/agents.binpb rename to tests/resources/adhoc_routing/no_updates/agents.binpb diff --git a/assets/adhoc_routing/no_updates/config-1.yml b/tests/resources/adhoc_routing/no_updates/config-1.yml similarity index 56% rename from assets/adhoc_routing/no_updates/config-1.yml rename to tests/resources/adhoc_routing/no_updates/config-1.yml index 8b2a48cb..22fcecf3 100644 --- a/assets/adhoc_routing/no_updates/config-1.yml +++ b/tests/resources/adhoc_routing/no_updates/config-1.yml @@ -1,10 +1,10 @@ modules: protofiles: type: ProtoFiles - network: ./assets/adhoc_routing/no_updates/network.binpb - population: ./assets/adhoc_routing/no_updates/agents.binpb - vehicles: ./assets/adhoc_routing/no_updates/vehicles.binpb - ids: ./assets/adhoc_routing/no_updates/ids.binpb + network: ./tests/resources/adhoc_routing/no_updates/network.binpb + population: ./tests/resources/adhoc_routing/no_updates/agents.binpb + vehicles: ./tests/resources/adhoc_routing/no_updates/vehicles.binpb + ids: ./tests/resources/adhoc_routing/no_updates/ids.binpb partitioning: type: Partitioning num_parts: 1 diff --git a/assets/adhoc_routing/no_updates/config-2.yml b/tests/resources/adhoc_routing/no_updates/config-2.yml similarity index 56% rename from assets/adhoc_routing/no_updates/config-2.yml rename to tests/resources/adhoc_routing/no_updates/config-2.yml index 686908f0..16fe8e8d 100644 --- a/assets/adhoc_routing/no_updates/config-2.yml +++ b/tests/resources/adhoc_routing/no_updates/config-2.yml @@ -1,10 +1,10 @@ modules: protofiles: type: ProtoFiles - network: ./assets/adhoc_routing/no_updates/network.binpb - population: ./assets/adhoc_routing/no_updates/agents.binpb - vehicles: ./assets/adhoc_routing/no_updates/vehicles.binpb - ids: ./assets/adhoc_routing/no_updates/ids.binpb + network: ./tests/resources/adhoc_routing/no_updates/network.binpb + population: ./tests/resources/adhoc_routing/no_updates/agents.binpb + vehicles: ./tests/resources/adhoc_routing/no_updates/vehicles.binpb + ids: ./tests/resources/adhoc_routing/no_updates/ids.binpb partitioning: type: Partitioning num_parts: 2 diff --git a/assets/adhoc_routing/no_updates/expected_events.xml b/tests/resources/adhoc_routing/no_updates/expected_events.xml similarity index 100% rename from assets/adhoc_routing/no_updates/expected_events.xml rename to tests/resources/adhoc_routing/no_updates/expected_events.xml diff --git a/assets/adhoc_routing/no_updates/ids.binpb b/tests/resources/adhoc_routing/no_updates/ids.binpb similarity index 100% rename from assets/adhoc_routing/no_updates/ids.binpb rename to tests/resources/adhoc_routing/no_updates/ids.binpb diff --git a/assets/adhoc_routing/no_updates/network.binpb b/tests/resources/adhoc_routing/no_updates/network.binpb similarity index 100% rename from assets/adhoc_routing/no_updates/network.binpb rename to tests/resources/adhoc_routing/no_updates/network.binpb diff --git a/tests/resources/adhoc_routing/no_updates/output_events.xml b/tests/resources/adhoc_routing/no_updates/output_events.xml deleted file mode 100644 index 982e28d8..00000000 --- a/tests/resources/adhoc_routing/no_updates/output_events.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/assets/adhoc_routing/no_updates/vehicles.binpb b/tests/resources/adhoc_routing/no_updates/vehicles.binpb similarity index 100% rename from assets/adhoc_routing/no_updates/vehicles.binpb rename to tests/resources/adhoc_routing/no_updates/vehicles.binpb diff --git a/assets/adhoc_routing/with_updates/agents.binpb b/tests/resources/adhoc_routing/with_updates/agents.binpb similarity index 100% rename from assets/adhoc_routing/with_updates/agents.binpb rename to tests/resources/adhoc_routing/with_updates/agents.binpb diff --git a/assets/adhoc_routing/with_updates/config-1.yml b/tests/resources/adhoc_routing/with_updates/config-1.yml similarity index 56% rename from assets/adhoc_routing/with_updates/config-1.yml rename to tests/resources/adhoc_routing/with_updates/config-1.yml index 9531e111..c315fb9b 100644 --- a/assets/adhoc_routing/with_updates/config-1.yml +++ b/tests/resources/adhoc_routing/with_updates/config-1.yml @@ -1,10 +1,10 @@ modules: protofiles: type: ProtoFiles - network: ./assets/adhoc_routing/with_updates/network.binpb - population: ./assets/adhoc_routing/with_updates/agents.binpb - vehicles: ./assets/adhoc_routing/with_updates/vehicles.binpb - ids: ./assets/adhoc_routing/with_updates/ids.binpb + network: ./tests/resources/adhoc_routing/with_updates/network.binpb + population: ./tests/resources/adhoc_routing/with_updates/agents.binpb + vehicles: ./tests/resources/adhoc_routing/with_updates/vehicles.binpb + ids: ./tests/resources/adhoc_routing/with_updates/ids.binpb partitioning: type: Partitioning num_parts: 1 diff --git a/assets/adhoc_routing/with_updates/config-2.yml b/tests/resources/adhoc_routing/with_updates/config-2.yml similarity index 56% rename from assets/adhoc_routing/with_updates/config-2.yml rename to tests/resources/adhoc_routing/with_updates/config-2.yml index ec9b80a9..475dec5c 100644 --- a/assets/adhoc_routing/with_updates/config-2.yml +++ b/tests/resources/adhoc_routing/with_updates/config-2.yml @@ -1,10 +1,10 @@ modules: protofiles: type: ProtoFiles - network: ./assets/adhoc_routing/with_updates/network.binpb - population: ./assets/adhoc_routing/with_updates/agents.binpb - vehicles: ./assets/adhoc_routing/with_updates/vehicles.binpb - ids: ./assets/adhoc_routing/with_updates/ids.binpb + network: ./tests/resources/adhoc_routing/with_updates/network.binpb + population: ./tests/resources/adhoc_routing/with_updates/agents.binpb + vehicles: ./tests/resources/adhoc_routing/with_updates/vehicles.binpb + ids: ./tests/resources/adhoc_routing/with_updates/ids.binpb partitioning: type: Partitioning num_parts: 1 diff --git a/assets/adhoc_routing/with_updates/expected_events.xml b/tests/resources/adhoc_routing/with_updates/expected_events.xml similarity index 100% rename from assets/adhoc_routing/with_updates/expected_events.xml rename to tests/resources/adhoc_routing/with_updates/expected_events.xml diff --git a/assets/adhoc_routing/with_updates/ids.binpb b/tests/resources/adhoc_routing/with_updates/ids.binpb similarity index 100% rename from assets/adhoc_routing/with_updates/ids.binpb rename to tests/resources/adhoc_routing/with_updates/ids.binpb diff --git a/assets/adhoc_routing/with_updates/network.binpb b/tests/resources/adhoc_routing/with_updates/network.binpb similarity index 100% rename from assets/adhoc_routing/with_updates/network.binpb rename to tests/resources/adhoc_routing/with_updates/network.binpb diff --git a/tests/resources/adhoc_routing/with_updates/output_events.xml b/tests/resources/adhoc_routing/with_updates/output_events.xml deleted file mode 100644 index 5d80910a..00000000 --- a/tests/resources/adhoc_routing/with_updates/output_events.xml +++ /dev/null @@ -1,147 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/assets/adhoc_routing/with_updates/vehicles.binpb b/tests/resources/adhoc_routing/with_updates/vehicles.binpb similarity index 100% rename from assets/adhoc_routing/with_updates/vehicles.binpb rename to tests/resources/adhoc_routing/with_updates/vehicles.binpb diff --git a/tests/resources/equil/output_events.xml b/tests/resources/equil/output_events.xml deleted file mode 100644 index f04c7c57..00000000 --- a/tests/resources/equil/output_events.xml +++ /dev/null @@ -1,2609 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/tests/resources/three_link/full_legs/output_events.xml b/tests/resources/three_link/full_legs/output_events.xml deleted file mode 100644 index 00239b29..00000000 --- a/tests/resources/three_link/full_legs/output_events.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/tests/resources/three_link/multiple_agents/no_jam/output_events.xml b/tests/resources/three_link/multiple_agents/no_jam/output_events.xml deleted file mode 100644 index 937b7584..00000000 --- a/tests/resources/three_link/multiple_agents/no_jam/output_events.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/tests/resources/three_link/multiple_agents/with_jam/output_events.xml b/tests/resources/three_link/multiple_agents/with_jam/output_events.xml deleted file mode 100644 index 6be8d112..00000000 --- a/tests/resources/three_link/multiple_agents/with_jam/output_events.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/tests/resources/three_link/output_events.xml b/tests/resources/three_link/output_events.xml deleted file mode 100644 index b4778b6e..00000000 --- a/tests/resources/three_link/output_events.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/tests/test_3_links.rs b/tests/test_3_links.rs new file mode 100644 index 00000000..2b84be10 --- /dev/null +++ b/tests/test_3_links.rs @@ -0,0 +1,31 @@ +use crate::test_simulation::{execute_sim, execute_sim_with_channels, TestSubscriber}; +use rust_q_sim::simulation::config::CommandLineArgs; +use rust_q_sim::simulation::messaging::communication::communicators::DummySimCommunicator; + +mod test_simulation; + +#[test] +fn execute_3_links_single_part() { + let config_args = CommandLineArgs { + config_path: "./tests/resources/3-links/3-links-config-1.yml".to_string(), + num_parts: None, + }; + + execute_sim( + DummySimCommunicator(), + Box::new(TestSubscriber::new_with_events_from_file( + "./tests/resources/3-links/expected_events.xml", + )), + config_args, + ); +} + +#[test] +fn execute_3_links_2_parts() { + let config_args = CommandLineArgs { + config_path: "./tests/resources/3-links/3-links-config-2.yml".to_string(), + num_parts: None, + }; + + execute_sim_with_channels(config_args, "./tests/resources/3-links/expected_events.xml"); +} diff --git a/tests/test_adhoc_routing.rs b/tests/test_adhoc_routing.rs new file mode 100644 index 00000000..d2197da5 --- /dev/null +++ b/tests/test_adhoc_routing.rs @@ -0,0 +1,63 @@ +use crate::test_simulation::{execute_sim, execute_sim_with_channels, TestSubscriber}; +use rust_q_sim::simulation::config::CommandLineArgs; +use rust_q_sim::simulation::messaging::communication::communicators::DummySimCommunicator; + +mod test_simulation; + +#[test] +fn execute_adhoc_routing_one_part_no_updates() { + let config_args = CommandLineArgs { + config_path: "./tests/resources/adhoc_routing/no_updates/config-1.yml".to_string(), + num_parts: None, + }; + + execute_sim( + DummySimCommunicator(), + Box::new(TestSubscriber::new_with_events_from_file( + "./tests/resources/adhoc_routing/no_updates/expected_events.xml", + )), + config_args, + ); +} + +#[test] +fn execute_adhoc_routing_two_parts_no_updates() { + let config_args = CommandLineArgs { + config_path: "./tests/resources/adhoc_routing/no_updates/config-2.yml".to_string(), + num_parts: None, + }; + + execute_sim_with_channels( + config_args, + "./tests/resources/adhoc_routing/no_updates/expected_events.xml", + ); +} + +#[test] +fn execute_adhoc_routing_one_part_with_updates() { + let config_args = CommandLineArgs { + config_path: "./tests/resources/adhoc_routing/with_updates/config-1.yml".to_string(), + num_parts: None, + }; + + execute_sim( + DummySimCommunicator(), + Box::new(TestSubscriber::new_with_events_from_file( + "./tests/resources/adhoc_routing/with_updates/expected_events.xml", + )), + config_args, + ); +} + +#[test] +fn execute_adhoc_routing_two_parts_with_updates() { + let config_args = CommandLineArgs { + config_path: "./tests/resources/adhoc_routing/with_updates/config-2.yml".to_string(), + num_parts: None, + }; + + execute_sim_with_channels( + config_args, + "./tests/resources/adhoc_routing/with_updates/expected_events.xml", + ); +} diff --git a/tests/test_simulation.rs b/tests/test_simulation.rs index 54209620..1fc971a1 100644 --- a/tests/test_simulation.rs +++ b/tests/test_simulation.rs @@ -12,9 +12,10 @@ use tracing::info; use rust_q_sim::simulation::config::{CommandLineArgs, Config, RoutingMode}; use rust_q_sim::simulation::controller::{get_numbered_output_filename, partition_input}; +use rust_q_sim::simulation::id; use rust_q_sim::simulation::io::xml_events::XmlEventsWriter; use rust_q_sim::simulation::messaging::communication::communicators::{ - ChannelSimCommunicator, DummySimCommunicator, SimCommunicator, + ChannelSimCommunicator, SimCommunicator, }; use rust_q_sim::simulation::messaging::communication::message_broker::NetMessageBroker; use rust_q_sim::simulation::messaging::events::{EventsPublisher, EventsSubscriber}; @@ -28,91 +29,8 @@ use rust_q_sim::simulation::replanning::routing::travel_time_collector::TravelTi use rust_q_sim::simulation::simulation::Simulation; use rust_q_sim::simulation::vehicles::garage::Garage; use rust_q_sim::simulation::wire_types::events::Event; -use rust_q_sim::simulation::{id, logging}; -#[test] -fn execute_3_links_single_part() { - let config_args = CommandLineArgs { - config_path: "./assets/3-links/3-links-config-1.yml".to_string(), - num_parts: None, - }; - - execute_sim( - DummySimCommunicator(), - Box::new(TestSubscriber::new()), - config_args, - ); -} - -#[test] -fn execute_3_links_2_parts() { - let config_args = CommandLineArgs { - config_path: "./assets/3-links/3-links-config-2.yml".to_string(), - num_parts: None, - }; - - execute_sim_with_channels(config_args, ""); -} - -#[test] -fn execute_adhoc_routing_one_part_no_updates() { - let config_args = CommandLineArgs { - config_path: "./assets/adhoc_routing/no_updates/config-1.yml".to_string(), - num_parts: None, - }; - - execute_sim( - DummySimCommunicator(), - Box::new(TestSubscriber::new_with_events_from_file( - "./assets/adhoc_routing/no_updates/expected_events.xml", - )), - config_args, - ); -} - -#[test] -fn execute_adhoc_routing_two_parts_no_updates() { - let config_args = CommandLineArgs { - config_path: "./assets/adhoc_routing/no_updates/config-2.yml".to_string(), - num_parts: None, - }; - - execute_sim_with_channels( - config_args, - "./assets/adhoc_routing/no_updates/expected_events.xml", - ); -} - -#[test] -fn execute_adhoc_routing_one_part_with_updates() { - let config_args = CommandLineArgs { - config_path: "./assets/adhoc_routing/with_updates/config-1.yml".to_string(), - num_parts: None, - }; - - execute_sim( - DummySimCommunicator(), - Box::new(TestSubscriber::new_with_events_from_file( - "./assets/adhoc_routing/with_updates/expected_events.xml", - )), - config_args, - ); -} - -#[test] -fn execute_adhoc_routing_two_parts_with_updates() { - let config_args = CommandLineArgs { - config_path: "./assets/adhoc_routing/with_updates/config-2.yml".to_string(), - num_parts: None, - }; - - execute_sim_with_channels( - config_args, - "./assets/adhoc_routing/with_updates/expected_events.xml", - ); -} - -fn execute_sim_with_channels(config_args: CommandLineArgs, expected_events: &str) { +pub fn execute_sim_with_channels(config_args: CommandLineArgs, expected_events: &str) { let config = Config::from_file(&config_args); let comms = ChannelSimCommunicator::create_n_2_n(config.partitioning().num_parts); let mut receiver = ReceivingSubscriber::new_with_events_from_file(&expected_events); @@ -139,7 +57,7 @@ fn execute_sim_with_channels(config_args: CommandLineArgs, expected_events: &str try_join(handles); } -fn execute_sim( +pub fn execute_sim( comm: C, test_subscriber: Box, config_args: CommandLineArgs, @@ -176,13 +94,6 @@ fn execute_sim( } } - if rank == 0 { - let _guards = logging::init_logging( - config.output().output_dir.as_ref(), - config.partitioning().num_parts.to_string().as_str(), - ); - } - let network = Network::from_file_as_is(&temp_network_file); let mut garage = Garage::from_file(&PathBuf::from(config.proto_files().vehicles)); @@ -251,7 +162,7 @@ impl EventsSubscriber for EmptySubscriber { } } -struct TestSubscriber { +pub struct TestSubscriber { next_index: usize, expected_events: Vec, } @@ -301,14 +212,7 @@ impl ReceivingSubscriber { } impl TestSubscriber { - fn new() -> Self { - Self { - next_index: 0, - expected_events: Self::expected_events(), - } - } - - fn new_with_events_from_file(events_file: &str) -> Self { + pub fn new_with_events_from_file(events_file: &str) -> Self { Self { next_index: 0, expected_events: Self::expected_events_from_file(events_file), @@ -331,33 +235,6 @@ impl TestSubscriber { .map(|s| s + "\n") .collect() } - - fn expected_events() -> Vec { - let result = vec![ - "\n".to_string(), - "\n".to_string(), - "\n".to_string(), - "\n".to_string(), - "\n".to_string(), - "\n".to_string(), - "\n".to_string(), - "\n".to_string(), - "\n".to_string(), - "\n".to_string(), - "\n".to_string(), - "\n".to_string(), - "\n".to_string(), - "\n".to_string(), - "\n".to_string(), - "\n".to_string(), - "\n".to_string(), - "\n".to_string(), - "\n".to_string(), - "\n".to_string() - ]; - - result - } } impl TestSubscriber { diff --git a/tests/three_link_it.rs b/tests/three_link_it.rs deleted file mode 100644 index 510022c2..00000000 --- a/tests/three_link_it.rs +++ /dev/null @@ -1,115 +0,0 @@ -use serial_test::serial; - -use crate::event_test_utils::{compare_events, run_mpi_simulation_and_convert_events}; - -mod event_test_utils; - -#[test] -#[serial] -#[ignore] -/// Network: 3 links in a line. -/// Agents: 1 agent travelling line. -/// Route: Given. Plan also includes walking legs and car interactions. -fn test_three_link_default() { - test_three_link( - "assets/3-links/1-agent.xml", - None, - "static", - "tests/resources/three_link", - ) -} - -#[test] -#[serial] -#[ignore] -/// Network: 3 links in a line. -/// Agents: 1 agent travelling line. -/// Route: Will be calculated during qsim. There are legs in plans file which will be discarded. -fn test_three_link_full_legs_in_plans() { - test_three_link( - "assets/3-links/1-agent-full-leg.xml", - None, - "static/full_legs", - "tests/resources/three_link/full_legs", - ) -} - -#[test] -#[serial] -#[ignore] -/// Network: 3 links in a line. -/// Agents: 1 agent travelling line. -/// Route: Will be computed during qsim. There are main legs in plans file. -fn test_three_link_with_routing_legs_in_plans() { - test_three_link( - "assets/3-links/1-agent.xml", - None, - "adhoc/with_legs", - "tests/resources/three_link/full_legs", - ) -} - -#[test] -#[serial] -#[ignore] -/// Network: 3 links in a line. -/// Agents: 1 agent travelling line. -/// Route: Given. -/// Vehicle definitions: Given. Everything should be like simple test case without routing. -fn test_three_link_one_agent_with_vehicle_definitions() { - test_three_link( - "assets/3-links/1-agent.xml", - Some("assets/3-links/vehicles.xml"), - "static/vehicle_definitions", - "tests/resources/three_link", - ) -} - -#[test] -#[serial] -#[ignore] -/// Network: 3 links in a line. -/// Agents: 3 agents travelling line. Order: car -> bike -> car. There is enough time between agents, thus no jam. -/// Route: Given. -/// Vehicle definitions: Given. Bike travel time is longer than car. -fn test_three_link_multiple_agents_with_vehicle_definitions() { - test_three_link( - "assets/3-links/3-agent.xml", - Some("assets/3-links/vehicles.xml"), - "static/multiple_agents/no_jam", - "tests/resources/three_link/multiple_agents/no_jam", - ) -} - -#[test] -#[serial] -#[ignore] -/// Network: 3 links in a line. -/// Agents: 3 agents travelling line. car -> car -> bike. There is jam due to the bike. -/// Route: Given. -/// Vehicle definitions: Given. Bike travel time is longer than car. Car -fn test_three_link_multiple_agents_with_jam_by_vehicle_definitions() { - test_three_link( - "assets/3-links/3-agent_jam.xml", - Some("assets/3-links/vehicles.xml"), - "static/multiple_agents/with_jam", - "tests/resources/three_link/multiple_agents/with_jam", - ) -} - -fn test_three_link( - plans_file: &str, - vehicle_definitions_file: Option<&str>, - output_dir: &str, - expected_events_dir: &str, -) { - let output_dir = format!("test_output/mpi_test/three_link/{}/", output_dir); - run_mpi_simulation_and_convert_events( - 1, - "assets/3-links/3-links-network.xml", - plans_file, - output_dir.as_str(), - vehicle_definitions_file, - ); - compare_events(output_dir.as_str(), expected_events_dir) -}