add first coase test

This commit is contained in:
Galfour 2019-05-04 10:04:45 +00:00
parent ad5cc8b2d4
commit 9c80d060ed
2 changed files with 33 additions and 16 deletions

View File

@ -27,9 +27,8 @@ let card_ty = ez_t_record [
let card_ez owner = card (e_a_empty_address owner) let card_ez owner = card (e_a_empty_address owner)
let make_cards lst = let make_cards assoc_lst =
let card_id_ty = t_nat () in let card_id_ty = t_nat () in
let assoc_lst = List.mapi (fun i x -> (e_a_empty_nat i , x)) lst in
e_a_empty_map assoc_lst card_id_ty card_ty e_a_empty_map assoc_lst card_id_ty card_ty
let card_pattern (coeff , qtt) = let card_pattern (coeff , qtt) =
@ -62,20 +61,29 @@ let storage cards_patterns cards next_id =
let storage_ez cps cs next_id = let storage_ez cps cs next_id =
storage (make_card_patterns cps) (make_cards cs) (e_a_empty_nat next_id) storage (make_card_patterns cps) (make_cards cs) (e_a_empty_nat next_id)
let basic a b n next_id = let cards_ez owner n =
List.mapi (fun i x -> (e_a_empty_nat i , x))
@@ List.map card_ez
@@ List.map (Function.constant owner)
@@ List.range n
let first_owner =
let open Tezos_utils.Memory_proto_alpha in
let id = List.nth dummy_environment.identities 0 in
let kt = id.implicit_contract in
Alpha_context.Contract.to_b58check kt
let second_owner =
let open Tezos_utils.Memory_proto_alpha in
let id = List.nth dummy_environment.identities 1 in
let kt = id.implicit_contract in
Alpha_context.Contract.to_b58check kt
let basic a b cards next_id =
let card_patterns = List.map card_pattern_ez [ let card_patterns = List.map card_pattern_ez [
(100 , a) ; (100 , a) ;
(20 , b) ; (20 , b) ;
] in ] in
let owner =
let open Tezos_utils.Memory_proto_alpha in
let id = List.hd dummy_environment.identities in
let kt = id.implicit_contract in
Alpha_context.Contract.to_b58check kt in
let cards =
List.map card_ez
@@ List.map (Function.constant owner)
@@ List.range n in
storage_ez card_patterns cards next_id storage_ez card_patterns cards next_id
let buy () = let buy () =
@ -86,20 +94,29 @@ let buy () =
let buy_action = ez_e_a_empty_record [ let buy_action = ez_e_a_empty_record [
("card_to_buy" , e_a_empty_nat 0) ; ("card_to_buy" , e_a_empty_nat 0) ;
] in ] in
let storage = basic 100 1000 n (2 * n) in let storage = basic 100 1000 (cards_ez first_owner n) (2 * n) in
e_a_empty_pair buy_action storage e_a_empty_pair buy_action storage
in in
let expected =
let ops = e_a_empty_list [] (t_operation ()) in
let storage =
let cards =
cards_ez first_owner n @
[(e_a_empty_nat (2 * n) , card (e_a_empty_address second_owner))]
in
basic 101 1000 cards ((2 * n) + 1) in
e_a_empty_pair ops storage
in
let%bind amount = let%bind amount =
trace_option (simple_error "getting amount for run") @@ trace_option (simple_error "getting amount for run") @@
Tezos_utils.Memory_proto_alpha.Alpha_context.Tez.of_mutez @@ Int64.of_int 10000000000 in Tezos_utils.Memory_proto_alpha.Alpha_context.Tez.of_mutez @@ Int64.of_int 10000000000 in
let%bind result = easy_run_typed ~amount "buy_single" program input in let%bind result = easy_run_typed ~amount "buy_single" program input in
Format.printf "\nResult : %a\n" Ast_typed.PP.value result ; Format.printf "\nResult : %a\n" Ast_typed.PP.value result ;
let expected = e_a_empty_bool (n = 0) in
AST_Typed.assert_value_eq (expected, result) AST_Typed.assert_value_eq (expected, result)
in in
let%bind _ = bind_list let%bind _ = bind_list
@@ List.map aux @@ List.map aux
@@ [0 ; 2 ; 7 ; 12] in @@ [2 ; (* 0 ; 7 ; 12 *)] in
ok () ok ()
let main = "Coase (End to End)", [ let main = "Coase (End to End)", [

View File

@ -9,6 +9,6 @@ let () =
Transpiler_tests.main ; Transpiler_tests.main ;
Typer_tests.main ; Typer_tests.main ;
Heap_tests.main ; Heap_tests.main ;
(* Coase_tests.main ; *) Coase_tests.main ;
] ; ] ;
() ()