use super::*;
fn b(pairs: &[(&str, f64)]) -> BTreeMap<Instrument, Price> {
pairs.iter().map(|&(k, v)| (k.into(), v)).collect()
}
fn expected_book_states() -> Vec<BTreeMap<Instrument, Price>> {
vec![
b(&[("inst1", 101.0)]), b(&[("inst1", 101.0), ("inst2", 202.0)]), b(&[("inst2", 204.0)]), b(&[("inst2", 204.0), ("inst3", 305.0)]), b(&[("inst3", 305.0), ("inst4", 406.0)]), b(&[("inst3", 307.0), ("inst4", 406.0)]), b(&[("inst3", 307.0), ("inst4", 408.0)]), b(&[("inst4", 408.0), ("inst5", 509.0)]), b(&[("inst4", 410.0), ("inst5", 509.0)]), b(&[("inst4", 410.0), ("inst5", 511.0)]), b(&[("inst5", 511.0), ("inst6", 612.0)]), b(&[("inst5", 513.0), ("inst6", 612.0)]), b(&[("inst5", 513.0), ("inst6", 614.0)]), b(&[("inst6", 614.0), ("inst7", 715.0)]), b(&[("inst6", 616.0), ("inst7", 715.0)]), b(&[("inst6", 616.0), ("inst7", 717.0)]), b(&[("inst7", 717.0), ("inst8", 818.0)]), b(&[("inst7", 719.0), ("inst8", 818.0)]), b(&[("inst7", 719.0), ("inst8", 820.0)]), ]
}
#[test]
fn price_book_accumulation() {
let period = std::time::Duration::from_secs(1);
let (price_book, overflow_node) = build(period);
let assertion = price_book.accumulate().finally(|states, _| {
assert_eq!(states, expected_book_states());
Ok(())
});
Graph::new(
vec![assertion, overflow_node],
RunMode::HistoricalFrom(NanoTime::ZERO),
RunFor::Duration(period * 19),
)
.run()
.unwrap();
}