Skip to content

Instantly share code, notes, and snippets.

@jayhuang75
Last active December 12, 2022 14:22
Show Gist options
  • Save jayhuang75/7b5528734476f4bdf88eed7658fdbb64 to your computer and use it in GitHub Desktop.
Save jayhuang75/7b5528734476f4bdf88eed7658fdbb64 to your computer and use it in GitHub Desktop.
mediator_unit_test.rs
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new_aircraft() {
let ac312 = PassengerAircraft::new("ac312_toronto_newyork_1700");
assert_eq!(ac312.id(), "ac312_toronto_newyork_1700");
}
#[test]
fn test_new_airport() {
let yyz = Airport::new("YYZ", 2);
assert_eq!(yyz.name, "YYZ");
assert_eq!(yyz.gates.len(), 2);
assert_eq!(yyz.gates[&1], true);
}
#[test]
#[should_panic]
fn test_new_airport_panic() {
let _ = Airport::new("yul", 0);
}
#[test]
fn test_new_airport_impl() {
let mut yyz = Airport::new("YYZ", 2);
let ac312_key = "ac312_newyork_toronto_1700";
let ac313_key = "ac313_boston_toronto_1700";
let ac314_key = "ac314_montreal_toronto_1800";
let ac315_key = "ac315_vancover_toronto_1740";
let ac316_key = "ac316_shanghai_toronto_1810";
let ac312 = PassengerAircraft::new(ac312_key);
let ac313 = PassengerAircraft::new(ac313_key);
let ac314 = PassengerAircraft::new(ac314_key);
let ac315 = PassengerAircraft::new(ac315_key);
let ac316 = PassengerAircraft::new(ac316_key);
yyz.land(ac312);
yyz.land(ac313);
yyz.land(ac314);
yyz.land(ac315);
yyz.land(ac316);
if let Some(queue) = yyz.aircraft_queue(){
assert_eq!(queue[0], ac314_key);
}
// println!("aircraft queue {:?}", yyz.aircraft_queue);
yyz.depart(ac312_key);
yyz.depart(ac313_key);
// println!("{:?}", yyz.dashboard());
for (gate_id, aircraft_id) in yyz.aircraft_on_gate {
println!("aircraft [{:?}] at gate [{:?}]", aircraft_id, gate_id);
}
for (gate_id, available) in yyz.gates {
println!("gate [{:?}] is it available [{:?}]", gate_id, available);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment