Skip to content

Commit

Permalink
Fixed constraint tests after OutputHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenhaahr committed Dec 9, 2024
1 parent 47eb193 commit c517022
Showing 1 changed file with 37 additions and 29 deletions.
66 changes: 37 additions & 29 deletions tests/constraint_based_lola.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,11 +29,15 @@ pub fn input_streams1() -> BTreeMap<VarName, BoxStream<'static, Value>> {
input_streams
}

fn output_handler(spec: LOLASpecification) -> ManualOutputHandler<Value>{
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());
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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<VarName, Value>)> =
// 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<VarName, Value>)> =
outputs.enumerate().collect().await;
// assert!(outputs.len() == 1);
assert_eq!(
outputs,
vec![
(
0,
vec![(VarName("z".into()), Value::Int(1))]
.into_iter()
.collect(),
),
]
);
}

0 comments on commit c517022

Please sign in to comment.