Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
[NF] Add more when-tests.
Browse files Browse the repository at this point in the history
Belonging to [master]:
  - OpenModelica/OMCompiler#3001
  - #1148
  • Loading branch information
perost authored and OpenModelica-Hudson committed Mar 26, 2019
1 parent b14fc7d commit 4e96c49
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 0 deletions.
8 changes: 8 additions & 0 deletions flattening/modelica/scodeinst/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -818,15 +818,23 @@ When2.mo \
When3.mo \
When4.mo \
When5.mo \
WhenClocked1.mo \
WhenClockedElse1.mo \
WhenClockedElse2.mo \
WhenClockedStatement1.mo \
WhenIllegalContext1.mo \
WhenIllegalContext2.mo \
WhenIllegalContext3.mo \
WhenIllegalContext4.mo \
WhenInitial1.mo \
WhenInvalidEquation1.mo \
WhenNested1.mo \
WhenNested2.mo \
WhenVariability1.mo \
WhenVariability2.mo \
WhenVariableMismatch1.mo \
WhenVariableMismatch2.mo \
WhenVariableMismatch3.mo \
Wild1.mo \
OCGTests.mos \

Expand Down
26 changes: 26 additions & 0 deletions flattening/modelica/scodeinst/WhenClocked1.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// name: WhenClocked1
// keywords:
// status: correct
// cflags: -d=newInst
//

model WhenClocked1
Real x, y;
equation
when Clock(0.1) then
x + y = 0;
x - y = 0;
end when;
end WhenClocked1;

// Result:
// class WhenClocked1
// Real x;
// Real y;
// equation
// when Clock(0.1) then
// x + y = 0.0;
// x - y = 0.0;
// end when;
// end WhenClocked1;
// endResult
27 changes: 27 additions & 0 deletions flattening/modelica/scodeinst/WhenClockedElse1.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// name: WhenClockedElse1
// keywords:
// status: incorrect
// cflags: -d=newInst
//

model WhenClockedElse1
Real x, y;
equation
when Clock(0.1) then
x = 0;
y = 1;
elsewhen Clock(0.2) then
x = 2;
y = 3;
end when;
end WhenClockedElse1;

// Result:
// Error processing file: WhenClockedElse1.mo
// [flattening/modelica/scodeinst/WhenClockedElse1.mo:10:3-16:11:writable] Error: Clocked when equation can not contain elsewhen part.
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
27 changes: 27 additions & 0 deletions flattening/modelica/scodeinst/WhenClockedElse2.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// name: WhenClockedElse2
// keywords:
// status: incorrect
// cflags: -d=newInst
//

model WhenClockedElse2
Real x, y;
equation
when time > 0 then
x = 0;
y = 1;
elsewhen Clock(0.2) then
x = 2;
y = 3;
end when;
end WhenClockedElse2;

// Result:
// Error processing file: WhenClockedElse2.mo
// [flattening/modelica/scodeinst/WhenClockedElse2.mo:10:3-16:11:writable] Error: Clocked when branch in when equation.
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
24 changes: 24 additions & 0 deletions flattening/modelica/scodeinst/WhenClockedStatement1.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// name: WhenClockedStatement1
// keywords:
// status: incorrect
// cflags: -d=newInst
//

model WhenClockedStatement1
Real x, y;
algorithm
when Clock(1) then
x := 0;
y := 1;
end when;
end WhenClockedStatement1;

// Result:
// Error processing file: WhenClockedStatement1.mo
// [flattening/modelica/scodeinst/WhenClockedStatement1.mo:10:3-13:11:writable] Error: Type error in when conditional 'Clock(1, 1)'. Expected Boolean scalar or vector, got Clock.
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
24 changes: 24 additions & 0 deletions flattening/modelica/scodeinst/WhenInvalidEquation1.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// name: WhenInvalidEquation1
// keywords:
// status: incorrect
// cflags: -d=newInst
//

model WhenInvalidEquation1
Real x, y;
equation
when time > 0 then
x + y = 0;
x - y = 0;
end when;
end WhenInvalidEquation1;

// Result:
// Error processing file: WhenInvalidEquation1.mo
// [flattening/modelica/scodeinst/WhenInvalidEquation1.mo:11:5-11:14:writable] Error: Invalid left-hand side of when-equation: x + y.
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
25 changes: 25 additions & 0 deletions flattening/modelica/scodeinst/WhenVariableMismatch1.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// name: WhenVariableMismatch1
// keywords:
// status: incorrect
// cflags: -d=newInst
//

model WhenVariableMismatch1
Real x, y;
equation
when time > 0 then
x = 0;
elsewhen time > 1 then
y = 0;
end when;
end WhenVariableMismatch1;

// Result:
// Error processing file: WhenVariableMismatch1.mo
// [flattening/modelica/scodeinst/WhenVariableMismatch1.mo:10:3-14:11:writable] Error: The same variables must be solved in elsewhen clause as in the when clause.
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
25 changes: 25 additions & 0 deletions flattening/modelica/scodeinst/WhenVariableMismatch2.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// name: WhenVariableMismatch2
// keywords:
// status: incorrect
// cflags: -d=newInst
//

model WhenVariableMismatch2
Real x[2];
equation
when time > 0 then
x[1] = 0;
elsewhen time > 1 then
x[2] = 0;
end when;
end WhenVariableMismatch2;

// Result:
// Error processing file: WhenVariableMismatch2.mo
// [flattening/modelica/scodeinst/WhenVariableMismatch2.mo:10:3-14:11:writable] Error: The same variables must be solved in elsewhen clause as in the when clause.
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
29 changes: 29 additions & 0 deletions flattening/modelica/scodeinst/WhenVariableMismatch3.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// name: WhenVariableMismatch3
// keywords:
// status: incorrect
// cflags: -d=newInst
//

model WhenVariableMismatch3
Real x, y;
equation
when time > 0 then
if x > 0 then
x = 0;
else
y = 0;
end if;
elsewhen time > 1 then
x = 0;
end when;
end WhenVariableMismatch3;

// Result:
// Error processing file: WhenVariableMismatch3.mo
// [flattening/modelica/scodeinst/WhenVariableMismatch3.mo:11:5-15:11:writable] Error: The branches of an if-equation inside a when-equation must have the same set of component references on the left-hand side.
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult

0 comments on commit 4e96c49

Please sign in to comment.