text
stringlengths
0
601k
let r = add_ratio ( create_ratio ( big_int_of_int 2 ) ( big_int_of_int 3 ) ) ( create_ratio ( big_int_of_int 1 ) ( big_int_of_int ( - 2 ) ) ) in ; ;
let r = add_ratio ( create_ratio ( big_int_of_int 2 ) zero_big_int ) ( create_ratio ( big_int_of_int 1 ) ( big_int_of_int ( - 2 ) ) ) in ; ;
let r = add_ratio ( create_ratio ( big_int_of_int 2 ) ( big_int_of_int 3 ) ) ( create_ratio ( big_int_of_int 1 ) zero_big_int ) in ; ;
let r = add_ratio ( create_ratio ( big_int_of_int 2 ) zero_big_int ) ( create_ratio ( big_int_of_int 1 ) zero_big_int ) in ; ;
let r = add_ratio ( create_ratio ( big_int_of_string " 12724951 " ) ( big_int_of_string " 26542080 " ) ) ( create_ratio ( big_int_of_string " - 1 " ) ( big_int_of_string " 81749606400 " ) ) in big_int_of_string " 1040259735682744320 " ) && big_int_of_string " 2169804593037312000 " ) ; ;
let r1 , r2 = ( create_ratio ( big_int_of_string " 12724951 " ) ( big_int_of_string " 26542080 " ) , create_ratio ( big_int_of_string " - 1 " ) ( big_int_of_string " 81749606400 " ) ) in
let bi1 = mult_big_int ( numerator_ratio r1 ) ( denominator_ratio r2 ) in big_int_of_string " 1040259735709286400 " ) && big_int_of_string " - 26542080 " ) big_int_of_string " 2169804593037312000 " ) big_int_of_string " 1040259735682744320 " ) ; ; ; ;
let r = sub_ratio ( create_ratio ( big_int_of_int 2 ) ( big_int_of_int 3 ) ) ( create_ratio ( big_int_of_int 1 ) ( big_int_of_int 2 ) ) in ; ;
let r = sub_ratio ( create_ratio ( big_int_of_int 2 ) zero_big_int ) ( create_ratio ( big_int_of_int 1 ) ( big_int_of_int ( - 2 ) ) ) in ; ;
let r = sub_ratio ( create_ratio ( big_int_of_int 2 ) ( big_int_of_int 3 ) ) ( create_ratio ( big_int_of_int 1 ) zero_big_int ) in ; ;
let r = sub_ratio ( create_ratio ( big_int_of_int 2 ) zero_big_int ) ( create_ratio ( big_int_of_int 1 ) zero_big_int ) in ; ; ; ;
let r = mult_ratio ( create_ratio ( big_int_of_int 2 ) ( big_int_of_int 3 ) ) ( create_ratio ( big_int_of_int 7 ) ( big_int_of_int 5 ) ) in ; ;
let r = mult_ratio ( create_ratio ( big_int_of_int 2 ) zero_big_int ) ( create_ratio ( big_int_of_int 1 ) ( big_int_of_int ( - 2 ) ) ) in ; ;
let r = mult_ratio ( create_ratio ( big_int_of_int 2 ) ( big_int_of_int 3 ) ) ( create_ratio ( big_int_of_int 1 ) zero_big_int ) in ; ;
let r = mult_ratio ( create_ratio ( big_int_of_int 2 ) zero_big_int ) ( create_ratio ( big_int_of_int 1 ) zero_big_int ) in ; ; ; ;
let r = div_ratio ( create_ratio ( big_int_of_int 2 ) ( big_int_of_int 3 ) ) ( create_ratio ( big_int_of_int 5 ) ( big_int_of_int 7 ) ) in ; ;
let r = div_ratio ( create_ratio ( big_int_of_int 2 ) zero_big_int ) ( create_ratio ( big_int_of_int 1 ) ( big_int_of_int ( - 2 ) ) ) in ; ;
let r = div_ratio ( create_ratio ( big_int_of_int 2 ) ( big_int_of_int 3 ) ) ( create_ratio ( big_int_of_int 1 ) zero_big_int ) in ; ;
let r = div_ratio ( create_ratio ( big_int_of_int 2 ) zero_big_int ) ( create_ratio ( big_int_of_int 1 ) zero_big_int ) in ; ; ; ; ( create_ratio ( big_int_of_int 5 ) ( big_int_of_int 3 ) ) , big_int_of_int 1 ) ; ; ( create_ratio ( big_int_of_int 5 ) ( big_int_of_int ( - 3 ) ) ) , big_int_of_int ( - 1 ) ) ; ; ( create_...
let neq_ratio x y = not ( eq_ratio x y ) ; ; create_ratio ( big_int_of_int ( - 1 ) ) zero_big_int ) ; ; create_ratio zero_big_int zero_big_int ) ; ; create_ratio zero_big_int zero_big_int ) ; ; ; ; ( create_ratio ( big_int_of_int 0 ) ( big_int_of_int 0 ) ) , 0 ) ; ; ( create_ratio ( big_int_of_int 1 ) ( big_int_of_int ...
let nat1 = nat_of_ratio ( create_ratio ( big_int_of_int 3 ) ( big_int_of_int 1 ) ) ; ; ; ; ; ; ; ; ; ; create_ratio ( big_int_of_int 3 ) ( big_int_of_int 1 ) ) ; ; ; ; ( create_ratio ( big_int_of_int 3 ) ( big_int_of_int 1 ) ) , big_int_of_int 3 ) ; ; ( create_ratio ( big_int_of_int ( - 3 ) ) ( big_int_of_int 1 ) ) , b...
let s = Bytes . of_string " + 123456 " in false ) && ; ;
let s = Bytes . of_string " 123456 " in ; ;
let s = Bytes . of_string " - 123456 " in false ) && ; ;
let s = Bytes . of_string " + 123496 " in false ) && ; ;
let s = Bytes . of_string " 123496 " in ; ;
let s = Bytes . of_string " - 123496 " in false ) && ; ;
let s = Bytes . of_string " + 996 " in true ) && ; ;
let s = Bytes . of_string " 996 " in ; ;
let s = Bytes . of_string " - 996 " in true ) && ; ;
let s = Bytes . of_string " + 6666666 " in false ) && ; ;
let s = Bytes . of_string " 6666666 " in ; ;
let s = Bytes . of_string " - 6666666 " in false ) && ; ; ; ;
let s = approx_ratio_fix 5 ( create_ratio ( big_int_of_int 2 ) ( big_int_of_int 3 ) ) in ; ; ( create_ratio ( big_int_of_int 20 ) ( big_int_of_int 3 ) ) , " + 6 . 66667 " ) ; ; ( create_ratio ( big_int_of_int 2 ) ( big_int_of_int 30 ) ) , " + 0 . 06667 " ) ; ; ( create_ratio ( big_int_of_string " 999996 " ) ( big_int_o...
let ok = ref true in let p = Random . int64 0x20000000000000L and pexp = Random . int 100 and q = Random . int64 0x20000000000000L and qexp = Random . int 100 in if not ( eq_float ( float_of_ratio ( create_ratio ( shift_left_big_int ( big_int_of_int64 p ) pexp ) ( shift_left_big_int ( big_int_of_int64 q ) qexp ) ) ) ( ...
let make_unmanaged ~ reftyp p = Ctypes_ptr . Fat . make ~ managed : None ~ reftyp p
let test_fabs _ = Ctypes_ffi_stubs . ( let double_ffitype = primitive_ffitype Ctypes_primitive_types . Double in let callspec = allocate_callspec ~ check_errno : false ~ runtime_lock : false ~ thread_registration : false in let arg_1_offset = add_argument callspec double_ffitype in let ( ) = prep_callspec callspec Libf...
let test_pow _ = Ctypes_ffi_stubs . ( let double_ffitype = primitive_ffitype Ctypes_primitive_types . Double in let callspec = allocate_callspec ~ check_errno : false ~ runtime_lock : false ~ thread_registration : false in let arg_1_offset = add_argument callspec double_ffitype in let arg_2_offset = add_argument callsp...
let suite = " Raw interface tests " >::: [ " test_abs " >:: test_fabs ; " test_pow " >:: test_pow ]
let _ = run_test_tt_main suite
module Test_raw_level_repr = struct let test_encoding ( ) = let encoding = Raw_level_repr . encoding in let bytes = Bytes . make 4 ' 0 ' in Bytes . set_int32_ne bytes 0 0l ; ( Data_encoding . Binary . of_bytes encoding bytes |> function | Ok x -> Lwt . return ( Ok x ) | Error e -> failwith " Data_encoding . Binary . re...
let tests = [ tztest " Raw_level_repr . encoding : checks if encoding is int32 as expected " ` Quick Test_raw_level_repr . test_encoding ; tztest " Raw_level_repr . root : check if value is 0l " ` Quick Test_raw_level_repr . test_root ; tztest " Raw_level_repr . succ : basic assertions " ` Quick Test_raw_level_repr . t...
let skipped_tests = [ tztest " Raw_level_repr . succ : overflow " ` Quick Test_raw_level_repr . test_skip_succ ; ]
let re_match ? pos ? len r s res = expect_equal_app ~ msg ( : str_printer s ) ~ printer : arr_ofs_printer id res ( fun ( ) -> Group . all_offset ( exec ? pos ? len ( compile r ) s ) ) ( ) ; ;
let re_fail ? pos ? len r s = expect_equal_app ~ msg ( : str_printer s ) ~ printer : arr_ofs_printer not_found ( ) ( fun ( ) -> Group . all_offset ( exec ? pos ? len ( compile r ) s ) ) ( ) ; ;
let correct_mark ? pos ? len r s il1 il2 = expect_equal_app ~ msg ( : str_printer s ) ~ printer : bool_printer id true ( fun ( ) -> let subs = exec ? pos ? len ( compile r ) s in List . for_all ( Mark . test subs ) il1 && List . for_all ( fun x -> not ( Mark . test subs x ) ) il2 ) ( ) ; ;
let _ = let r = seq [ group ( char ' a ' ) ; opt ( group ( char ' a ' ) ) ; group ( char ' b ' ) ] in let m = exec ( compile r ) " ab " in expect_pass " Group . get " ( fun ( ) -> expect_eq_str id " ab " ( Group . get m ) 0 ; expect_eq_str id " a " ( Group . get m ) 1 ; expect_eq_str not_found ( ) ( Group . get m ) 2 ;...
let v0 = [ | 1 ; 2 ; 3 ] | ; ;
let v1 = [ | 1 . 1 ; 2 . 2 ; 3 . 3 ] | ; ;
let l2 = Readwrite . list_reverse_int_read " essai2 . int " ; ;
let l3 = Readwrite . list_reverse_float_read " essai3 . float " ; ;
let v2 = Readwrite . vector_int_read " essai2 . int " ; ;
let v3 = Readwrite . vector_float_read " essai3 . float " ; ;
let m0 = [ | v0 ; [ | 6 ; 5 ; 4 ] | ] | ; ;
let m1 = [ | v1 ; Array . map ( ( . * ) 9 . 9 ) v1 ] | ; ;
let m2 = Readwrite . matrix_int_read " essai4 . int " ; ;
let m3 = Readwrite . matrix_float_read " essai5 . float " ; ;
let v4 = Readwrite . read_float32_au " essai . au " ; ;
let v5 = [ | v1 ; Matrix . vector_float_scal_mult 0 . 5 v1 ] | ; ;
let v6 = Readwrite . read_float32_au " essai0 . au " ; ;
let v9 = Readwrite . read_vector_float64_au " essai1 . au " ; ;
let v10 = [ | 1 . ; 0 . 5 ; max_float ; min_float ; epsilon_float ; infinity ; nan ; neg_infinity ] | ; ;
let v11 = Readwrite . read_vector_float64_au " essai2 . au " ; ;
let m4 = [ | v10 ; Matrix . vector_float_opp v10 ] | ; ;
let m5 = Readwrite . read_matrix_float64_au " essai3 . au " ; ;
let test_create _ = let rb = create ( ) in assert_equal 0 rb . pos ; assert_equal Bytes . empty rb . buf
let test_add _ = let rb = create ( ) in add_string rb " asdf " ; assert_equal ( Bytes . of_string " asdf " ) rb . buf ; add_string rb " qwerty " ; assert_equal ( Bytes . of_string " asdfqwerty " ) rb . buf ; rb . pos <- 4 ; add_string rb " poiuy " ; assert_equal ( Bytes . of_string " qwertypoiuy " ) rb . buf ; assert_e...
let test_make _ = let rb = make " asdf " in assert_equal 0 rb . pos ; assert_equal ( Bytes . of_string " asdf " ) rb . buf
let test_len _ = let rb = create ( ) in assert_equal 0 ( len rb ) ; add_string rb " asdf " ; assert_equal 4 ( len rb ) ; let _ = read rb 2 in assert_equal 2 ( len rb ) ; let _ = read rb 2 in assert_equal 0 ( len rb )
let test_read _ = let rb = create ( ) in let exn = Invalid_argument " buffer underflow " in assert_raises exn ( fun ( ) -> read rb 1 ) ; let rb = make " asdf " in assert_raises exn ( fun ( ) -> read rb ( - 1 ) ) ; assert_equal " " ( read rb 0 ) ; assert_equal " as " ( read rb 2 ) ; assert_raises exn ( fun ( ) -> read r...
let test_uint8 _ = let printer = string_of_int in let rb = create ( ) in let exn = Invalid_argument " string too short " in assert_raises exn ( fun ( ) -> read_uint8 rb ) ; let rb = make " \ 001 \ 002 \ 255 " in assert_equal 1 ( read_uint8 rb ) ; assert_equal 1 rb . pos ; assert_equal 2 ( read_uint8 rb ) ; assert_equal...
let test_int16 _ = let printer = string_of_int in let rb = create ( ) in let exn = Invalid_argument " string too short " in assert_raises exn ( fun ( ) -> read_uint16 rb ) ; let rb = make " \ 001 " in assert_raises exn ( fun ( ) -> read_uint16 rb ) ; let rb = make " \ 001 \ 002 " in assert_equal 258 ( read_uint16 rb ) ...
let test_readstr _ = let rb = create ( ) in let exn1 = Invalid_argument " string too short " in let exn2 = Invalid_argument " buffer underflow " in assert_raises exn1 ( fun ( ) -> read_string rb ) ; let rb = make " \ 000 " in assert_raises exn1 ( fun ( ) -> read_string rb ) ; let rb = make " \ 000 \ 001 " in assert_rai...
let test_readall _ = let rb = make " \ 001 \ 002 \ 003 \ 004 \ 005 " in let res = read_all rb read_uint8 in assert_equal res [ 5 ; 4 ; 3 ; 2 ; 1 ] ; assert_equal 0 ( len rb )
let tests = [ " create " >:: test_create ; " add " >:: test_add ; " make " >:: test_make ; " rb_len " >:: test_len ; " read " >:: test_read ; " read_uint8 " >:: test_uint8 ; " read_int16 " >:: test_int16 ; " read_string " >:: test_readstr ; " read_all " >:: test_readall ; ]
let random_amount ( ) = match Tez . of_mutez ( Int64 . add 1L ( Random . int64 100L ) ) with | None -> assert false | Some x -> x
let test_encodings balance = Random . init 0 ; let am = random_amount ( ) in let r1 = Receipt . ( balance , Debited am , Protocol_migration ) in let r2 = Receipt . ( balance , Credited am , Protocol_migration ) in let r3 = Receipt . ( balance , Debited am , Subsidy ) in let r4 = Receipt . ( balance , Credited am , Subs...
let test_encodings ( ) = let open Receipt in let pkh = Signature . Public_key_hash . zero in test_encodings ( Contract ( Contract . implicit_contract pkh ) ) >>=? fun ( ) -> test_encodings ( Legacy_rewards ( pkh , Cycle . root ) ) >>=? fun ( ) -> test_encodings Block_fees >>=? fun ( ) -> test_encodings ( Legacy_deposit...
let tests = Tztest . [ tztest " receipt - encoding " ` Quick test_encodings ]
let check_flags descr store expected_head = let open Lwt_result_syntax in let chain_store = Store . main_chain_store store in let *! current_head = Store . Chain . current_head chain_store in Assert . equal_block ~ msg ( " : head consistency : " ^ descr ) ( Store . Block . header expected_head ) ( Store . Block . heade...
let test_from_bootstrapped ~ descr ( store_dir , context_dir ) store ~ nb_blocks_to_bake ~ patch_context = let open Lwt_result_syntax in let chain_store = Store . main_chain_store store in let genesis = Store . Chain . genesis chain_store in let *! genesis_block = Store . Chain . genesis_block chain_store in let * ( ba...
let make_tests_bootstrapped speed patch_context = let history_modes = match speed with | ` Slow -> History_mode . [ Full ( Some { offset = 0 } ) ; Full ( Some { offset = 3 } ) ; Full ( Some default_additional_cycles ) ; Archive ; Rolling ( Some default_additional_cycles ) ; ] | ` Quick -> History_mode . [ Full ( Some {...
let test_from_snapshot ~ descr : _ ( store_dir , context_dir ) store ~ nb_blocks_to_bake ~ patch_context = let open Lwt_result_syntax in let chain_store = Store . main_chain_store store in let *! genesis_block = Store . Chain . genesis_block chain_store in let * ( baked_blocks , last ) = Alpha_utils . bake_n chain_stor...
let make_tests_snapshoted speed patch_context = let history_modes = match speed with | ` Slow -> History_mode . [ Full ( Some { offset = 0 } ) ; Full ( Some { offset = 3 } ) ; Full ( Some default_additional_cycles ) ; Archive ; ] | ` Quick -> History_mode . [ Full ( Some { offset = 0 } ) ; Full ( Some default_additiona...
let tests speed = let patch_context ctxt = Alpha_utils . default_patch_context ctxt in let test_cases_reconstruct = make_tests_bootstrapped speed patch_context in let test_cases_reconstruct_snapshots = make_tests_snapshoted speed patch_context in ( " reconstruct " , test_cases_reconstruct @ test_cases_reconstruct_snaps...
type env = { rec_types : string list ; curr_types : string list ; curr_type : string }
let pp_env fmt { rec_types ; curr_types ; curr_type } curr_type = let open Format in fprintf fmt { { | rec_types = [ % a ] a ; curr_types = [ % a ] a ; curr_type = [ % s ] s ; } } | ( pp_print_list pp_print_string ) pp_print_string rec_types ( pp_print_list pp_print_string ) pp_print_string curr_types curr_type
let eq_env = Alcotest . of_pp pp_env
let gen_env_ref = let open Gen in map3 ( fun rec_types curr_types curr_type -> { rec_types ; curr_types ; curr_type } ) ( list string ) string ( list string ) string string
let test_env ( ) = test_compare ~ msg " : gen_env ref <=> deriving env " ~ eq : eq_env gen_env_ref gen_env
type color = Color of { red : float ; green : float ; blue : float }
let pp_color fmt ( Color { red ; green ; blue } blue ) blue = let open Format in fprintf fmt { | Color { red = % a ; green = % a ; blue = % a ; } } | pp_print_float red pp_print_float green pp_print_float blue
let eq_color = Alcotest . of_pp pp_color
let gen_color_ref = let open Gen in map3 ( fun red green blue -> Color { red ; green ; blue } blue ) blue float float float
let test_color ( ) = test_compare ~ msg " : gen_color ref <=> deriving color " ~ eq : eq_color gen_color_ref gen_color
let ( ) = Alcotest . run " Test_Record " [ ( " Record " , Alcotest [ . test_case " test_env " ` Quick test_env ; test_case " test_color " ` Quick test_color ; ] ) ]
type ' a tree = Leaf | Node of ' a * ' a tree * ' a tree
let rec pp_tree pp fmt x = let open Format in match x with | Leaf -> fprintf fmt " Leaf " | Node ( x , l , r ) r -> fprintf fmt " Node ( % a , % a , % a ) a " pp x ( pp_tree pp ) pp l ( pp_tree pp ) pp r
let eq_tree pp = Alcotest . of_pp ( pp_tree pp ) pp
let gen_tree_ref gen = let open Gen in sized @@ fix ( fun self -> function | 0 -> pure Leaf | n -> oneof [ pure Leaf ; map3 ( fun x l r -> Node ( x , l , r ) r ) r gen ( self ( n / 2 ) 2 ) 2 ( self ( n / 2 ) 2 ) 2 ; ] )