]> Nishi Git Mirror - gwion.git/commitdiff
:art: Functional array tests
authorJérémie Astor <fennecdjay@gmail.com>
Wed, 21 Apr 2021 05:59:10 +0000 (07:59 +0200)
committerJérémie Astor <fennecdjay@gmail.com>
Wed, 21 Apr 2021 05:59:10 +0000 (07:59 +0200)
tests/functionnal_array/concatmap.gw [new file with mode: 0644]
tests/functionnal_array/count.gw [new file with mode: 0644]
tests/functionnal_array/filter.gw [new file with mode: 0644]
tests/functionnal_array/foldl-float.gw [new file with mode: 0644]
tests/functionnal_array/foldl.gw [new file with mode: 0644]
tests/functionnal_array/foldr-float.gw [new file with mode: 0644]
tests/functionnal_array/map.gw [new file with mode: 0644]

diff --git a/tests/functionnal_array/concatmap.gw b/tests/functionnal_array/concatmap.gw
new file mode 100644 (file)
index 0000000..70b40a9
--- /dev/null
@@ -0,0 +1,29 @@
+
+#!+ this is doc a comment
+
+#!- this also
+
+const float ii;
+123=> var float f;
+
+foreach(a : [12, 1, 2 ,3].compactMap:[int]( \a {
+    var int?i;
+    145 => i.val;
+    if(maybe)
+      i.val++;
+    return i;
+  }
+)) {
+  <<< "mapped to => ${a}" >>>;
+}
+
+fun int? t(int x) {
+  var int?i;
+  145 => i.val;
+  if(maybe)
+    i.val++;
+  return i;
+}
+foreach(a : [12, 1, 2 ,3].compactMap:[int](t))
+  <<< "mapped to => ${a}" >>>;
+<<< "test" >>>;
diff --git a/tests/functionnal_array/count.gw b/tests/functionnal_array/count.gw
new file mode 100644 (file)
index 0000000..799d2b0
--- /dev/null
@@ -0,0 +1,13 @@
+var int _i;
+const int i[2];
+
+fun bool t(int i) { return true; }
+<<< i.count(t) >>>;
+<<< i.count(t) >>>;
+<<< i.count(t) >>>;
+<<< i.count(t) >>>;
+
+<<< i.filter(\a { return maybe; }).size() >>>;
+<<< i.filter(\a { return maybe; }).size() >>>;
+<<< i.filter(\a { return maybe; }).size() >>>;
+<<< i.filter(\a { return maybe; }).size() >>>;
diff --git a/tests/functionnal_array/filter.gw b/tests/functionnal_array/filter.gw
new file mode 100644 (file)
index 0000000..002ef85
--- /dev/null
@@ -0,0 +1,9 @@
+#!const float f;const int i[0];
+#!const int aa;
+fun bool t(int i) { return true; }
+<<< [1].filter(\a { return maybe; }).size() >>>;
+<<< [1].filter(t).size() >>>;
+#!me.exit();
+#!me.exit();
+
+#!<<< i.filter(\a { return maybe; }).size() >>>;
diff --git a/tests/functionnal_array/foldl-float.gw b/tests/functionnal_array/foldl-float.gw
new file mode 100644 (file)
index 0000000..546c804
--- /dev/null
@@ -0,0 +1,9 @@
+fun float t(float i, float j) {
+  <<< "${i} ${j} ${i+j}" >>>;
+  return i$int + j$int;
+}
+
+#!const int i ;
+const float f[3];
+#!<<< f.foldl:[float](t, 1.2) >>>;
+[1.,2.,3.].foldl:[float](t, 3.);
diff --git a/tests/functionnal_array/foldl.gw b/tests/functionnal_array/foldl.gw
new file mode 100644 (file)
index 0000000..b48057b
--- /dev/null
@@ -0,0 +1,12 @@
+const float iii;
+fun int t(int i, int j) {
+  <<< "${i} ${j} ${i+j}" >>>;
+  return i$int + j;
+}
+<<< [1,2,3].foldl:[int](t, 0) >>>;
+<<< [1,2,3].foldl:[int](t, 0) >>>;
+<<< [1,2,3].foldl:[int](t, 0) >>>;
+<<< [1,2,3].foldl:[int](t, 0) >>>;
+
+const int i[0];
+<<< i.foldl:[int](t, 0) >>>;
diff --git a/tests/functionnal_array/foldr-float.gw b/tests/functionnal_array/foldr-float.gw
new file mode 100644 (file)
index 0000000..2dba850
--- /dev/null
@@ -0,0 +1,9 @@
+fun float t(float i, float j) {
+  <<< "${i} ${j} ${i+j}" >>>;
+  return i$int + j$int;
+}
+
+#!const int i ;
+#!const float f[3];
+#!<<< f.foldl:[float](t, 1.2) >>>;
+[1.,2.,3.].foldr:[float](t, 3.);
diff --git a/tests/functionnal_array/map.gw b/tests/functionnal_array/map.gw
new file mode 100644 (file)
index 0000000..c323dec
--- /dev/null
@@ -0,0 +1,13 @@
+fun float t(float i) { return 2; }
+foreach(a : [12., 1, 2 ,3].map:[float](t))
+  <<< "mapped to => ${a}" >>>;
+#!foreach(a : [12, 1, 2 ,3].map:[int](t))
+#!  <<< "mapped to => ${a}" >>>;
+#!foreach(a : [12, 1, 2 ,3].map:[int](t))
+#!  <<< "mapped to => ${a}" >>>;
+#!foreach(a : [12, 1, 2 ,3].map:[int](t))
+#!  <<< "mapped to => ${a}" >>>;
+#!foreach(a : [12, 1, 2 ,3].map:[int]( \a {145 => a;return 2;}))
+#!  <<< "mapped to => ${a}" >>>;
+#!foreach(a : [12, 1, 2 ,3].map:[int]( \a {145 => a;return 2;}))
+#!  <<< "mapped to => ${a}" >>>;