Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NF] Added function evaluation tests.
Belonging to [master]: - #73 - OpenModelica/OMCompiler#2407 - OpenModelica/OpenModelica-testsuite#936
- Loading branch information
1 parent
a523321
commit 9fbd53a
Showing
12 changed files
with
335 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// name: CevalFunc1 | ||
// keywords: | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
function f | ||
input Real x; | ||
output Real y; | ||
algorithm | ||
y := x * 2; | ||
end f; | ||
|
||
model CevalFunc1 | ||
constant Real x = f(3.0); | ||
end CevalFunc1; | ||
|
||
// Result: | ||
// class CevalFunc1 | ||
// constant Real x = 6.0; | ||
// end CevalFunc1; | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// name: CevalFuncAssert1 | ||
// keywords: | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
function f | ||
input Integer n; | ||
output Integer res; | ||
algorithm | ||
assert(n <= 2, "f got n larger than 2", AssertionLevel.warning); | ||
res := n; | ||
end f; | ||
|
||
model CevalFuncAssert1 | ||
constant Real x = f(10); | ||
end CevalFuncAssert1; | ||
|
||
// Result: | ||
// class CevalFuncAssert1 | ||
// constant Real x = 10.0; | ||
// end CevalFuncAssert1; | ||
// [flattening/modelica/scodeinst/CevalFuncAssert1.mo:12:3-12:66:writable] Warning: assert triggered: f got n larger than 2 | ||
// | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// name: CevalFuncAssert2 | ||
// keywords: | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
function f | ||
input Integer n; | ||
output Integer res; | ||
algorithm | ||
assert(n <= 2, "f got n larger than 2", AssertionLevel.error); | ||
res := n; | ||
end f; | ||
|
||
model CevalFuncAssert2 | ||
constant Real x = f(10); | ||
end CevalFuncAssert2; | ||
|
||
// Result: | ||
// function f | ||
// input Integer n; | ||
// output Integer res; | ||
// algorithm | ||
// assert(n <= 2, "f got n larger than 2"); | ||
// res := n; | ||
// end f; | ||
// | ||
// class CevalFuncAssert2 | ||
// constant Real x = /*Real*/(f(10)); | ||
// end CevalFuncAssert2; | ||
// [flattening/modelica/scodeinst/CevalFuncAssert2.mo:12:3-12:64:writable] Error: assert triggered: f got n larger than 2 | ||
// | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// name: CevalFunc2 | ||
// keywords: | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
function f | ||
input Integer n; | ||
output Integer res; | ||
algorithm | ||
res := 0; | ||
|
||
for i in 1:n loop | ||
res := res + i; | ||
end for; | ||
end f; | ||
|
||
model CevalFunc1 | ||
constant Real x = f(10); | ||
end CevalFunc1; | ||
|
||
// Result: | ||
// class CevalFunc1 | ||
// constant Real x = 55.0; | ||
// end CevalFunc1; | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// name: CevalFuncFor2 | ||
// keywords: | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
function f | ||
input Integer n; | ||
output Integer res; | ||
algorithm | ||
res := 0; | ||
|
||
for i in 1:n loop | ||
for i in 1:i loop | ||
res := res + i; | ||
end for; | ||
end for; | ||
end f; | ||
|
||
model CevalFuncFor2 | ||
constant Real x = f(10); | ||
end CevalFuncFor2; | ||
|
||
// Result: | ||
// class CevalFuncFor2 | ||
// constant Real x = 220.0; | ||
// end CevalFuncFor2; | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// name: CevalFuncIf1 | ||
// keywords: | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
function f | ||
input Real x; | ||
output Real y; | ||
algorithm | ||
if x > 4 then | ||
y := 3.0; | ||
elseif x > 2 then | ||
y := 5.0; | ||
else | ||
y := 7.0; | ||
end if; | ||
end f; | ||
|
||
model CevalFuncIf1 | ||
constant Real x = f(1.0); | ||
constant Real y = f(3.0); | ||
constant Real z = f(5.0); | ||
end CevalFuncIf1; | ||
|
||
// Result: | ||
// class CevalFuncIf1 | ||
// constant Real x = 7.0; | ||
// constant Real y = 5.0; | ||
// constant Real z = 3.0; | ||
// end CevalFuncIf1; | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// name: CevalFuncRecursive1 | ||
// keywords: | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
function fac | ||
input Integer n; | ||
output Integer res; | ||
algorithm | ||
res := if n > 1 then n * fac(n - 1) else n; | ||
end fac; | ||
|
||
model CevalFuncRecursive1 | ||
constant Real x = fac(6); | ||
end CevalFuncRecursive1; | ||
|
||
// Result: | ||
// class CevalFuncRecursive1 | ||
// constant Real x = 720.0; | ||
// end CevalFuncRecursive1; | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// name: CevalFuncRecursive2 | ||
// keywords: | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
function f | ||
input Real x; | ||
output Real y; | ||
algorithm | ||
y := f(x + 1); | ||
end f; | ||
|
||
model CevalFuncRecursive2 | ||
constant Real x = f(3.0); | ||
end CevalFuncRecursive2; | ||
|
||
// Result: | ||
// function f | ||
// input Real x; | ||
// output Real y; | ||
// algorithm | ||
// y := f(x + 1.0); | ||
// end f; | ||
// | ||
// class CevalFuncRecursive2 | ||
// constant Real x = f(3.0); | ||
// end CevalFuncRecursive2; | ||
// [flattening/modelica/scodeinst/CevalFuncRecursive2.mo:8:1-13:6:writable] Error: The recursion limit (--evalRecursionLimit=256) was exceeded during evaluation of f. | ||
// | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// name: CevalFuncTerminate1 | ||
// keywords: | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
function f | ||
output Integer n = 2; | ||
algorithm | ||
terminate("terminating"); | ||
end f; | ||
|
||
model CevalFuncTerminate1 | ||
constant Real x = f(); | ||
end CevalFuncTerminate1; | ||
|
||
// Result: | ||
// function f | ||
// output Integer n = 2; | ||
// algorithm | ||
// terminate("terminating"); | ||
// end f; | ||
// | ||
// class CevalFuncTerminate1 | ||
// constant Real x = /*Real*/(f()); | ||
// end CevalFuncTerminate1; | ||
// [flattening/modelica/scodeinst/CevalFuncTerminate1.mo:11:3-11:27:writable] Error: terminate triggered: terminating | ||
// | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// name: CevalFuncWhile1 | ||
// keywords: | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
function f | ||
input Integer n; | ||
output Integer res; | ||
protected | ||
Integer i; | ||
algorithm | ||
i := n; | ||
res := 0; | ||
|
||
while i > 0 loop | ||
res := res + i; | ||
i := i - 1; | ||
end while; | ||
end f; | ||
|
||
model CevalFuncWhile1 | ||
constant Real x = f(10); | ||
end CevalFuncWhile1; | ||
|
||
// Result: | ||
// class CevalFuncWhile1 | ||
// constant Real x = 55.0; | ||
// end CevalFuncWhile1; | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// name: CevalFuncWhile2 | ||
// keywords: | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
function f | ||
output Integer res; | ||
algorithm | ||
res := 0; | ||
while true loop | ||
res := res + 1; | ||
end while; | ||
end f; | ||
|
||
model CevalFuncWhile2 | ||
constant Real x = f(); | ||
end CevalFuncWhile2; | ||
|
||
// Result: | ||
// function f | ||
// output Integer res; | ||
// algorithm | ||
// res := 0; | ||
// while true loop | ||
// res := res + 1; | ||
// end while; | ||
// end f; | ||
// | ||
// class CevalFuncWhile2 | ||
// constant Real x = /*Real*/(f()); | ||
// end CevalFuncWhile2; | ||
// [flattening/modelica/scodeinst/CevalFuncWhile2.mo:12:3-14:12:writable] Error: The loop iteration limit (--evalLoopLimit=100000) was exceeded during evaluation. | ||
// | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters