use super::RoutedProbe;
use crate::LaneIdent;
#[test]
fn a_probe_states_its_lane_and_what_it_asks_with() {
let probe = RoutedProbe::new(LaneIdent::new("zh"), "世界");
assert_eq!(probe.lane(), LaneIdent::new("zh"));
assert_eq!(probe.probe(), &"世界");
}
#[test]
fn both_seats_carry_the_consuming_and_the_in_place_forms() {
let probe = RoutedProbe::new(LaneIdent::new("zh"), "世界".to_owned());
let moved = probe.clone().with_lane(LaneIdent::new("ja"));
assert_eq!(moved.lane(), LaneIdent::new("ja"));
assert_eq!(moved.probe(), "世界");
let rewritten = probe.clone().with_probe("せかい".to_owned());
assert_eq!(rewritten.lane(), LaneIdent::new("zh"));
assert_eq!(rewritten.probe(), "せかい");
let mut held = probe.clone();
held
.set_lane(LaneIdent::new("ja"))
.set_probe("せかい".to_owned());
assert_eq!(held, moved.with_probe("せかい".to_owned()));
}
#[test]
fn a_probe_comes_apart_into_its_two_seats() {
let probe = RoutedProbe::new(LaneIdent::new("en"), "hello".to_owned());
assert_eq!(probe.clone().into_probe(), "hello");
assert_eq!(
probe.into_components(),
(LaneIdent::new("en"), "hello".to_owned(), 1.0)
);
}
#[test]
fn mapping_the_probe_leaves_the_lane_alone() {
let text = RoutedProbe::new(LaneIdent::new("zh"), "世界".to_owned());
let counted = text.map_probe(|probe| probe.chars().count());
assert_eq!(counted.lane(), LaneIdent::new("zh"));
assert_eq!(counted.probe(), &2);
}
#[test]
fn a_probe_is_unweighted_unless_a_router_says_otherwise() {
let probe = RoutedProbe::new(LaneIdent::new("en"), "hello");
assert_eq!(probe.weight(), 1.0);
assert_eq!(probe.weight(), RoutedProbe::<&str>::UNWEIGHTED);
}
#[test]
fn the_weight_carries_the_consuming_and_the_in_place_forms() {
let probe = RoutedProbe::new(LaneIdent::new("en"), "hello".to_owned());
let leaned = probe.clone().with_weight(2.0);
assert_eq!(leaned.weight(), 2.0);
assert_eq!(leaned.lane(), LaneIdent::new("en"));
assert_eq!(leaned.probe(), "hello");
let mut held = probe;
held.set_weight(0.5);
assert_eq!(held.weight(), 0.5);
}
#[test]
fn a_probe_comes_apart_into_all_three_seats() {
let probe = RoutedProbe::new(LaneIdent::new("ja"), "せかい".to_owned()).with_weight(2.0);
assert_eq!(
probe.into_components(),
(LaneIdent::new("ja"), "せかい".to_owned(), 2.0)
);
}
#[test]
fn mapping_the_probe_keeps_the_weight() {
let text = RoutedProbe::new(LaneIdent::new("zh"), "世界".to_owned()).with_weight(2.5);
let counted = text.map_probe(|probe| probe.chars().count());
assert_eq!(counted.lane(), LaneIdent::new("zh"));
assert_eq!(counted.probe(), &2);
assert_eq!(counted.weight(), 2.5, "the weight survives the crossing");
}