Feature/ligo 100 map tests
This commit is contained in:
parent
210bd665c0
commit
6850d21650
@ -165,6 +165,7 @@ module Simplify = struct
|
||||
("Map.fold" , "MAP_FOLD") ;
|
||||
("Map.empty" , "MAP_EMPTY") ;
|
||||
("Map.literal" , "MAP_LITERAL" ) ;
|
||||
("Map.size" , "SIZE" ) ;
|
||||
|
||||
("String.length", "SIZE") ;
|
||||
("String.size", "SIZE") ;
|
||||
@ -615,6 +616,7 @@ module Typer = struct
|
||||
map_update ;
|
||||
map_mem ;
|
||||
map_find ;
|
||||
map_find_opt ;
|
||||
map_map ;
|
||||
map_fold ;
|
||||
map_iter ;
|
||||
|
@ -28,33 +28,3 @@ function get (const m : storage_) : option(int) is
|
||||
begin
|
||||
skip
|
||||
end with m.0[42]
|
||||
|
||||
// the following is not supported (negative test cases):
|
||||
|
||||
// const bm : storage_ = big_map
|
||||
// 144 -> 23 ;
|
||||
// 51 -> 23 ;
|
||||
// 42 -> 23 ;
|
||||
// 120 -> 23 ;
|
||||
// 421 -> 23 ;
|
||||
// end
|
||||
|
||||
// type foobar is big_map(int, int)
|
||||
// const fb : foobar = big_map
|
||||
// 23 -> 0 ;
|
||||
// 42 -> 0 ;
|
||||
// end
|
||||
|
||||
// function size_ (const m : storage_) : nat is
|
||||
// block {skip} with (size(m.0))
|
||||
|
||||
// function iter_op (const m : storage_) : int is
|
||||
// var r : int := 0 ;
|
||||
// function aggregate (const i : int ; const j : int) : unit is block { r := r + i + j } with unit ;
|
||||
// block {
|
||||
// map_iter(m.0 , aggregate) ;
|
||||
// } with r ;
|
||||
|
||||
// function map_op (const m : storage_) : storage_ is
|
||||
// function increment (const i : int ; const j : int) : int is block { skip } with j + 1 ;
|
||||
// block { skip } with map_map(m.0 , increment) ;
|
||||
|
12
src/test/contracts/big_map.mligo
Normal file
12
src/test/contracts/big_map.mligo
Normal file
@ -0,0 +1,12 @@
|
||||
type storage_ = ((int, int) big_map * unit)
|
||||
|
||||
let set_ (n : int) (m : storage_) : storage_ =
|
||||
(Map.update 23 (Some(n)) m.(0), ())
|
||||
|
||||
let rm (m : storage_) : storage_ =
|
||||
(Map.remove 42 m.(0), ())
|
||||
|
||||
let gf (m : storage_) : int = Map.find 23 m.(0)
|
||||
|
||||
let get (m: storage_): int option =
|
||||
Map.find_opt 42 m.(0)
|
@ -2,7 +2,16 @@
|
||||
|
||||
type foobar is map(int, int)
|
||||
|
||||
const fb : foobar = map
|
||||
const empty_map : foobar = map end
|
||||
|
||||
const map1 : foobar = map
|
||||
144 -> 23 ;
|
||||
51 -> 23 ;
|
||||
42 -> 23 ;
|
||||
120 -> 23 ;
|
||||
421 -> 23 ;
|
||||
end
|
||||
const map2 : foobar = map
|
||||
23 -> 0 ;
|
||||
42 -> 0 ;
|
||||
end
|
||||
@ -31,20 +40,12 @@ function get_ (const m : foobar) : option(int) is
|
||||
skip
|
||||
end with map_get(42 , m)
|
||||
|
||||
const bm : foobar = map
|
||||
144 -> 23 ;
|
||||
51 -> 23 ;
|
||||
42 -> 23 ;
|
||||
120 -> 23 ;
|
||||
421 -> 23 ;
|
||||
end
|
||||
|
||||
function iter_op (const m : foobar) : int is
|
||||
var r : int := 0 ;
|
||||
function aggregate (const i : int ; const j : int) : unit is block { r := r + i + j } with unit ;
|
||||
block {
|
||||
map_iter(m , aggregate) ;
|
||||
} with r ;
|
||||
function iter_op (const m : foobar) : unit is
|
||||
function aggregate (const i : int ; const j : int) : unit is block
|
||||
{ if (i=j) then skip else failwith("fail") } with unit ;
|
||||
block {skip}
|
||||
// map_iter(m , aggregate) ;
|
||||
with map_iter(m, aggregate) ;
|
||||
|
||||
function map_op (const m : foobar) : foobar is
|
||||
function increment (const i : int ; const j : int) : int is block { skip } with j + 1 ;
|
||||
|
@ -1,7 +1,31 @@
|
||||
type foobar = (int , int) map
|
||||
|
||||
let foobar : foobar = Map.empty
|
||||
let empty_map : foobar = Map.empty
|
||||
|
||||
let foobarz : foobar = Map.literal [ (1 , 10) ; (2 , 20) ]
|
||||
let map1 : foobar = Map.literal
|
||||
[ (144 , 23) ; (51 , 23) ; (42 , 23) ; (120 , 23) ; (421 , 23) ]
|
||||
let map2 : foobar = Map [ (23 , 0) ; (42 , 0) ]
|
||||
|
||||
let foo : int = Map.find 1 foobarz
|
||||
let set_ (n : int) (m : foobar) : foobar =
|
||||
Map.update 23 (Some n) m
|
||||
|
||||
let rm (m : foobar) : foobar = Map.remove 42 m
|
||||
|
||||
let size_ (m : foobar) : nat = Map.size m
|
||||
|
||||
let gf (m : foobar) : int = Map.find 23 m
|
||||
|
||||
let get (m : foobar) : int option = Map.find_opt 42 m
|
||||
let get_ (m : foobar) : int option = Map.find_opt 42 m
|
||||
|
||||
let iter_op (m : foobar) : unit =
|
||||
let assert_eq = fun (i : int) (j : int) -> assert(i=j) in
|
||||
Map.iter m assert_eq
|
||||
|
||||
let map_op (m : foobar) : foobar =
|
||||
let increment = fun (i : int) (j : int) -> j+1 in
|
||||
Map.map m increment
|
||||
|
||||
let fold_op (m : foobar) : foobar =
|
||||
let aggregate = fun (i : int) (j : (int * int)) -> i + j.(0) + j.(1) in
|
||||
Map.fold m 10 aggregate
|
@ -377,36 +377,13 @@ let moption () : unit result =
|
||||
in
|
||||
ok ()
|
||||
|
||||
let mmap () : unit result =
|
||||
let%bind program = mtype_file "./contracts/map.mligo" in
|
||||
let%bind () = expect_eq_evaluate program "foobar"
|
||||
(e_annotation (e_map []) (t_map t_int t_int)) in
|
||||
let%bind () = expect_eq_evaluate program "foobarz"
|
||||
(e_annotation (e_map [(e_int 1 , e_int 10) ; (e_int 2 , e_int 20)]) (t_map t_int t_int)) in
|
||||
let%bind () = expect_eq_evaluate program "foo" (e_int 10) in
|
||||
ok ()
|
||||
|
||||
let map () : unit result =
|
||||
let%bind program = type_file "./contracts/map.ligo" in
|
||||
let map_ type_f path : unit result =
|
||||
let%bind program = type_f path in
|
||||
let ez lst =
|
||||
let open Ast_simplified.Combinators in
|
||||
let lst' = List.map (fun (x, y) -> e_int x, e_int y) lst in
|
||||
e_typed_map lst' t_int t_int
|
||||
in
|
||||
let%bind () =
|
||||
let make_input = fun n -> ez [(23, n) ; (42, 4)] in
|
||||
let make_expected = e_int in
|
||||
expect_eq_n program "gf" make_input make_expected
|
||||
in
|
||||
let%bind () =
|
||||
let make_input = fun n -> ez List.(map (fun x -> (x, x)) @@ range n) in
|
||||
let make_expected = e_nat in
|
||||
expect_eq_n_strict_pos_small program "size_" make_input make_expected
|
||||
in
|
||||
let%bind () =
|
||||
let expected = ez [(23, 0) ; (42, 0)] in
|
||||
expect_eq_evaluate program "fb" expected
|
||||
in
|
||||
let%bind () =
|
||||
let make_input = fun n ->
|
||||
let m = ez [(23 , 0) ; (42 , 0)] in
|
||||
@ -415,6 +392,21 @@ let map () : unit result =
|
||||
let make_expected = fun n -> ez [(23 , n) ; (42 , 0)] in
|
||||
expect_eq_n_pos_small program "set_" make_input make_expected
|
||||
in
|
||||
let%bind () =
|
||||
let input = ez [(23, 23) ; (42, 42)] in
|
||||
let expected = ez [23, 23] in
|
||||
expect_eq program "rm" input expected
|
||||
in
|
||||
let%bind () =
|
||||
let make_input = fun n -> ez List.(map (fun x -> (x, x)) @@ range n) in
|
||||
let make_expected = e_nat in
|
||||
expect_eq_n_strict_pos_small program "size_" make_input make_expected
|
||||
in
|
||||
let%bind () =
|
||||
let make_input = fun n -> ez [(23, n) ; (42, 4)] in
|
||||
let make_expected = e_int in
|
||||
expect_eq_n program "gf" make_input make_expected
|
||||
in
|
||||
let%bind () =
|
||||
let make_input = fun n -> ez [(23, n) ; (42, 4)] in
|
||||
let make_expected = fun _ -> e_some @@ e_int 4 in
|
||||
@ -425,34 +417,35 @@ let map () : unit result =
|
||||
let make_expected = fun _ -> e_some @@ e_int 4 in
|
||||
expect_eq_n program "get_" make_input make_expected
|
||||
in
|
||||
let%bind () = expect_eq_evaluate program "empty_map"
|
||||
(e_annotation (e_map []) (t_map t_int t_int)) in
|
||||
let%bind () =
|
||||
let expected = ez @@ List.map (fun x -> (x, 23)) [144 ; 51 ; 42 ; 120 ; 421] in
|
||||
expect_eq_evaluate program "bm" expected
|
||||
expect_eq_evaluate program "map1" expected
|
||||
in
|
||||
let%bind () =
|
||||
let input = ez [(23, 23) ; (42, 42)] in
|
||||
let expected = ez [23, 23] in
|
||||
expect_eq program "rm" input expected
|
||||
let expected = ez [(23, 0) ; (42, 0)] in
|
||||
expect_eq_evaluate program "map2" expected
|
||||
in
|
||||
let%bind () =
|
||||
let input = ez [(1 , 10) ; (2 , 20) ; (3 , 30) ] in
|
||||
let expected = e_int 66 in
|
||||
let input = ez [(1 , 1) ; (2 , 2) ; (3 , 3) ] in
|
||||
let expected = e_unit () in
|
||||
expect_eq program "iter_op" input expected
|
||||
in
|
||||
let%bind () =
|
||||
let input = ez [(1 , 10) ; (2 , 20) ; (3 , 30) ] in
|
||||
let expected = e_int 76 in
|
||||
expect_eq program "fold_op" input expected
|
||||
in
|
||||
let%bind () =
|
||||
let input = ez [(1 , 10) ; (2 , 20) ; (3 , 30) ] in
|
||||
let expected = ez [(1 , 11) ; (2 , 21) ; (3 , 31) ] in
|
||||
expect_eq program "map_op" input expected
|
||||
in
|
||||
let%bind () =
|
||||
let input = ez [(1 , 10) ; (2 , 20) ; (3 , 30) ] in
|
||||
let expected = e_int 76 in
|
||||
expect_eq program "fold_op" input expected
|
||||
in
|
||||
ok ()
|
||||
|
||||
let big_map () : unit result =
|
||||
let%bind program = type_file "./contracts/big_map.ligo" in
|
||||
let big_map_ type_f path : unit result =
|
||||
let%bind program = type_f path in
|
||||
let ez lst =
|
||||
let open Ast_simplified.Combinators in
|
||||
let lst' = List.map (fun (x, y) -> e_int x, e_int y) lst in
|
||||
@ -483,6 +476,13 @@ let big_map () : unit result =
|
||||
in
|
||||
ok ()
|
||||
|
||||
|
||||
let map () : unit result = map_ type_file "./contracts/map.ligo"
|
||||
let mmap () : unit result = map_ mtype_file "./contracts/map.mligo"
|
||||
let big_map () : unit result = big_map_ type_file "./contracts/big_map.ligo"
|
||||
let mbig_map () : unit result = big_map_ mtype_file "./contracts/big_map.mligo"
|
||||
|
||||
|
||||
let list () : unit result =
|
||||
let%bind program = type_file "./contracts/list.ligo" in
|
||||
let ez lst =
|
||||
@ -853,6 +853,7 @@ let main = test_suite "Integration (End to End)" [
|
||||
test "map" map ;
|
||||
test "map (mligo)" mmap ;
|
||||
test "big_map" big_map ;
|
||||
test "big_map (mligo)" mbig_map ;
|
||||
test "list" list ;
|
||||
test "loop" loop ;
|
||||
test "matching" matching ;
|
||||
|
Loading…
Reference in New Issue
Block a user