From c51702207b8eca0656924529613ae9c2e5d018c8 Mon Sep 17 00:00:00 2001 From: Morten Haahr Kristensen Date: Mon, 9 Dec 2024 10:51:13 +0100 Subject: [PATCH] Fixed constraint tests after OutputHandler --- tests/constraint_based_lola.rs | 66 +++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/tests/constraint_based_lola.rs b/tests/constraint_based_lola.rs index 86dd2ba..3e1d0c3 100644 --- a/tests/constraint_based_lola.rs +++ b/tests/constraint_based_lola.rs @@ -3,7 +3,7 @@ use futures::stream::StreamExt; use std::collections::BTreeMap; use trustworthiness_checker::constraint_based_runtime::ConstraintBasedMonitor; -use trustworthiness_checker::lola_specification; +use trustworthiness_checker::{lola_specification, LOLASpecification}; use trustworthiness_checker::manual_output_handler::ManualOutputHandler; use trustworthiness_checker::{Monitor, Value, VarName}; mod lola_fixtures; @@ -29,11 +29,15 @@ pub fn input_streams1() -> BTreeMap> { input_streams } +fn output_handler(spec: LOLASpecification) -> ManualOutputHandler{ + ManualOutputHandler::new(spec.output_vars.clone()) +} + #[tokio::test] async fn test_simple_add_monitor() { let mut input_streams = input_streams1(); let spec = lola_specification(&mut spec_simple_add_monitor()).unwrap(); - let mut output_handler = ManualOutputHandler::new(spec.output_vars.clone()); + let mut output_handler = output_handler(spec.clone()); let outputs = output_handler.get_output(); let monitor = ConstraintBasedMonitor::new(spec, &mut input_streams, output_handler); tokio::spawn(monitor.run()); @@ -68,7 +72,7 @@ async fn test_simple_add_monitor() { async fn test_runtime_initialization() { let mut input_streams = input_empty(); let spec = lola_specification(&mut spec_empty()).unwrap(); - let mut output_handler = ManualOutputHandler::new(spec.output_vars.clone()); + let mut output_handler = output_handler(spec.clone()); let outputs = output_handler.get_output(); let monitor = ConstraintBasedMonitor::new(spec, &mut input_streams, output_handler); tokio::spawn(monitor.run()); @@ -81,7 +85,7 @@ async fn test_var() { let mut input_streams = input_streams1(); let mut spec = "in x\nout z\nz =x"; let spec = lola_specification(&mut spec).unwrap(); - let mut output_handler = ManualOutputHandler::new(spec.output_vars.clone()); + let mut output_handler = output_handler(spec.clone()); let outputs = output_handler.get_output(); let monitor = ConstraintBasedMonitor::new(spec, &mut input_streams, output_handler); tokio::spawn(monitor.run()); @@ -117,7 +121,7 @@ async fn test_literal_expression() { let mut input_streams = input_streams1(); let mut spec = "out z\nz =42"; let spec = lola_specification(&mut spec).unwrap(); - let mut output_handler = ManualOutputHandler::new(spec.output_vars.clone()); + let mut output_handler = output_handler(spec.clone()); let outputs = output_handler.get_output(); let monitor = ConstraintBasedMonitor::new(spec, &mut input_streams, output_handler); tokio::spawn(monitor.run()); @@ -154,7 +158,7 @@ async fn test_addition() { let mut input_streams = input_streams1(); let mut spec = "in x\nout z\nz =x+1"; let spec = lola_specification(&mut spec).unwrap(); - let mut output_handler = ManualOutputHandler::new(spec.output_vars.clone()); + let mut output_handler = output_handler(spec.clone()); let outputs = output_handler.get_output(); let monitor = ConstraintBasedMonitor::new(spec, &mut input_streams, output_handler); tokio::spawn(monitor.run()); @@ -190,7 +194,7 @@ async fn test_subtraction() { let mut input_streams = input_streams1(); let mut spec = "in x\nout z\nz =x-10"; let spec = lola_specification(&mut spec).unwrap(); - let mut output_handler = ManualOutputHandler::new(spec.output_vars.clone()); + let mut output_handler = output_handler(spec.clone()); let outputs = output_handler.get_output(); let monitor = ConstraintBasedMonitor::new(spec, &mut input_streams, output_handler); tokio::spawn(monitor.run()); @@ -227,7 +231,7 @@ async fn test_index_past() { let mut input_streams = input_streams1(); let mut spec = "in x\nout z\nz =x[-1, 0]"; let spec = lola_specification(&mut spec).unwrap(); - let mut output_handler = ManualOutputHandler::new(spec.output_vars.clone()); + let mut output_handler = output_handler(spec.clone()); let outputs = output_handler.get_output(); let monitor = ConstraintBasedMonitor::new(spec, &mut input_streams, output_handler); tokio::spawn(monitor.run()); @@ -262,24 +266,28 @@ async fn test_index_past() { ); } -// #[tokio::test] -// async fn test_index_future() { -// let mut input_streams = input_streams1(); -// let mut spec = "in x\nout z\nz =x[1, 0]"; -// let spec = lola_specification(&mut spec).unwrap(); -// let mut monitor = ConstraintBasedMonitor::new(spec, &mut input_streams); -// let outputs: Vec<(usize, BTreeMap)> = -// monitor.monitor_outputs().enumerate().collect().await; -// // assert!(outputs.len() == 1); -// assert_eq!( -// outputs, -// vec![ -// ( -// 0, -// vec![(VarName("z".into()), Value::Int(1))] -// .into_iter() -// .collect(), -// ), -// ] -// ); -// } +#[ignore = "Future indexing doesn't work when data is handled async"] +#[tokio::test] +async fn test_index_future() { + let mut input_streams = input_streams1(); + let mut spec = "in x\nout z\nz =x[1, 0]"; + let spec = lola_specification(&mut spec).unwrap(); + let mut output_handler = output_handler(spec.clone()); + let outputs = output_handler.get_output(); + let monitor = ConstraintBasedMonitor::new(spec, &mut input_streams, output_handler); + tokio::spawn(monitor.run()); + let outputs: Vec<(usize, BTreeMap)> = + outputs.enumerate().collect().await; + // assert!(outputs.len() == 1); + assert_eq!( + outputs, + vec![ + ( + 0, + vec![(VarName("z".into()), Value::Int(1))] + .into_iter() + .collect(), + ), + ] + ); +}