use crate::spec::{expect_failure, expect_parse_success};
mod clock_types {
use super::*;
#[test]
fn mls_16_1_clock_basic() {
expect_parse_success(
r#"
model Test
Clock c;
equation
end Test;
"#,
);
}
#[test]
fn mls_16_1_clock_real_interval() {
expect_parse_success(
r#"
model Test
Clock c = Clock(0.1);
equation
end Test;
"#,
);
}
#[test]
fn mls_16_1_clock_integer_factor() {
expect_parse_success(
r#"
model Test
Clock c1 = Clock(0.1);
Clock c2 = Clock(c1, 2);
equation
end Test;
"#,
);
}
#[test]
fn mls_16_1_clock_boolean_condition() {
expect_parse_success(
r#"
model Test
Boolean trigger;
Clock c = Clock(trigger);
equation
trigger = time > 1;
end Test;
"#,
);
}
#[test]
#[ignore = "Clock flow restriction not yet implemented"]
fn mls_16_1_clock_no_flow() {
expect_failure(
r#"
connector BadConnector
flow Clock c;
end BadConnector;
"#,
"BadConnector",
);
}
#[test]
#[ignore = "Clock stream restriction not yet implemented"]
fn mls_16_1_clock_no_stream() {
expect_failure(
r#"
connector BadConnector
stream Clock c;
end BadConnector;
"#,
"BadConnector",
);
}
#[test]
#[ignore = "Clock discrete restriction not yet implemented"]
fn mls_16_1_clock_no_discrete() {
expect_failure(
r#"
model Test
discrete Clock c;
equation
end Test;
"#,
"Test",
);
}
}
mod clock_operators {
use super::*;
#[test]
fn mls_16_2_sample_operator() {
expect_parse_success(
r#"
model Test
Real x(start = 0);
Clock c = Clock(0.1);
Real xs;
equation
der(x) = 1;
xs = sample(x, c);
end Test;
"#,
);
}
#[test]
fn mls_16_2_hold_operator() {
expect_parse_success(
r#"
model Test
Clock c = Clock(0.1);
Real xs;
Real xh;
equation
xs = sample(1.0, c);
xh = hold(xs);
end Test;
"#,
);
}
#[test]
fn mls_16_2_previous_operator() {
expect_parse_success(
r#"
model Test
Clock c = Clock(0.1);
Real x(start = 0);
equation
x = previous(x) + 1;
end Test;
"#,
);
}
#[test]
fn mls_16_2_subsample_operator() {
expect_parse_success(
r#"
model Test
Clock c1 = Clock(0.1);
Real x;
Real y;
equation
x = sample(1.0, c1);
y = subSample(x, 2);
end Test;
"#,
);
}
#[test]
fn mls_16_2_supersample_operator() {
expect_parse_success(
r#"
model Test
Clock c1 = Clock(0.1);
Real x;
Real y;
equation
x = sample(1.0, c1);
y = superSample(x, 2);
end Test;
"#,
);
}
#[test]
fn mls_16_2_shiftsample_operator() {
expect_parse_success(
r#"
model Test
Clock c = Clock(0.1);
Real x;
Real y;
equation
x = sample(1.0, c);
y = shiftSample(x, 1, 2);
end Test;
"#,
);
}
#[test]
fn mls_16_2_backsample_operator() {
expect_parse_success(
r#"
model Test
Clock c = Clock(0.1);
Real x;
Real y;
equation
x = sample(1.0, c);
y = backSample(x, 1, 2);
end Test;
"#,
);
}
#[test]
fn mls_16_2_noclock_operator() {
expect_parse_success(
r#"
model Test
Clock c = Clock(0.1);
Real x;
Real y;
equation
x = sample(1.0, c);
y = noClock(x);
end Test;
"#,
);
}
#[test]
fn mls_16_2_interval_function() {
expect_parse_success(
r#"
model Test
Clock c = Clock(0.1);
Real x;
Real dt;
equation
x = sample(1.0, c);
dt = interval(x);
end Test;
"#,
);
}
#[test]
fn mls_16_2_first_tick() {
expect_parse_success(
r#"
model Test
Clock c = Clock(0.1);
Boolean isFirst;
equation
isFirst = firstTick(c);
end Test;
"#,
);
}
}
mod clocked_equations {
use super::*;
#[test]
fn mls_16_3_clocked_when() {
expect_parse_success(
r#"
model Test
Clock c = Clock(0.1);
Real x(start = 0);
equation
when c then
x = previous(x) + 1;
end when;
end Test;
"#,
);
}
#[test]
fn mls_16_3_clock_inference() {
expect_parse_success(
r#"
model Test
input Real u;
output Real y;
Real x(start = 0);
equation
x = previous(x) + u;
y = x;
end Test;
"#,
);
}
#[test]
fn mls_16_3_base_clock_partitioning() {
expect_parse_success(
r#"
model Test
Clock c1 = Clock(0.1);
Clock c2 = Clock(0.2);
Real x1, x2;
equation
x1 = sample(1.0, c1);
x2 = sample(2.0, c2);
end Test;
"#,
);
}
}
mod discretized_partitions {
use super::*;
#[test]
fn mls_16_4_solver_method() {
expect_parse_success(
r#"
model Test
Real x(start = 0);
equation
der(x) = -x;
annotation(
__Dymola_discretized = true,
__Dymola_solver = "ExplicitEuler"
);
end Test;
"#,
);
}
#[test]
fn mls_16_4_explicit_euler() {
expect_parse_success(
r#"
model Test
Clock c = Clock(solverMethod = "ExplicitEuler");
Real x(start = 1);
equation
when c then
x = previous(x) - 0.1 * previous(x);
end when;
end Test;
"#,
);
}
#[test]
fn mls_16_4_implicit_euler() {
expect_parse_success(
r#"
model Test
Clock c = Clock(solverMethod = "ImplicitEuler");
Real x(start = 1);
equation
when c then
x = previous(x) / (1 + 0.1);
end when;
end Test;
"#,
);
}
}
mod clocked_initialization {
use super::*;
#[test]
fn mls_16_5_clocked_start() {
expect_parse_success(
r#"
model Test
Clock c = Clock(0.1);
Real x(start = 5);
equation
x = previous(x) + 1;
end Test;
"#,
);
}
#[test]
fn mls_16_5_previous_start() {
expect_parse_success(
r#"
model Test
Clock c = Clock(0.1);
Real x(start = 0);
Real y;
equation
when c then
y = previous(x);
x = y + 1;
end when;
end Test;
"#,
);
}
}