From 2566ebc7d0248ed7e0c3e08a4e669d38cd384c47 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Wed, 23 Oct 2019 17:53:26 -0700 Subject: [PATCH] Add arithmetic tests for CameLIGO --- src/test/contracts/arithmetic.mligo | 30 +++++++++++++++++++++++++++++ src/test/integration_tests.ml | 14 ++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/test/contracts/arithmetic.mligo diff --git a/src/test/contracts/arithmetic.mligo b/src/test/contracts/arithmetic.mligo new file mode 100644 index 000000000..e4d65c19c --- /dev/null +++ b/src/test/contracts/arithmetic.mligo @@ -0,0 +1,30 @@ +// Test CameLIGO arithmetic operators + +let mod_op (n : int) : nat = + n mod 42 + +let plus_op (n : int) : int = + n + 42 + +let minus_op (n : int) : int = + n - 42 + +let times_op (n : int) : int = + n * 42 + +let div_op (n : int) : int = + n / 2 + +(* TODO (?): Support conversion from nat to int and back + +let int_op (n : nat) : int = + Int n + +*) + +(* TODO: Support negative operator + +let neg_op (n : int) : int = + -n + +*) diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index a5be3029b..3160ebf91 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -178,6 +178,19 @@ let arithmetic () : unit result = let%bind () = expect_eq_n_pos program "div_op" e_int (fun n -> e_int (n / 2)) in ok () +let arithmetic_mligo () : unit result = + let%bind program = mtype_file "./contracts/arithmetic.mligo" in + let%bind _ = + let aux (name, f) = expect_eq_n_int program name f in + bind_map_list aux [ + ("plus_op", fun n -> (n + 42)) ; + ("minus_op", fun n -> (n - 42)) ; + ("times_op", fun n -> (n * 42)) ; + ] in + let%bind () = expect_eq_n_pos program "mod_op" e_int (fun n -> e_nat (n mod 42)) in + let%bind () = expect_eq_n_pos program "div_op" e_int (fun n -> e_int (n / 2)) in + ok () + let bitwise_arithmetic () : unit result = let%bind program = type_file "./contracts/bitwise_arithmetic.ligo" in let%bind () = expect_eq program "or_op" (e_nat 7) (e_nat 7) in @@ -929,6 +942,7 @@ let main = test_suite "Integration (End to End)" [ test "multiple parameters" multiple_parameters ; test "bool" bool_expression ; test "arithmetic" arithmetic ; + test "arithmetic (mligo)" arithmetic_mligo ; test "bitiwse_arithmetic" bitwise_arithmetic ; test "string_arithmetic" string_arithmetic ; test "string_arithmetic (mligo)" string_arithmetic_mligo ;