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

Commit 4e96c49

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Add more when-tests.
Belonging to [master]: - OpenModelica/OMCompiler#3001 - #1148
1 parent b14fc7d commit 4e96c49

9 files changed

Lines changed: 215 additions & 0 deletions

flattening/modelica/scodeinst/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,15 +818,23 @@ When2.mo \
818818
When3.mo \
819819
When4.mo \
820820
When5.mo \
821+
WhenClocked1.mo \
822+
WhenClockedElse1.mo \
823+
WhenClockedElse2.mo \
824+
WhenClockedStatement1.mo \
821825
WhenIllegalContext1.mo \
822826
WhenIllegalContext2.mo \
823827
WhenIllegalContext3.mo \
824828
WhenIllegalContext4.mo \
825829
WhenInitial1.mo \
830+
WhenInvalidEquation1.mo \
826831
WhenNested1.mo \
827832
WhenNested2.mo \
828833
WhenVariability1.mo \
829834
WhenVariability2.mo \
835+
WhenVariableMismatch1.mo \
836+
WhenVariableMismatch2.mo \
837+
WhenVariableMismatch3.mo \
830838
Wild1.mo \
831839
OCGTests.mos \
832840

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// name: WhenClocked1
2+
// keywords:
3+
// status: correct
4+
// cflags: -d=newInst
5+
//
6+
7+
model WhenClocked1
8+
Real x, y;
9+
equation
10+
when Clock(0.1) then
11+
x + y = 0;
12+
x - y = 0;
13+
end when;
14+
end WhenClocked1;
15+
16+
// Result:
17+
// class WhenClocked1
18+
// Real x;
19+
// Real y;
20+
// equation
21+
// when Clock(0.1) then
22+
// x + y = 0.0;
23+
// x - y = 0.0;
24+
// end when;
25+
// end WhenClocked1;
26+
// endResult
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// name: WhenClockedElse1
2+
// keywords:
3+
// status: incorrect
4+
// cflags: -d=newInst
5+
//
6+
7+
model WhenClockedElse1
8+
Real x, y;
9+
equation
10+
when Clock(0.1) then
11+
x = 0;
12+
y = 1;
13+
elsewhen Clock(0.2) then
14+
x = 2;
15+
y = 3;
16+
end when;
17+
end WhenClockedElse1;
18+
19+
// Result:
20+
// Error processing file: WhenClockedElse1.mo
21+
// [flattening/modelica/scodeinst/WhenClockedElse1.mo:10:3-16:11:writable] Error: Clocked when equation can not contain elsewhen part.
22+
//
23+
// # Error encountered! Exiting...
24+
// # Please check the error message and the flags.
25+
//
26+
// Execution failed!
27+
// endResult
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// name: WhenClockedElse2
2+
// keywords:
3+
// status: incorrect
4+
// cflags: -d=newInst
5+
//
6+
7+
model WhenClockedElse2
8+
Real x, y;
9+
equation
10+
when time > 0 then
11+
x = 0;
12+
y = 1;
13+
elsewhen Clock(0.2) then
14+
x = 2;
15+
y = 3;
16+
end when;
17+
end WhenClockedElse2;
18+
19+
// Result:
20+
// Error processing file: WhenClockedElse2.mo
21+
// [flattening/modelica/scodeinst/WhenClockedElse2.mo:10:3-16:11:writable] Error: Clocked when branch in when equation.
22+
//
23+
// # Error encountered! Exiting...
24+
// # Please check the error message and the flags.
25+
//
26+
// Execution failed!
27+
// endResult
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// name: WhenClockedStatement1
2+
// keywords:
3+
// status: incorrect
4+
// cflags: -d=newInst
5+
//
6+
7+
model WhenClockedStatement1
8+
Real x, y;
9+
algorithm
10+
when Clock(1) then
11+
x := 0;
12+
y := 1;
13+
end when;
14+
end WhenClockedStatement1;
15+
16+
// Result:
17+
// Error processing file: WhenClockedStatement1.mo
18+
// [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.
19+
//
20+
// # Error encountered! Exiting...
21+
// # Please check the error message and the flags.
22+
//
23+
// Execution failed!
24+
// endResult
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// name: WhenInvalidEquation1
2+
// keywords:
3+
// status: incorrect
4+
// cflags: -d=newInst
5+
//
6+
7+
model WhenInvalidEquation1
8+
Real x, y;
9+
equation
10+
when time > 0 then
11+
x + y = 0;
12+
x - y = 0;
13+
end when;
14+
end WhenInvalidEquation1;
15+
16+
// Result:
17+
// Error processing file: WhenInvalidEquation1.mo
18+
// [flattening/modelica/scodeinst/WhenInvalidEquation1.mo:11:5-11:14:writable] Error: Invalid left-hand side of when-equation: x + y.
19+
//
20+
// # Error encountered! Exiting...
21+
// # Please check the error message and the flags.
22+
//
23+
// Execution failed!
24+
// endResult
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// name: WhenVariableMismatch1
2+
// keywords:
3+
// status: incorrect
4+
// cflags: -d=newInst
5+
//
6+
7+
model WhenVariableMismatch1
8+
Real x, y;
9+
equation
10+
when time > 0 then
11+
x = 0;
12+
elsewhen time > 1 then
13+
y = 0;
14+
end when;
15+
end WhenVariableMismatch1;
16+
17+
// Result:
18+
// Error processing file: WhenVariableMismatch1.mo
19+
// [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.
20+
//
21+
// # Error encountered! Exiting...
22+
// # Please check the error message and the flags.
23+
//
24+
// Execution failed!
25+
// endResult
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// name: WhenVariableMismatch2
2+
// keywords:
3+
// status: incorrect
4+
// cflags: -d=newInst
5+
//
6+
7+
model WhenVariableMismatch2
8+
Real x[2];
9+
equation
10+
when time > 0 then
11+
x[1] = 0;
12+
elsewhen time > 1 then
13+
x[2] = 0;
14+
end when;
15+
end WhenVariableMismatch2;
16+
17+
// Result:
18+
// Error processing file: WhenVariableMismatch2.mo
19+
// [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.
20+
//
21+
// # Error encountered! Exiting...
22+
// # Please check the error message and the flags.
23+
//
24+
// Execution failed!
25+
// endResult
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// name: WhenVariableMismatch3
2+
// keywords:
3+
// status: incorrect
4+
// cflags: -d=newInst
5+
//
6+
7+
model WhenVariableMismatch3
8+
Real x, y;
9+
equation
10+
when time > 0 then
11+
if x > 0 then
12+
x = 0;
13+
else
14+
y = 0;
15+
end if;
16+
elsewhen time > 1 then
17+
x = 0;
18+
end when;
19+
end WhenVariableMismatch3;
20+
21+
// Result:
22+
// Error processing file: WhenVariableMismatch3.mo
23+
// [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.
24+
//
25+
// # Error encountered! Exiting...
26+
// # Please check the error message and the flags.
27+
//
28+
// Execution failed!
29+
// endResult

0 commit comments

Comments
 (0)