Skip to content

Commit

Permalink
[NF] Add if-expression tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
perost authored and OpenModelica-Hudson committed Apr 5, 2018
1 parent 7257817 commit fde17ad
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 1 deletion.
15 changes: 15 additions & 0 deletions flattening/modelica/scodeinst/IfExpression1.mo
@@ -0,0 +1,15 @@
// name: IfExpression1
// keywords:
// status: correct
// cflags: -d=newInst
//

model IfExpression1
Real x = if true then 1 else 2;
end IfExpression1;

// Result:
// class IfExpression1
// Real x = 1.0;
// end IfExpression1;
// endResult
15 changes: 15 additions & 0 deletions flattening/modelica/scodeinst/IfExpression2.mo
@@ -0,0 +1,15 @@
// name: IfExpression2
// keywords:
// status: correct
// cflags: -d=newInst
//

model IfExpression2
Real x = if time > 1 then 1 else 2;
end IfExpression2;

// Result:
// class IfExpression2
// Real x = /*Real*/(if time > 1.0 then 1 else 2);
// end IfExpression2;
// endResult
17 changes: 17 additions & 0 deletions flattening/modelica/scodeinst/IfExpression3.mo
@@ -0,0 +1,17 @@
// name: IfExpression3
// keywords:
// status: correct
// cflags: -d=newInst
//

model IfExpression3
parameter Boolean b = true;
Real x = if b then 1 else 2;
end IfExpression3;

// Result:
// class IfExpression3
// parameter Boolean b = true;
// Real x = /*Real*/(if b then 1 else 2);
// end IfExpression3;
// endResult
20 changes: 20 additions & 0 deletions flattening/modelica/scodeinst/IfExpression4.mo
@@ -0,0 +1,20 @@
// name: IfExpression4
// keywords:
// status: correct
// cflags: -d=newInst
//

model IfExpression4
parameter Boolean b = true;
Real x[2] = if b then {1, 2} else {3, 4, 5};
end IfExpression4;

// Result:
// class IfExpression4
// parameter Boolean b = true;
// Real x[1];
// Real x[2];
// equation
// x = {1.0, 2.0};
// end IfExpression4;
// endResult
19 changes: 19 additions & 0 deletions flattening/modelica/scodeinst/IfExpression5.mo
@@ -0,0 +1,19 @@
// name: IfExpression5
// keywords:
// status: incorrect
// cflags: -d=newInst
//

model IfExpression5
Real x[2] = if time > 1 then {1, 2} else {3, 4, 5};
end IfExpression5;

// Result:
// Error processing file: IfExpression5.mo
// [flattening/modelica/scodeinst/IfExpression5.mo:8:3-8:53:writable] Error: Type mismatch in if-expression in component . True branch: {1, 2} has type Integer[2], false branch: {3, 4, 5} has type Integer[3].
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
24 changes: 24 additions & 0 deletions flattening/modelica/scodeinst/IfExpression6.mo
@@ -0,0 +1,24 @@
// name: IfExpression6
// keywords:
// status: correct
// cflags: -d=newInst
//

model M
parameter Boolean b;
Real x[if b then 2 else 3] = if b then {1, 2} else {3, 4, 5};
end M;

model IfExpression6
M m[2](b = {true, false});
end IfExpression6;

// Result:
// class IfExpression4
// parameter Boolean b = true;
// Real x[1];
// Real x[2];
// equation
// x = {1.0, 2.0};
// end IfExpression4;
// endResult
6 changes: 6 additions & 0 deletions flattening/modelica/scodeinst/Makefile
Expand Up @@ -387,6 +387,11 @@ IfEquation1.mo \
IfEquation2.mo \
IfEquation3.mo \
IfEquation4.mo \
IfExpression1.mo \
IfExpression2.mo \
IfExpression3.mo \
IfExpression4.mo \
IfExpression5.mo \
IfEquationInvalidCond1.mo \
ih1.mo \
ih2.mo \
Expand Down Expand Up @@ -624,6 +629,7 @@ Wild1.mo \
# test that currently fail. Move up when fixed.
# Run make testfailing
FAILINGTESTFILES=\
IfExpression6.mo \
TupleOperation3.mo \
RedeclareConstant1.mo \
BuiltinAttribute13.mo \
Expand Down
2 changes: 1 addition & 1 deletion flattening/modelica/scodeinst/ceval6.mo
Expand Up @@ -34,7 +34,7 @@ end A;
// parameter Boolean b9 = 1 == 0;
// parameter Boolean b10 = 1 <> 0;
// parameter Boolean b = false or false and not true or true and false and not false or true and not true and not false and true;
// parameter Integer n = if false then 2 else 3;
// parameter Integer n = 3;
// Real x[1];
// Real x[2];
// Real x[3];
Expand Down

0 comments on commit fde17ad

Please sign in to comment.