text stringlengths 0 601k |
|---|
let int32 loc = [ % expr QCheck . Gen . ui32 ] ui32 |
let int64 loc = [ % expr QCheck . Gen . ui64 ] ui64 |
let option ~ loc e = [ % expr QCheck . Gen . option [ % e e ] e ] e |
let list ~ loc e = [ % expr QCheck . Gen . list [ % e e ] e ] e |
let array ~ loc e = [ % expr QCheck . Gen . array [ % e e ] e ] e |
let pure ~ loc x = [ % expr QCheck . Gen . pure [ % e x ] x ] x |
let frequency ~ loc l = match l with | [ % expr [ ( [ % e ? _ ] _ , [ % e ? x ] x ) x ] x ] x -> x | _ -> [ % expr QCheck . Gen . frequency [ % e l ] l ] l |
let map ~ loc pat expr gen = [ % expr QCheck . Gen . map ( fun [ % p pat ] pat -> [ % e expr ] expr ) expr [ % e gen ] gen ] gen |
let pair ~ loc a b = [ % expr QCheck . Gen . pair [ % e a ] a [ % e b ] b ] b |
let triple ~ loc a b c = [ % expr QCheck . Gen . triple [ % e a ] a [ % e b ] b [ % e c ] c ] c |
let quad ~ loc a b c d = [ % expr QCheck . Gen . quad [ % e a ] a [ % e b ] b [ % e c ] c [ % e d ] d ] d |
let sized ~ loc e = [ % expr QCheck . Gen . sized @@ [ % e e ] e ] e |
let fix ~ loc e = [ % expr QCheck . Gen . fix [ % e e ] e ] e |
module Observable = struct let unit loc = [ % expr QCheck . Observable . unit ] unit let int loc = [ % expr QCheck . Observable . int ] int let string loc = [ % expr QCheck . Observable . string ] string let char loc = [ % expr QCheck . Observable . char ] char let bool loc = [ % expr QCheck . Observable . bool ] bool ... |
let qcheck_wrap ? verbose ? long ? rand = List . map ( QCheck_alcotest . to_alcotest ? verbose ? long ? rand ) |
let qcheck_eq ? pp ? cmp ? eq expected actual = let pass = match ( eq , cmp ) with | ( Some eq , _ ) -> eq expected actual | ( None , Some cmp ) -> cmp expected actual = 0 | ( None , None ) -> Stdlib . compare expected actual = 0 in if pass then true else match pp with | None -> QCheck . Test . fail_reportf " [ @< h 0 ... |
let qcheck_eq_tests ~ eq ~ arb ~ eq_name = let reflexivity_test = QCheck . Test . make ~ name ( : Printf . sprintf " % s is reflexive : forall t , % s t t " eq_name eq_name ) arb ( fun t -> if eq t t then true else QCheck . Test . fail_reportf " [ @< v 2 [ >% s t t ] should hold , but it doesn ' t , !@\ [ t ] is printe... |
let qcheck_eq ' ? pp ? cmp ? eq ~ expected ~ actual ( ) = qcheck_eq ? pp ? cmp ? eq expected actual |
let int64_range_gen a b st = let range = Int64 . sub b a in let raw_val = Random . State . int64 st range in let res = Int64 . add a raw_val in assert ( a <= res && res <= b ) ; res |
let int64_range a b = QCheck . int64 |> QCheck . set_gen ( int64_range_gen a b ) |
let int_strictly_positive_gen = QCheck . Gen . int_range 1 |
let int64_strictly_positive_gen = int64_range_gen 1L |
let endpoint_arb = let open QCheck in let open Gen in let protocol_gen = oneofl [ " http " ; " https " ] in let path_gen = let + path_chunks = list_size ( 1 -- 8 ) ( string_size ~ gen ( : char_range ' a ' ' z ' ) ( 1 -- 8 ) ) in String . concat " . " path_chunks in let port_arb = let + port = 1 -- 32768 in " " : ^ Int ... |
let rec of_option_gen gen random = match gen random with None -> of_option_gen gen random | Some a -> a |
let of_option_arb QCheck . { gen ; print ; small ; shrink ; collect ; stats } = let gen = of_option_gen gen in let print = Option . map ( fun print_opt a -> print_opt ( Some a ) ) print in let small = Option . map ( fun small_opt a -> small_opt ( Some a ) ) small in let shrink = Option . map ( fun shrink_opt a f -> shr... |
let uint16 = QCheck . ( 0 -- 65535 ) |
let int16 = QCheck . ( - 32768 -- 32767 ) |
let uint8 = QCheck . ( 0 -- 255 ) |
let int8 = QCheck . ( - 128 -- 127 ) |
let string_fixed n = QCheck . ( Gen . pure n |> string_of_size ) |
let bytes_arb = QCheck . ( map ~ rev : Bytes . to_string Bytes . of_string string ) |
let of_option_shrink shrink_opt x yield = Option . iter ( fun shrink -> shrink x yield ) shrink_opt |
let sublist : ' a list -> ' a list QCheck . Gen . t = let rec take_n n = function | x :: xs when n > 0 -> x :: take_n ( n - 1 ) xs | _ -> [ ] in fun elems -> let open QCheck . Gen in match elems with | [ ] -> return [ ] | _ -> let * res_len = int_range 0 ( List . length elems ) in let + shuffle = shuffle_l elems in tak... |
let holey ( l : ' a list ) : ' a list QCheck . Gen . t = let open QCheck . Gen in let + bools = list_size ( return ( List . length l ) ) bool in let rev_result = List . fold_left ( fun acc ( elem , pick ) -> if pick then elem :: acc else acc ) [ ] ( List . combine l bools ) in List . rev rev_result |
module MakeMapArb ( Map : Stdlib . Map . S ) = struct open QCheck let arb_of_size ( size_gen : int Gen . t ) ( key_arb : Map . key arbitrary ) ( val_arb : ' v arbitrary ) : ' v Map . t arbitrary = map ~ rev ( : fun map -> Map . to_seq map |> List . of_seq ) ( fun entries -> List . to_seq entries |> Map . of_seq ) ( lis... |
let not_success = function RSuccess _ -> false | _ -> true |
let result_path = function | RSuccess path | RError ( path , _ ) _ | RFailure ( path , _ ) _ | RSkip ( path , _ ) _ | RTodo ( path , _ ) _ -> path |
let result_msg = function | RSuccess _ -> " Success " | RError ( _ , msg ) msg | RFailure ( _ , msg ) msg | RSkip ( _ , msg ) msg | RTodo ( _ , msg ) msg -> msg |
let result_flavour = function | RError _ -> ` Red , " Error " | RFailure _ -> ` Red , " Failure " | RSuccess _ -> ` Green , " Success " | RSkip _ -> ` Blue , " Skip " | RTodo _ -> ` Yellow , " Todo " |
let string_of_path path = let path = List . filter ( function Label _ -> true | _ -> false ) false path in String . concat " " > ( List . rev_map string_of_node path ) path |
let separator1 = " \ 027 [ 027K " ^ ( String . make 79 ' \\ ' ) ' |
let separator2 = String . make 79 ' / ' |
let print_result_list ~ colors = List . iter ( fun result -> let c , res = result_flavour result in pf " % s \ n % a : % s \ n \ n % s \ n % s \ n " separator1 ( Color . pp_str_c ~ colors c ) c res ( string_of_path ( result_path result ) result ) result ( result_msg result ) result separator2 ) separator2 |
let conf_seed = OUnit2 . Conf . make_int " seed " ~- 1 " set random seed " |
let conf_verbose = OUnit2 . Conf . make_bool " qcheck_verbose " true " enable verbose QCheck tests " |
let conf_long = OUnit2 . Conf . make_bool " qcheck_long " false " enable long QCheck tests " |
let default_rand ( ) = Random . State . make [ | 89809344 ; 994326685 ; 290180182 ] | |
let to_ounit2_test ( ? rand = default_rand ( default_rand ) default_rand ) default_rand ( QCheck2 . Test . Test cell ) cell = let module T = QCheck2 . Test in let name = T . get_name cell in let open OUnit2 in name >: test_case ~ length : OUnitTest . Long ( fun ctxt -> let rand = match conf_seed ctxt with | - 1 -> Rand... |
let to_ounit2_test_list ? rand lst = List . rev ( List . rev_map ( to_ounit2_test ? rand ) rand lst ) lst |
let to_ounit_test_cell ( ? verbose = verbose ( verbose ) verbose ) verbose ( ? long = long_tests ( long_tests ) long_tests ) long_tests ( ? rand = random_state ( random_state ) random_state ) random_state cell = let module T = QCheck2 . Test in let name = T . get_name cell in let run ( ) = try T . check_cell_exn cell ~... |
let to_ounit_test ? verbose ? long ? rand ( QCheck2 . Test . Test c ) c = to_ounit_test_cell ? verbose ? long ? rand c |
let ( ) >::: name l = name >::: ( List . map ( fun t -> to_ounit_test t ) t l ) l |
let time_fun f x y = let begin_time = Unix . gettimeofday ( ) in let res = f x y in Unix . gettimeofday ( ) . - begin_time , res |
let run ( ? argv = Sys . argv ) argv test = let cli_args = Raw . parse_cli ~ full_options : true argv in let colors = cli_args . Raw . cli_colors in let pp_color = Color . pp_str_c ~ bold : true ~ colors in let _counter = ref ( 0 , 0 , 0 ) 0 in let total_tests = test_case_count test in let exec_times = ref [ ] in let u... |
let run_tap test = let test_number = ref 0 in let handle_event = function | EStart _ | EEnd _ -> incr test_number | EResult ( RSuccess p ) p -> pf " ok % d - % s \ n " %! ! test_number ( string_of_path p ) p | EResult ( RFailure ( p , m ) m ) m -> pf " not ok % d - % s # % s \ n " %! ! test_number ( string_of_path p ) ... |
let passing = QCheck . Test . make ~ count : 1000 ~ name " : list_rev_is_involutive " QCheck ( . list small_int ) small_int ( fun l -> List . rev ( List . rev l ) l = l ) l ; ; |
let failing = QCheck . Test . make ~ count : 10 ~ name " : fail_sort_id " QCheck ( . list small_int ) small_int ( fun l -> l = List . sort compare l ) l ; ; |
let error = QCheck . Test . make ~ count : 10 ~ name " : error_raise_exn " QCheck . int ( fun _ -> raise Error ) Error |
let simple_qcheck = QCheck . Test . make ~ name " : fail_check_err_message " ~ count : 100 QCheck . small_int ( fun _ -> QCheck . Test . fail_reportf [ " @< v > this @ will @ always @ fail ] ) " @ |
type tree = Leaf of int | Node of tree * tree |
let leaf x = Leaf x |
let node x y = Node ( x , y ) y |
let gen_tree = QCheck . Gen ( . sized @@ fix ( fun self n -> match n with | 0 -> map leaf nat | n -> frequency [ 1 , map leaf nat ; 2 , map2 node ( self ( n / 2 ) 2 ) 2 ( self ( n / 2 ) 2 ) 2 ] 2 ) ) |
let rec rev_tree = function | Node ( x , y ) y -> Node ( rev_tree y , rev_tree x ) x | Leaf x -> Leaf x |
let passing_tree_rev = QCheck . Test . make ~ count : 1000 ~ name " : tree_rev_is_involutive " QCheck ( . make gen_tree ) gen_tree ( fun tree -> rev_tree ( rev_tree tree ) tree = tree ) tree |
let ( ) = Printexc . record_backtrace true ; let open OUnit2 in run_test_tt_main ( " tests " >::: List . map QCheck_ounit . to_ounit2_test [ passing ; failing ; error ; simple_qcheck ; passing_tree_rev ] passing_tree_rev ) passing_tree_rev |
type path_input = | Chain_ID | Block_hash | List_offset | Op_offset | Block_level | Protocol_hash | Rand_string |
type path = ( string , path_input ) Either . t list |
type rpc_input = | Any : rpc_input | Boolean : rpc_input | Integer : { min : int option ; max : int option } -> rpc_input | Z : rpc_input | Int_enum : int list -> rpc_input | Float : { min : float option ; max : float option } -> rpc_input | Even_alphanum : rpc_input | String_enum : string list -> rpc_input | Rand_stri... |
type rpc_description = { description : string ; meth : Client . meth ; path : path ; data : rpc_input option ; } |
type rpc_instance = { description : string ; meth : Client . meth ; full_path : string list ; input : Ezjsonm . value option ; } |
let show_rpc_instance { meth ; full_path ; input ; _ } : string = let inp_str = match input with | None -> " none " | Some value -> Ezjsonm . value_to_string ~ minify : false value in let meth_str = Client . string_of_meth meth in let path_str = String . concat " " / full_path in sf " \ n \ nMeth : % s \ nPath :% s \ n... |
module RPC_Index = struct open Tezos_openapi open Tezos_openapi . Openapi module String_map = Map . Make ( String ) let path_param_form_re = Re . Str . ( regexp " { . } " ) ^+$ let parse_path_input s : path_input = match s with | " { chain_id } " -> Chain_ID | " { block_hash } " -> Block_hash | " { list_offset } " -> L... |
module Gen = struct type ' a t = ' a QCheck . Gen . t let chain_id_gen : string t = let open QCheck . Gen in let open Tezos_crypto in let non_alias = list string >|= Chain_id . hash_string >|= Chain_id . to_string in frequency [ ( 4 , pure " main " ) ; ( 2 , pure " test " ) ; ( 1 , non_alias ) ] let block_hash_gen : st... |
module Test = struct let call_rpc client { meth ; full_path ; input ; _ } : ( JSON . t , Unix . process_status ) result Lwt . t = let proc = Client . spawn_rpc ? data : input meth full_path client in let * exit_code = Process . wait proc in match exit_code with | WEXITED 0 -> let * output = Lwt_io . read @@ Process . s... |
let property_test_rpc_server ~ executors = Long_test . register ~ __FILE__ ~ title " : property_test_rpc_server " ~ tags [ " : node " ; " pbt " ; " fuzz " ; " rpc " ] ~ executors ~ timeout ( : Hours 1 ) Test . test_rpc_server |
let register ( ) = property_test_rpc_server |
let passing = QCheck . Test . make ~ count : 100 ~ long_factor : 100 ~ name " : list_rev_is_involutive " QCheck ( . list small_int ) small_int ( fun l -> List . rev ( List . rev l ) l = l ) l ; ; |
let failing = QCheck . Test . make ~ count : 10 ~ name " : should_fail_sort_id " QCheck ( . small_list small_int ) small_int ( fun l -> l = List . sort compare l ) l ; ; |
let error = QCheck . Test . make ~ count : 10 ~ name " : should_error_raise_exn " QCheck . int ( fun _ -> raise Error ) Error |
let collect = QCheck . Test . make ~ count : 100 ~ long_factor : 100 ~ name " : collect_results " QCheck ( . make ~ collect : string_of_int ( Gen . int_bound 4 ) 4 ) 4 ( fun _ -> true ) true |
let stats = QCheck . Test . make ~ count : 100 ~ long_factor : 100 ~ name " : with_stats " QCheck ( . make ( Gen . int_bound 120 ) 120 ~ stats [ : " mod4 " , ( fun i -> i mod 4 ) 4 ; " num " , ( fun i -> i ) i ; ] ) ( fun _ -> true ) true |
let fun1 = QCheck . Test . make ~ count : 100 ~ long_factor : 100 ~ name " : FAIL_pred_map_commute " QCheck ( . triple ( small_list small_int ) small_int ( fun1 Observable . int int ) int ( fun1 Observable . int bool ) bool ) bool ( fun ( l , QCheck . Fun ( _ , f ) f , QCheck . Fun ( _ , p ) p ) p -> List . filter p ( ... |
let fun2 = QCheck . Test . make ~ count : 100 ~ name " : FAIL_fun2_pred_strings " QCheck ( . fun1 Observable . string bool ) bool ( fun ( QCheck . Fun ( _ , p ) p ) p -> not ( p " some random string ) " || p " some other string ) " |
let bad_assume_warn = QCheck . Test . make ~ count : 2_000 ~ name " : WARN_unlikely_precond " QCheck . int ( fun x -> QCheck . assume ( x mod 100 = 1 ) 1 ; true ) true |
let bad_assume_fail = QCheck . Test . make ~ count : 2_000 ~ if_assumptions_fail ( ` : Fatal , 0 . 1 ) 1 ~ name " : FAIL_unlikely_precond " QCheck . int ( fun x -> QCheck . assume ( x mod 100 = 1 ) 1 ; true ) true |
let prop_foldleft_foldright = let open QCheck in Test . make ~ name " : fold_left fold_right " ~ count : 1000 ~ long_factor : 20 ( triple int_gen ( list int_gen ) int_gen ( fun2 Observable . int Observable . int int_gen ) int_gen ) int_gen ( fun ( z , xs , f ) f -> let l1 = List . fold_right ( Fn . apply f ) f xs z in ... |
let prop_foldleft_foldright_uncurry = let open QCheck in Test . make ~ name " : fold_left fold_right uncurried " ~ count : 1000 ~ long_factor : 20 ( triple ( fun1 Observable ( . pair int int ) int int_gen ) int_gen int_gen ( list int_gen ) int_gen ) int_gen ( fun ( f , z , xs ) xs -> List . fold_right ( fun x y -> Fn .... |
let long_shrink = let open QCheck in let listgen = list_of_size ( Gen . int_range 1000 10000 ) 10000 int in Test . make ~ name " : long_shrink " ( pair listgen listgen ) listgen ( fun ( xs , ys ) ys -> List . rev ( xs @ ys ) ys = ( List . rev xs ) xs ( @ List . rev ys ) ys ) ys |
let find_ex = let open QCheck in Test . make ~ name " : find_example " ( 2 -- 50 ) 50 ( fun n -> let st = Random . State . make [ | 0 ] | in let f m = n < m && m < 2 * n in try let m = find_example_gen ~ rand : st ~ count : 100_000 ~ f Gen ( . 0 -- 1000 ) 1000 in f m with No_example_found _ -> false ) false |
let find_ex_uncaught_issue_99 : _ list = let open QCheck in let t1 = let rs = make ( find_example ~ count : 10 ~ f ( : fun _ -> false ) false Gen . int ) int in Test . make ~ name " : FAIL_ # 99_1 " rs ( fun _ -> true ) true in let t2 = Test . make ~ name " : should_succeed_ # 99_2 " ~ count : 10 int ( fun i -> i <= ma... |
let shrink_int = QCheck . Test . make ~ count : 1000 ~ name " : mod3_should_fail " QCheck . int ( fun i -> i mod 3 <> 0 ) 0 ; ; |
let stats_negs = QCheck ( . Test . make ~ count : 5_000 ~ name " : stats_neg " ( add_stat ( " dist " , fun x -> x ) x small_signed_int ) small_signed_int ) small_signed_int ( fun _ -> true ) true |
type tree = Leaf of int | Node of tree * tree |
let leaf x = Leaf x |
let node x y = Node ( x , y ) y |
let gen_tree = QCheck . Gen ( . sized @@ fix ( fun self n -> match n with | 0 -> map leaf nat | n -> frequency [ 1 , map leaf nat ; 2 , map2 node ( self ( n / 2 ) 2 ) 2 ( self ( n / 2 ) 2 ) 2 ] 2 ) ) |
let rec rev_tree = function | Node ( x , y ) y -> Node ( rev_tree y , rev_tree x ) x | Leaf x -> Leaf x |
let passing_tree_rev = QCheck . Test . make ~ count : 1000 ~ name " : tree_rev_is_involutive " QCheck ( . make gen_tree ) gen_tree ( fun tree -> rev_tree ( rev_tree tree ) tree = tree ) tree |
let stats_tests = let open QCheck in [ Test . make ~ name " : stat_display_test_1 " ~ count : 1000 ( add_stat ( " dist " , fun x -> x ) x small_signed_int ) small_signed_int ( fun _ -> true ) true ; Test . make ~ name " : stat_display_test_2 " ~ count : 1000 ( add_stat ( " dist " , fun x -> x ) x small_nat ) small_nat ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.