From: Jérémie Astor Date: Wed, 21 Apr 2021 05:59:10 +0000 (+0200) Subject: :art: Functional array tests X-Git-Tag: nightly~732 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=124e39b07b4a9ee8c95281e4d3c12c5c18aceb0a;p=gwion.git :art: Functional array tests --- diff --git a/tests/functionnal_array/concatmap.gw b/tests/functionnal_array/concatmap.gw new file mode 100644 index 00000000..70b40a9a --- /dev/null +++ b/tests/functionnal_array/concatmap.gw @@ -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 index 00000000..799d2b03 --- /dev/null +++ b/tests/functionnal_array/count.gw @@ -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 index 00000000..002ef851 --- /dev/null +++ b/tests/functionnal_array/filter.gw @@ -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 index 00000000..546c8042 --- /dev/null +++ b/tests/functionnal_array/foldl-float.gw @@ -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 index 00000000..b48057b6 --- /dev/null +++ b/tests/functionnal_array/foldl.gw @@ -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 index 00000000..2dba8504 --- /dev/null +++ b/tests/functionnal_array/foldr-float.gw @@ -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 index 00000000..c323decf --- /dev/null +++ b/tests/functionnal_array/map.gw @@ -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}" >>>;