Skip to content

Commit

Permalink
moved test cases
Browse files Browse the repository at this point in the history
paulheinr committed Dec 18, 2023
1 parent 6324ed5 commit a25bd75
Showing 36 changed files with 147 additions and 3,430 deletions.
Binary file removed assets/adhoc_routing/no_updates/expected_events.pbf
Binary file not shown.
Binary file not shown.
38 changes: 0 additions & 38 deletions tests/equil_it.rs

This file was deleted.

197 changes: 0 additions & 197 deletions tests/event_test_utils.rs

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
23 changes: 23 additions & 0 deletions tests/resources/3-links/expected_events.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<events version="1.0">
<event time="32400" type="actend" person="100" link="link1" actType="home" />
<event time="32400" type="departure" person="100" link="link1" legMode="walk" />
<event time="32408" type="travelled" person="100" distance="10" mode="walk" />
<event time="32408" type="arrival" person="100" link="link1" legMode="walk" />
<event time="32408" type="actstart" person="100" link="link1" actType="car interaction" />
<event time="32409" type="actend" person="100" link="link1" actType="car interaction" />
<event time="32409" type="departure" person="100" link="link1" legMode="car" />
<event time="32409" type="PersonEntersVehicle" person="100" vehicle="100_car" />
<event time="32419" type="left link" link="link1" vehicle="100_car" />
<event time="32419" type="entered link" link="link2" vehicle="100_car" />
<event time="32519" type="left link" link="link2" vehicle="100_car" />
<event time="32519" type="entered link" link="link3" vehicle="100_car" />
<event time="32529" type="PersonLeavesVehicle" person="100" vehicle="100_car" />
<event time="32529" type="arrival" person="100" link="link3" legMode="car" />
<event time="32529" type="actstart" person="100" link="link3" actType="car interaction" />
<event time="32530" type="actend" person="100" link="link3" actType="car interaction" />
<event time="32530" type="departure" person="100" link="link3" legMode="walk" />
<event time="32546" type="travelled" person="100" distance="20" mode="walk" />
<event time="32546" type="arrival" person="100" link="link3" legMode="walk" />
<event time="32546" type="actstart" person="100" link="link3" actType="errands" />
</events>
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
73 changes: 0 additions & 73 deletions tests/resources/adhoc_routing/no_updates/output_events.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
147 changes: 0 additions & 147 deletions tests/resources/adhoc_routing/with_updates/output_events.xml

This file was deleted.

2,609 changes: 0 additions & 2,609 deletions tests/resources/equil/output_events.xml

This file was deleted.

19 changes: 0 additions & 19 deletions tests/resources/three_link/full_legs/output_events.xml

This file was deleted.

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions tests/resources/three_link/output_events.xml

This file was deleted.

31 changes: 31 additions & 0 deletions tests/test_3_links.rs
Original file line number Diff line number Diff line change
@@ -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");
}
63 changes: 63 additions & 0 deletions tests/test_adhoc_routing.rs
Original file line number Diff line number Diff line change
@@ -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",
);
}
135 changes: 6 additions & 129 deletions tests/test_simulation.rs
Original file line number Diff line number Diff line change
@@ -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<C: SimCommunicator + 'static>(
pub fn execute_sim<C: SimCommunicator + 'static>(
comm: C,
test_subscriber: Box<dyn EventsSubscriber + Send>,
config_args: CommandLineArgs,
@@ -176,13 +94,6 @@ fn execute_sim<C: SimCommunicator + 'static>(
}
}

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<String>,
}
@@ -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<String> {
let result = vec![
"<event time=\"32400\" type=\"actend\" person=\"100\" link=\"link1\" actType=\"home\" />\n".to_string(),
"<event time=\"32400\" type=\"departure\" person=\"100\" link=\"link1\" legMode=\"walk\" />\n".to_string(),
"<event time=\"32408\" type=\"travelled\" person=\"100\" distance=\"10\" mode=\"walk\" />\n".to_string(),
"<event time=\"32408\" type=\"arrival\" person=\"100\" link=\"link1\" legMode=\"walk\" />\n".to_string(),
"<event time=\"32408\" type=\"actstart\" person=\"100\" link=\"link1\" actType=\"car interaction\" />\n".to_string(),
"<event time=\"32409\" type=\"actend\" person=\"100\" link=\"link1\" actType=\"car interaction\" />\n".to_string(),
"<event time=\"32409\" type=\"departure\" person=\"100\" link=\"link1\" legMode=\"car\" />\n".to_string(),
"<event time=\"32409\" type=\"PersonEntersVehicle\" person=\"100\" vehicle=\"100_car\" />\n".to_string(),
"<event time=\"32419\" type=\"left link\" link=\"link1\" vehicle=\"100_car\" />\n".to_string(),
"<event time=\"32419\" type=\"entered link\" link=\"link2\" vehicle=\"100_car\" />\n".to_string(),
"<event time=\"32519\" type=\"left link\" link=\"link2\" vehicle=\"100_car\" />\n".to_string(),
"<event time=\"32519\" type=\"entered link\" link=\"link3\" vehicle=\"100_car\" />\n".to_string(),
"<event time=\"32529\" type=\"PersonLeavesVehicle\" person=\"100\" vehicle=\"100_car\" />\n".to_string(),
"<event time=\"32529\" type=\"arrival\" person=\"100\" link=\"link3\" legMode=\"car\" />\n".to_string(),
"<event time=\"32529\" type=\"actstart\" person=\"100\" link=\"link3\" actType=\"car interaction\" />\n".to_string(),
"<event time=\"32530\" type=\"actend\" person=\"100\" link=\"link3\" actType=\"car interaction\" />\n".to_string(),
"<event time=\"32530\" type=\"departure\" person=\"100\" link=\"link3\" legMode=\"walk\" />\n".to_string(),
"<event time=\"32546\" type=\"travelled\" person=\"100\" distance=\"20\" mode=\"walk\" />\n".to_string(),
"<event time=\"32546\" type=\"arrival\" person=\"100\" link=\"link3\" legMode=\"walk\" />\n".to_string(),
"<event time=\"32546\" type=\"actstart\" person=\"100\" link=\"link3\" actType=\"errands\" />\n".to_string()
];

result
}
}

impl TestSubscriber {
115 changes: 0 additions & 115 deletions tests/three_link_it.rs

This file was deleted.

0 comments on commit a25bd75

Please sign in to comment.