From a47ff1f33094c93e6da0f8e92b014800f5698f1b Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Fri, 11 Oct 2019 00:33:23 +0300 Subject: [PATCH] Add fib test in several languages --- test/lang/fib.js | 8 ++++++++ test/lang/fib.lua | 8 ++++++++ test/lang/fib.py | 6 ++++++ test/lang/fib.walt | 6 ++++++ test/lang/fib.wasm | Bin 0 -> 63 bytes test/lang/fib.wat | 30 ++++++++++++++++++++++++++++++ 6 files changed, 58 insertions(+) create mode 100644 test/lang/fib.js create mode 100644 test/lang/fib.lua create mode 100644 test/lang/fib.py create mode 100644 test/lang/fib.walt create mode 100644 test/lang/fib.wasm create mode 100644 test/lang/fib.wat diff --git a/test/lang/fib.js b/test/lang/fib.js new file mode 100644 index 0000000..fb15c22 --- /dev/null +++ b/test/lang/fib.js @@ -0,0 +1,8 @@ +function fib(n) { + if(n < 2) { + return n; + } + return fib(n-1) + fib(n-2) +} + +console.log(fib(38)) diff --git a/test/lang/fib.lua b/test/lang/fib.lua new file mode 100644 index 0000000..220db50 --- /dev/null +++ b/test/lang/fib.lua @@ -0,0 +1,8 @@ +local function fib(n) + if n < 2 then + return n + end + return fib(n-1) + fib(n-2) +end + +print(fib(38)) diff --git a/test/lang/fib.py b/test/lang/fib.py new file mode 100644 index 0000000..42475d6 --- /dev/null +++ b/test/lang/fib.py @@ -0,0 +1,6 @@ +def fib(n): + if n < 2: + return n + return fib(n-1) + fib(n-2) + +print(fib(38)) diff --git a/test/lang/fib.walt b/test/lang/fib.walt new file mode 100644 index 0000000..800fd42 --- /dev/null +++ b/test/lang/fib.walt @@ -0,0 +1,6 @@ +export function fib(n: i32): i32 { + if (n < 2) { + return n; + } + return fib(n-1) + fib(n-2); +} diff --git a/test/lang/fib.wasm b/test/lang/fib.wasm new file mode 100644 index 0000000000000000000000000000000000000000..c95a01f8a5ca6830c834f619afb2361444a1f724 GIT binary patch literal 63 zcmZQbEY4+QU|?WmV@zPIXRK#tVq{?FU}T9;%S>Wm;F4#QWl&&nWb$NjP+;Ka1~Ib* MKq8DlDvO^R016HW1poj5 literal 0 HcmV?d00001 diff --git a/test/lang/fib.wat b/test/lang/fib.wat new file mode 100644 index 0000000..6d149a1 --- /dev/null +++ b/test/lang/fib.wat @@ -0,0 +1,30 @@ +(module + (export "_fib" (func $fib)) + (func $fib (param $n i32) (result i32) + (if + (i32.lt_u + (get_local $n) + (i32.const 2) + ) + (return + (get_local $n) + ) + ) + (return + (i32.add + (call $fib + (i32.sub + (get_local $n) + (i32.const 2) + ) + ) + (call $fib + (i32.sub + (get_local $n) + (i32.const 1) + ) + ) + ) + ) + ) +)