Add higher order function test to CameLIGO

This commit is contained in:
John David Pressman 2019-11-22 02:22:29 -08:00
parent f4c3828866
commit 0b50d94071
2 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,46 @@
(* Test a function which takes another function as an argument *)
let foobar (i : int) : int =
let foo: (int -> int) =
fun (i : int) -> i
in
let bar: ((int -> int) -> int) =
fun (f : int -> int) -> f i
in
bar foo
(* higher order function with more than one argument *)
let higher2 (i: int) (f: int -> int): int =
let ii: int = f i in ii
let foobar2 (i : int) : int =
let foo2: (int -> int) =
fun (i : int) -> i
in
higher2 i foo2
let a : int = 0
let foobar3 (i : int) : int =
let foo2: (int -> int) =
fun (i : int) -> a + i
in
higher2 i foo2
let f (i : int) : int = i
let g (i : int) : int = f i
let foobar4 (i : int) : int = g (g i)
let higher3 (i: int) (f: int -> int) (g: int -> int) : int =
let ii: int = f (g i) in ii
let foobar5 (i : int) : int =
let a : int = 0 in
let foo: (int -> int) =
fun (i : int) -> a + i
in
let goo: (int -> int) =
fun (i : int) -> foo i
in
higher3 i foo goo

View File

@ -158,6 +158,17 @@ let higher_order () : unit result =
let%bind _ = expect_eq_n_int program "foobar5" make_expect in
ok ()
let higher_order_mligo () : unit result =
let%bind program = mtype_file "./contracts/high-order.mligo" in
let make_expect = fun n -> n in
let%bind _ = expect_eq_n_int program "foobar" make_expect in
let%bind _ = expect_eq_n_int program "foobar2" make_expect in
let%bind _ = expect_eq_n_int program "foobar3" make_expect in
let%bind _ = expect_eq_n_int program "foobar4" make_expect in
let%bind _ = expect_eq_n_int program "foobar5" make_expect in
ok ()
let shared_function () : unit result =
let%bind program = type_file "./contracts/function-shared.ligo" in
Format.printf "inc\n" ;
@ -1305,6 +1316,7 @@ let main = test_suite "Integration (End to End)" [
test "shared function" shared_function ;
test "shared function (mligo)" shared_function_mligo ;
test "higher order" higher_order ;
test "higher order (mligo)" higher_order_mligo ;
test "variant" variant ;
test "variant (mligo)" variant_mligo ;
test "variant matching" variant_matching ;