浏览代码

Add test for nested function declarations and recursion (although we probably don't want recursion in our statecharts)

Joeri Exelmans 5 年之前
父节点
当前提交
2f1c07eebf

+ 3 - 6
test/test_files/features/functions/test_functions.xml

@@ -1,11 +1,6 @@
 <?xml version="1.0" ?>
 <test>
   <statechart>
-    <semantics
-      big_step_maximality="take_many"
-      concurrency="single"
-      input_event_lifeline="first_combo_step"/>
-
     <datamodel>
       digit = func(i:int, pos:int) {
         pow = 10 ** pos;
@@ -15,12 +10,14 @@
       numdigits = func(i:int) {
         return float_to_int(log10(i)) + 1;
       };
+
+      ok = numdigits(123) == 3 and digit(123, 1) == 2;
     </datamodel>
 
     <root initial="ready">
       <state id="ready">
         <transition port="in" event="start" target="../final"
-          cond="numdigits(123) == 3 and digit(123, 1) == 2">
+          cond="ok">
           <raise port="out" event="ok"/>
         </transition>
       </state>

+ 42 - 0
test/test_files/features/functions/test_nested.xml

@@ -0,0 +1,42 @@
+<?xml version="1.0" ?>
+<test>
+  <statechart>
+    <datamodel><![CDATA[
+
+      ok = False;
+
+      outer = func(i:int) {
+        inner = func(j:int) {
+          if (i > j) {
+            ok = True;
+          };
+        };
+        inner(i-1);
+      };
+
+      outer(5);
+
+    ]]></datamodel>
+
+    <root initial="ready">
+      <state id="ready">
+        <transition port="in" event="start" target="../final"
+          cond="ok">
+          <raise port="out" event="ok"/>
+        </transition>
+      </state>
+
+      <state id="final"/>
+    </root>
+  </statechart>
+
+  <input>
+    <event port="in" name="start" time="0 d"/>
+  </input>
+
+  <output>
+    <big_step>
+      <event port="out" name="ok"/>
+    </big_step>
+  </output>
+</test>

+ 40 - 0
test/test_files/features/functions/test_recursion.xml

@@ -0,0 +1,40 @@
+<?xml version="1.0" ?>
+<test>
+  <statechart>
+    <datamodel><![CDATA[
+
+      factorial = func(i:int) {
+        return 0;
+      };
+
+      factorial = func(i:int) {
+        if (i <= 0) return 1;
+        return i*factorial(i-1);
+      };
+
+      ok = factorial(14) == 87178291200;
+
+    ]]></datamodel>
+
+    <root initial="ready">
+      <state id="ready">
+        <transition port="in" event="start" target="../final"
+          cond="ok">
+          <raise port="out" event="ok"/>
+        </transition>
+      </state>
+
+      <state id="final"/>
+    </root>
+  </statechart>
+
+  <input>
+    <event port="in" name="start" time="0 d"/>
+  </input>
+
+  <output>
+    <big_step>
+      <event port="out" name="ok"/>
+    </big_step>
+  </output>
+</test>