From 1597d1eaf44c9df91f0d466e36c415c50cc61292 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Wed, 19 Feb 2020 11:51:49 +0100 Subject: [PATCH] WIP: recursion --- src/test/contracts/recursion.ligo | 4 ++++ src/test/contracts/recursion.mligo | 5 +++++ src/test/integration_tests.ml | 16 ++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 src/test/contracts/recursion.ligo create mode 100644 src/test/contracts/recursion.mligo diff --git a/src/test/contracts/recursion.ligo b/src/test/contracts/recursion.ligo new file mode 100644 index 000000000..839ba45ef --- /dev/null +++ b/src/test/contracts/recursion.ligo @@ -0,0 +1,4 @@ +// Test while loops in PascaLIGO + +function fibo (const n : int; const acc: int) : int is + if n<1 then acc else fibo(n-1,acc+n) diff --git a/src/test/contracts/recursion.mligo b/src/test/contracts/recursion.mligo new file mode 100644 index 000000000..f072f00b6 --- /dev/null +++ b/src/test/contracts/recursion.mligo @@ -0,0 +1,5 @@ +// Test while loops in PascaLIGO + +let fibo (n : int) (acc: int) : int = + if (n < 1) then acc + else fibo (n-1) (acc+n) diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 91969b374..bf24a6012 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -1493,6 +1493,20 @@ let assert_religo () : unit result = let%bind _ = expect_eq program "main" (make_input true) make_expected in ok () +let recursion_ligo () : unit result = + let%bind program = type_file "./contracts/recursion.ligo" in + let make_input = e_pair (e_int 10) (e_int 0) in + let make_expected = e_int 55 in + let%bind _ = expect_eq program "fibo" make_input make_expected in + ok () + +let recursion_mligo () : unit result = + let%bind program = mtype_file "./contracts/recursion.mligo" in + let make_input = e_pair (e_int 10) (e_int 0) in + let make_expected = e_int 55 in + let%bind _ = expect_eq program "fibo" make_input make_expected in + ok () + let guess_string_mligo () : unit result = let%bind program = type_file "./contracts/guess_string.mligo" in let make_input = fun n -> e_pair (e_int n) (e_int 42) in @@ -2407,6 +2421,8 @@ let main = test_suite "Integration (End to End)" [ test "failwith ligo" failwith_ligo ; test "failwith mligo" failwith_mligo ; test "assert mligo" assert_mligo ; + test "recursion (ligo)" recursion_ligo ; + test "recursion (mligo)" recursion_mligo ; (* test "guess string mligo" guess_string_mligo ; WIP? *) test "lambda mligo" lambda_mligo ; test "lambda religo" lambda_religo ;