Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any experience with annotation(TestCase(shouldFail=false))?

I'm struggling with the annotation TestCase, which seems to have appeared in Modelica language 3.5 in early 2021. Has anyone used it successfully with Dymola or OpenModelica ?

Here is a sample code I'm using to test it. The simulation fails, which should normaly be prevented by the annotation TestCase. Any suggestion to make it work on these platforms ?

model Test
  Boolean a;
equation 
  a = time < 0.5;

  assert(
    a,
    "test has failed: time is above 0.5",
    level=AssertionLevel.error);
  annotation (TestCase(shouldPass=false));
end Test;
like image 652
AngeliqueR Avatar asked Nov 18 '25 17:11

AngeliqueR


1 Answers

For Dymola:

  • It only has effect if the model is inside a package you check.
  • Normally it just causes the check to be skipped. One part is that only models with experiment-annotations will actually be simulated, and this model only fails during simulation.

So consider the following:

package P
  model Test
    Boolean a;
  equation 
    a = time < 0.5;

    assert(
      a,
      "test has failed: time is above 0.5",
      level=AssertionLevel.error);
    annotation (experiment(StopTime=1), TestCase(shouldPass=false));
  end Test;
  model Test2
    annotation (TestCase(shouldPass=true));
  end Test2;
end P;

Checking P will skip Test.

Addendum: In Dymola 2024x Refresh 1 and earlier even check with simulation will just skip them, later versions should give a summary of issues.

A work-around for Dymola 2024x Refresh 1 is to instead use: annotation(__ModelicaAssociation(TestCase(shouldPass=false))) which was an earlier solution for the same problem.

like image 93
Hans Olsson Avatar answered Nov 20 '25 05:11

Hans Olsson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!