text stringlengths 0 601k |
|---|
let pp_dist pp fmtr dist = let l = Array . to_list dist in Format . pp_print_list ~ pp_sep ( : fun fmtr ( ) -> Format . fprintf fmtr " , " ) ( fun fmtr ( elt , w ) -> Format . fprintf fmtr " ( % a , % f ) " pp elt ( Q . to_float w ) ) fmtr l |
let linf ( dist : ( ' a * Q . t ) array ) pmf = Array . fold_left ( fun acc ( n , q ) -> Q . ( max acc ( abs ( pmf n - q ) ) ) ) Q . zero dist |
let state = Random . State . make [ | 0x1337533D ; 71287309 ; 666932349 ; 719132214 ; 461480042 ; 387006837 ; 443018964 ; 450865457 ; 901711679 ; 833353016 ; 397060904 ; ] | |
module Make_test ( Mass : sig include SMass val to_float : t -> float val sample : int_bound : int -> mass_bound : Mass . t -> int * Mass . t struct let make p = let module Probability = Internal_for_tests . Make ( Mass ) in let measure = List . mapi ( fun i p -> ( i , p ) ) p in let total_mass = List . fold_left Mass ... |
module Probability_mass_float : SMass with type t = float = struct type t = float let encoding = Data_encoding . float let zero = 0 . 0 let of_int = float_of_int let mul = ( . * ) let add = ( . + ) let sub = ( . - ) let ( = ) = Float . equal let ( <= ) ( x : t ) ( y : t ) = x <= y let ( < ) ( x : t ) ( y : t ) = x < y ... |
module Test_float = Make_test ( struct include Probability_mass_float let to_float x = x end ) ( struct let sample ~ int_bound ~ mass_bound = ( Random . State . int state int_bound , Random . State . float state mass_bound ) end ) |
module Probability_mass_z : SMass with type t = Z . t = struct let encoding = Data_encoding . z include Z include Z . Compare end |
module Test_z = Make_test ( struct include Probability_mass_z let to_float = Z . to_float end ) ( struct let sample ~ int_bound ~ mass_bound = ( Random . State . int state int_bound , Z . of_int64 ( Random . State . int64 state ( Z . to_int64 mass_bound ) ) ) end ) |
let qcheck_wrap = qcheck_wrap ~ rand : state |
let alias_float_test = QCheck . Test . make ~ count : 100 ~ name " : alias_float " QCheck . ( list_of_size ( Gen . int_range 1 20 ) pos_float ) Test_float . make |
let alias_z_test = QCheck . Test . make ~ count : 100 ~ name " : alias_z " QCheck . ( list_of_size ( Gen . int_range 1 20 ) ( make Gen . ( nat >>= fun n -> return ( Z . of_int n ) ) ) ) Test_z . make |
let ( ) = Alcotest . run " Sampling " [ ( " sampling " , qcheck_wrap [ alias_float_test ; alias_z_test ] ) ] |
let verbose = if Array . length Sys . argv < 2 then ( Format . eprintf " Executable expects random seed on input \ n " %! ; exit 1 ) else ( Random . init ( int_of_string Sys . argv . ( 1 ) ) ; List . exists ( ( = ) " - v " ) ) ( Array . to_list Sys . argv ) |
let state = Random . State . make [ | 42 ; 987897 ; 54120 ] | |
module Crypto_samplers = Crypto_samplers . Make_finite_key_pool ( struct let algo = ` Default let size = 16 end ) |
module Michelson_base_samplers = Michelson_samplers_base . Make ( struct let parameters = let size = { Base_samplers . min = 4 ; max = 32 } in { Michelson_samplers_base . int_size = size ; string_size = size ; bytes_size = size ; } end ) |
module Code = Michelson_mcmc_samplers . Make_code_sampler ( Michelson_base_samplers ) ( Crypto_samplers ) ( struct let rng_state = state let target_size = 500 let verbosity = if verbose then ` Trace else ` Silent end ) |
let start = Unix . gettimeofday ( ) |
let generator = Code . generator ~ burn_in ( : 500 * 7 ) state |
let stop = Unix . gettimeofday ( ) |
let ( ) = Format . printf " Burn in time : % f seconds . " @ ( stop . - start ) |
let _ = for i = 1 to 1000 do let Michelson_mcmc_samplers . { term = michelson ; bef ; aft } = generator state in Test_helpers . typecheck_by_tezos bef michelson ; if verbose then ( Format . eprintf " result % d / 1000 . " :@ i ; Format . eprintf " type : % a => % a . " @ Test_helpers . print_script_expr_list bef Test_h... |
let verbose = if Array . length Sys . argv < 2 then ( Format . eprintf " Executable expects random seed on input \ n " %! ; exit 1 ) else ( Random . init ( int_of_string Sys . argv . ( 1 ) ) ; List . exists ( ( = ) " - v " ) ) ( Array . to_list Sys . argv ) |
let state = Random . State . make [ | 42 ; 987897 ; 54120 ] | |
module Crypto_samplers = Crypto_samplers . Make_finite_key_pool ( struct let algo = ` Default let size = 16 end ) |
module Michelson_base_samplers = Michelson_samplers_base . Make ( struct let parameters = let size = { Base_samplers . min = 4 ; max = 32 } in { Michelson_samplers_base . int_size = size ; string_size = size ; bytes_size = size ; } end ) |
module Data = Michelson_mcmc_samplers . Make_data_sampler ( Michelson_base_samplers ) ( Crypto_samplers ) ( struct let rng_state = state let target_size = 500 let verbosity = if verbose then ` Trace else ` Silent end ) |
let start = Unix . gettimeofday ( ) |
let generator = Data . generator ~ burn_in ( : 200 * 7 ) state |
let stop = Unix . gettimeofday ( ) |
let ( ) = Format . printf " Burn in time : % f seconds . " @ ( stop . - start ) |
let _ = for _i = 0 to 1000 do let Michelson_mcmc_samplers . { term = michelson ; typ } = generator state in if verbose then ( Format . eprintf " result . " :@ ; Format . eprintf " type : % a . " @ Test_helpers . print_script_expr typ ; Format . eprintf " % a . " @ Test_helpers . print_script_expr michelson ) done |
module Request = struct include Cohttp . Request include ( Make ( IO ) : module type of Make ( IO ) with type t := t ) end |
let message = " Hello sanity " ! |
let chunk_body = [ " one " ; " " ; " " ; " bar " ; " " ] |
let ( ) = Debug . activate_debug ( ) |
let ( ) = Logs . set_level ( Some Warning ) |
let cond = Lwt_condition . create ( ) |
let server = List . map const [ Server . respond_string ~ status ` : OK ~ body : message ( ) ; Server . respond ~ status ` : OK ~ body ( : Body . of_string " " ) ( ) ; Server . respond ~ status ` : OK ~ body ( : Body . of_string_list chunk_body ) ( ) ; Server . respond ~ status ` : OK ~ body ( : Body . of_string " " ) ... |
let check_logs test ( ) = let old = Logs . ( warn_count ( ) + err_count ( ) ) in test ( ) >|= fun ( ) -> let new_errs = Logs . ( warn_count ( ) + err_count ( ) ) - old in if new_errs > 0 then Fmt . failwith " Test produced % d log messages at level >= warn " new_errs |
let ts = Cohttp_lwt_unix_test . test_server_s server ( fun uri -> let ctx = Cohttp_lwt_unix . Net . default_ctx in let t ( ) = Client . get ~ ctx uri >>= fun ( _ , body ) -> body |> Body . to_string >|= fun body -> assert_equal body message in let pipelined_chunk ( ) = let printer x = x in let body = String . concat " ... |
let _ = ts |> run_async_tests |> Lwt_main . run |
module Request = struct include Cohttp . Request include ( Make ( IO ) : module type of Make ( IO ) with type t := t ) end |
let message = " Hello sanity " ! |
let chunk_body = [ " one " ; " " ; " " ; " bar " ; " " ] |
let ( ) = Logs . set_level ( Some Info ) |
let ( ) = Logs . set_reporter Logs . nop_reporter |
let check_logs test ( ) = let old = Logs . ( warn_count ( ) + err_count ( ) ) in test ( ) >|= fun ( ) -> let new_errs = Logs . ( warn_count ( ) + err_count ( ) ) - old in if new_errs > 0 then Fmt . failwith " Test produced % d log messages at level >= warn " new_errs |
let server_noisy = List . map const [ Server . respond ~ status ` : OK ~ body ( : Body . of_string_list chunk_body ) ( ) ; Server . respond ~ status ` : Not_modified ~ body : Body . empty ( ) ; ] @ [ ( fun _ body -> Body . to_string body >>= fun fname -> Server . respond_file ~ fname ( ) >|= fun rsp -> ` Response rsp )... |
let ts_noisy = Cohttp_lwt_unix_test . test_server_s ~ port : 10193 server_noisy ( fun uri -> let ctx = Cohttp_lwt_unix . Net . default_ctx in let empty_chunk ( ) = Client . get ~ ctx uri >>= fun ( _ , body ) -> body |> Body . to_string >|= fun body -> assert_equal body ( String . concat " " chunk_body ) in let not_modi... |
let _ = ts_noisy |> run_async_tests |> Lwt_main . run |
let ( >>??= ) x y = match x with | Ok s -> y s | Error err -> Lwt . return @@ Error ( Environment . wrap_tztrace err ) |
module Raw_context_tests = struct open Sapling_helpers . Common let commitments_add_uncommitted ( ) = Context . init 1 >>=? fun ( b , _ ) -> Raw_context . prepare b . context ~ level : b . header . shell . level ~ predecessor_timestamp : b . header . shell . timestamp ~ timestamp : b . header . shell . timestamp >>= wr... |
module Alpha_context_tests = struct open Sapling_helpers . Alpha_context_helpers let test_verify_memo ( ) = init ( ) >>=? fun ctx -> let sk = Tezos_sapling . Core . Wallet . Spending_key . of_seed ( Tezos_crypto . Hacl . Rand . gen 32 ) in let vt = let ps = Tezos_sapling . Storage . empty ~ memo_size : 0 in Tezos_sapli... |
module Interpreter_tests = struct open Sapling_helpers . Interpreter_helpers let parameters_of_list transactions = let string = " { " ^ String . concat " ; " transactions ^ " } " in Alpha_context . Script . ( lazy_expr ( Expr . from_string string ) ) let test_shielded_tez ( ) = init ( ) >>=? fun ( genesis , baker , src... |
let tests = [ Tztest . tztest " commitments_add_uncommitted " ` Quick Raw_context_tests . commitments_add_uncommitted ; Tztest . tztest " nullifier_double " ` Quick Raw_context_tests . nullifier_double ; Tztest . tztest " nullifier_test " ` Quick Raw_context_tests . nullifier_test ; Tztest . tztest " cm_cipher_test " `... |
module Int = struct type t = int let compare = compare let hash = Hashtbl . hash let equal = ( ) = let default = 0 end |
module String = struct type t = string let compare = compare let hash = Hashtbl . hash let equal = ( ) = let default = " X " end |
let g1 = GI . create ( ) |
let ( ) = GI . add_edge g1 1 2 ; GI . add_edge g1 1 3 ; GI . add_edge g1 2 3 ; GI . add_edge g1 3 1 ; GI . add_edge g1 3 4 ; GI . add_edge g1 3 6 ; GI . add_edge g1 3 7 ; GI . add_edge g1 4 5 ; GI . add_edge g1 5 1 ; GI . add_edge g1 5 2 ; GI . add_edge g1 5 4 ; GI . add_edge g1 5 7 ; GI . add_edge g1 6 5 ; GI . add_ed... |
let g2 = GI . create ( ) |
let ( ) = GI . add_edge g2 1 2 ; GI . add_edge g2 2 3 ; GI . add_edge g2 3 4 ; GI . add_edge g2 4 5 ; GI . add_edge g2 5 6 ; GI . add_edge g2 6 1 |
let g3 = List . fold_left ( fun g ( src , dst ) -> GS . add_edge g src dst ) GS . empty [ ( " A " , " B " ) ; ( " B " , " A " ) ; ( " B " , " E " ) ; ( " C " , " A " ) ; ( " C " , " B " ) ; ( " C " , " D " ) ; ( " C " , " E " ) ; ( " D " , " C " ) ; ( " D " , " E " ) ; ( " E " , " C " ) ; ( " E " , " D " ) ; ( " E " , ... |
let g4 = GI . create ( ) |
let ( ) = GI . add_edge g4 1 2 ; GI . add_edge g4 2 3 ; GI . add_edge g4 3 5 ; GI . add_edge g4 3 9 ; GI . add_edge g4 3 11 ; GI . add_edge g4 3 12 ; GI . add_edge g4 4 1 ; GI . add_edge g4 4 5 ; GI . add_edge g4 4 7 ; GI . add_edge g4 4 9 ; GI . add_edge g4 5 3 ; GI . add_edge g4 5 4 ; GI . add_edge g4 6 7 ; GI . add_... |
let g5 = GI . create ( ) |
let ( ) = GI . add_edge g5 0 1 ; GI . add_edge g5 0 2 ; GI . add_edge g5 1 0 ; GI . add_edge g5 1 2 ; GI . add_edge g5 2 0 ; GI . add_edge g5 2 1 ; GI . add_edge g5 2 3 ; GI . add_edge g5 2 4 ; GI . add_edge g5 2 5 ; GI . add_edge g5 3 2 ; GI . add_edge g5 3 4 ; GI . add_edge g5 3 5 ; GI . add_edge g5 4 2 ; GI . add_ed... |
let pp_comma p ( ) = Format . ( pp_print_char p ' , ' ; pp_print_space p ( ) ) |
let pp_set pp_ele pf s = Format . ( fprintf pf " [ @< hv 4 { >% a } ] " @ ( pp_print_list ~ pp_sep : pp_comma pp_ele ) s ) |
let ( ) = let saps1 = CI . sstrong_articulation_points g1 in let saps2 = CI . sstrong_articulation_points g2 in let saps3 = CS . sstrong_articulation_points g3 in let saps4 = CI . sstrong_articulation_points g4 in let saps5 = CI . sstrong_articulation_points g5 in Format . ( printf " [ @< v >% a , @% a , @% a , @% a , ... |
let valid ( z : _ Saturation_repr . t ) = let x = z |> Saturation_repr . to_int in x >= 0 && x < max_int |
let err x = Exn ( Saturating_test_error x ) |
let small_enough ( z : _ Saturation_repr . t ) = Saturation_repr . ( Compare . Int . ( ( z |> to_int ) land 0x7fffffff80000000 = 0 ) ) |
let ok_int x = match Saturation_repr . of_int_opt x with None -> assert false | Some x -> x |
let n = ok_int 123123 |
let m = ok_int 377337 |
let add ( ) = Saturation_repr . ( fail_unless ( add saturated ( ok_int 1 ) = saturated ) ( err " saturated + 1 <> saturated " ) >>=? fun ( ) -> fail_unless ( add zero n = n ) ( err " zero + n <> n " ) >>=? fun ( ) -> fail_unless ( add n zero = n ) ( err " n + zero <> n " ) >>=? fun ( ) -> let r = add n m in fail_unless... |
let sub ( ) = Saturation_repr . ( fail_unless ( sub zero n = zero ) ( err " zero - n <> zero " ) >>=? fun ( ) -> let n = max n m and m = min n m in let r = sub n m in fail_unless ( valid r && r = ok_int ( ( n |> to_int ) - ( m |> to_int ) ) ) ( err " sub does not behave like - on small numbers . " ) ) |
let mul_safe_of_int x = Saturation_repr . ( match mul_safe ( ok_int x ) with Some x -> x | None -> assert false ) |
let n ' = mul_safe_of_int 1000 |
let m ' = mul_safe_of_int 10000 |
let mul_fast ( ) = Saturation_repr . ( fail_unless ( mul_fast zero n ' = zero ) ( err " mul_fast zero x <> zero " ) >>=? fun ( ) -> fail_unless ( mul_fast n ' zero = zero ) ( err " mul_fast x zero <> zero " ) >>=? fun ( ) -> let r = mul_fast n ' m ' in fail_unless ( valid r && r = ok_int ( ( n ' |> to_int ) * ( m ' |> ... |
let scale_fast ( ) = Saturation_repr . ( fail_unless ( scale_fast zero n = zero ) ( err " scale_fast zero x <> zero " ) >>=? fun ( ) -> fail_unless ( scale_fast n ' zero = zero ) ( err " scale_fast x zero <> zero " ) >>=? fun ( ) -> fail_unless ( scale_fast n ' saturated = saturated ) ( err " scale_fast x saturated <> ... |
let mul ( ) = Saturation_repr . ( fail_unless ( mul saturated saturated = saturated ) ( err " saturated * saturated <> saturated " ) >>=? fun ( ) -> fail_unless ( mul zero saturated = zero ) ( err " zero * saturated <> zero " ) >>=? fun ( ) -> fail_unless ( mul saturated zero = zero ) ( err " saturated * zero <> zero "... |
let shift_left ( ) = Saturation_repr . ( let must_saturate flag ( k , v ) = fail_unless ( Bool . equal flag ( shift_left k v = saturated ) ) ( err ( Printf . sprintf " shift_left % d % d % s saturated " ( k |> to_int ) v ( if flag then " " <> else " " ) ) ) = in List . iter_es ( must_saturate true ) [ ( saturated , 1 )... |
let of_z_opt ( ) = fail_unless ( Saturation_repr . ( of_z_opt ( Z . succ ( Z . of_int max_int ) ) ) = None ) ( err " of_z_opt should saturate when given a z integer greater than max_int . " ) >>=? fun ( ) -> fail_unless ( Saturation_repr . ( of_z_opt ( Z . pred Z . zero ) ) = None ) ( err " of_z_opt should fail on a z ... |
let encoding encoder ( ) = let check_encode_decode x = Data_encoding . Binary . ( match to_bytes encoder ( ok_int x ) with | Error _ -> fail ( err ( Printf . sprintf " Problem during binary encoding of % d " x ) ) | Ok bytes -> ( match of_bytes encoder bytes with | Error _ -> fail ( err ( Printf . sprintf " Problem dur... |
let tests = [ Tztest . tztest " Addition " ` Quick add ; Tztest . tztest " Subtraction " ` Quick sub ; Tztest . tztest " Multiplication " ` Quick mul ; Tztest . tztest " Multiplication ( fast version ) " ` Quick mul_fast ; Tztest . tztest " Shift left " ` Quick shift_left ; Tztest . tztest " Scale fast " ` Quick scale_... |
let test_scalarmult ctxt = assert ( Scalar_mult . primitive = " curve25519 ) " ; let sk = " \ x03 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 " ^ " \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 " ^ " \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 " in let sk = Scalar_mul... |
let test_permute ctxt = assert_raises ( Size_mismatch " Scalar_mult . to_integer ) " ( fun ( ) -> Scalar_mult . Bytes . to_integer ( Bytes . of_string " \ x03 ) ) " ; assert_raises ( Size_mismatch " Scalar_mult . to_group_elt ) " ( fun ( ) -> Scalar_mult . Bytes . to_group_elt ( Bytes . of_string " \ x03 ) ) " |
let test_equal ctxt = let sk = Bytes . of_string ( String . make ( Scalar_mult . integer_size ) integer_size ' A ' ) ' A ' in let sk ' = Bytes . of_string ( " B " ^ ( String . make ( Scalar_mult . integer_size - 1 ) 1 ' A ' ) ' A ' ) ' A ' in let sk ' ' = Bytes . of_string ( ( String . make ( Scalar_mult . integer_size... |
let suite = " Scalarmult " >::: [ " test_scalarmult " >:: test_scalarmult ; " test_permute " >:: test_permute ; " test_equal " >:: test_equal ; ] |
type role = User | Admin |
type user = { id : int ; name : string ; role : role } |
let users = ref [ { id = 1 ; name = " Alice " ; role = Admin } ; { id = 2 ; name = " Bob " ; role = User } ; ] |
let role_values = Schema . [ enum_value " user " ~ value : User ; enum_value " admin " ~ value : Admin ] |
let role = Schema . ( enum " role " ~ values : role_values ) |
let input_role = Schema . Arg . ( enum " role " ~ values : role_values ) |
let user = Schema . ( obj " user " ~ fields [ : field " id " ~ typ ( : non_null int ) ~ args : Arg . [ ] ~ resolve ( : fun { ctx = ( ) } p -> p . id ) ; field " name " ~ typ ( : non_null string ) ~ args : Arg . [ ] ~ resolve ( : fun _ p -> p . name ) ; field " role " ~ typ ( : non_null role ) ~ args : Arg . [ ] ~ resol... |
type tree = | Node of ( int * tree list ) | Leaf of int |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.