text stringlengths 12 786k |
|---|
let rec permut = function | [ ] -> [ [ ] ] | x :: xs -> let insert xs = let rec loop acc left right = match right with | [ ] -> List . rev ( x :: left ) :: acc | y :: ys -> loop ( List . rev_append left ( x :: right ) :: acc ) ( y :: left ) ys in loop [ ] [ ] ... |
let test_take_n _ = ListLabels . iter ( permut [ 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ] ) ~ f ( : fun xs -> Assert . equal ~ msg : __LOC__ ( TzList . take_n ~ compare 1 xs ) [ 9 ] ) ; ListLabels . iter ( permut [ 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; ... |
let test_drop_n _ = Assert . equal ~ msg : __LOC__ ( TzList . drop_n 3 [ 1 ; 2 ; 3 ; 4 ; 5 ] ) [ 4 ; 5 ] ; Assert . equal ~ msg : __LOC__ ( TzList . drop_n 3 [ 1 ; 2 ] ) [ ] ; Assert . equal ~ msg : __LOC__ ( TzList . drop_n 3 [ ] ) [ ... |
let test_filter_some _ = Assert . equal ~ msg : __LOC__ ( TzList . filter_some [ ] ) [ ] ; Assert . equal ~ msg : __LOC__ ( TzList . filter_some [ None ] ) [ ] ; Assert . equal ~ msg : __LOC__ ( TzList . filter_some [ None ; None ] ) [ ] ; Assert . eq... |
let list_size = QCheck . Gen . int_range 2 1000 |
let pp_int_list = Format . pp_print_list ~ pp_sep ( : fun ppf ( ) -> Format . fprintf ppf " ; " ) Format . pp_print_int |
let test_shuffle_preserves_values = QCheck . Test . make ~ name " : shuffle preserves value sets " ~ count QCheck . ( list_of_size list_size int ) ( fun l -> let l1 = List . sort Int . compare l in let l2 = List . sort Int . compare ( TzList . shuffle l ) in Lib_test . Qcheck_help... |
let test_take_drop = QCheck . Test . make ~ name " ( : take_n n l @@ drop_n n l ) = l " ~ count QCheck . ( pair ( list_of_size list_size int ) small_int ) ( fun ( l , n ) -> Lib_test . Qcheck_helpers . qcheck_eq ' ~ pp : pp_int_list ~ eq ( : = ) ~ actual : TzList . ... |
let test_filter_some_length = QCheck . Test . make ~ name " ( : length ( filter_some l ) ) = ( length ( filter ( Option . is_some ) l ) ) " ~ count QCheck . ( list_of_size list_size ( option int ) ) ( fun l -> Lib_test . Qcheck_helpers . qcheck_eq ' ~ pp : Format ... |
let ( ) = Alcotest . run " stdlib " [ ( " tzList " , [ ( " take_n " , ` Quick , test_take_n ) ; ( " drop_n " , ` Quick , test_drop_n ) ; ( " filter_some " , ` Quick , test_filter_some ) ; QCheck_alcotest . to_alcotest test_shuffle_preserves_values... |
let test_split_duplicated_separator_default_behavior ( ) = let inputs = [ " Hello World " ; " Hello World " ; " HelloWorld " ; " Hello World " ; " Hello World " ; " Hello World " ; ] in List . iter ( fun s -> assert ( TzString . split ? dup : None ' ' s = Tz... |
let test_split_dup_param_to_true_with_duplicated_separator ( ) = let inputs = [ " Hello World " ; " Hello World " ; " Hello World " ; " Hello World " ; " Hello World " ; ] in List . iter ( fun s -> assert ( [ " Hello " ; " World " ] = TzString . split ~ d... |
let test_split_dup_param_to_false_with_duplicated_separator ( ) = let inputs = [ ( " Hello World " , [ " Hello " ; " World " ] ) ; ( " Hello World " , [ " Hello " ; " " ; " World " ] ) ; ( " Hello World " , [ " Hello " ; " " ; " W... |
let test_split_roundtrip ( ) = let inputs = [ " HelloWorld " ; " Hello World " ; " Hello World " ; " H e l l o W o rl d " ; " " ; ] in List . iter ( fun input -> let split = TzString . split ~ dup : false ' ' input in let reassembled = String . concat " " spl... |
let split_tests = [ ( " Default behavior handles a duplicated separator " , ` Quick , test_split_duplicated_separator_default_behavior ) ; ( " dup parameter to true " , ` Quick , test_split_dup_param_to_true_with_duplicated_separator ) ; ( " dup parameter to false " , ` Quic... |
let ( ) = Alcotest . run " TzString " [ ( " split " , split_tests ) ] |
let raises f v = Exn . does_raise ( fun ( ) -> f v ) ( module struct let % test _ = Uchar . ( to_scalar min_value ) = 0x0000 let % test _ = Uchar . ( to_scalar max_value ) = 0x10FFFF end ) ; ; ( module struct let % test _ = raises Uchar . succ_exn Uchar . max_value let... |
let char_max = Uchar . of_scalar_exn 0x00FF ( module struct let % test _ = Uchar . ( is_char Uchar . min_value ) let % test _ = Uchar . ( is_char char_max ) let % test _ = Uchar . ( not ( is_char ( of_scalar_exn 0x0100 ) ) ) let % test _ = not ( Uchar . is_char Uchar .... |
let _ = print_newline ( ) ; Printf . printf " Testing union - find algorithm \ n " |
let test = let open UF . M in UF . add 0 >>= fun ( ) -> UF . add 1 >>= fun ( ) -> UF . add 2 >>= fun ( ) -> UF . add 3 >>= fun ( ) -> UF . add 4 >>= fun ( ) -> UF . find 0 >>= fun v0_repr -> UF . find 1 >>= fun v1_repr -> assert ( v0_repr <> v1_repr ) ; U... |
let ( ) = UF . M . run test |
let _ = Printf . printf " Success . \ n " |
let all_tests = ref [ ] |
let test_cnt = ref 0 |
let add_tests name tests = all_tests := ! all_tests @ [ name , tests ] |
let pos_tests = [ " a * b " , " b * a " ; " a * ( b * c ) " , " ( c * b ) * a " ; " ( a * b ) f " , " ( b * a ) f " ; " a * b -> c " , " b * a -> c " ; " ( a * b ) f * c " , " ( b * a ) f * c " ; " ( a * b ) f ... |
let neg_tests = [ " unit -> a " , " a " ; " unit -> unit -> a " , " a " ; " unit * unit -> a " , " a " ; " ( unit -> a ) * b " , " a * b " ; " ( unit -> a ) f " , " a f " ; " a -> ' a " , " x -> b -> c " ; " x * b -> c ... |
let slow_tests = [ " ' A * int list -> unit " , " anchor * bitmap * bool * bool * color * color * color * color * color * color * color * color * cursor * int * int * int * int * int * int * int * int * justification * relief * state * string * string * string -> ' a " ] |
let tests = let make_test speed res ( str1 , str2 ) = let env_query = Type . Env . make Query in let env = Type . Env . make Data in let test ( ) = let ty1 = Type . of_string env_query str1 in let ty2 = Type . of_string env str2 in let name = Fmt . str " % s ≡ % s " str1 str2 in A... |
let ( ) = add_tests " Unification . unifiable " tests |
let ( ) = Alcotest . run ~ quick_only : true ~ argv : Sys . argv " unification " ! all_tests |
let zero_obj = Caml . Obj . repr ( 0 : int ) let t = create_obj_array ~ len : 0 in assert ( length t = 0 ) ; ; let str = Caml . Obj . repr " foo " in let t = create ~ len : 2 str in assert ( phys_equal ( get t 0 ) str ) ; assert ( phys_equal ( get t 1 ) str ) ; ... |
module Sequence = struct type nonrec ' a t = ' a t type ' a z = ' a let length = length let get = get let set = set let create_bool ~ len = create ~ len false end let test a1 a2 f = let result = map2_exn ~ f ( of_list a1 ) ( of_list a2 ) in print_s [ % message ( result : int Uniform_ar... |
let t1 = Array ( Var 1 ) |
let t2 t = Fun ( Var 1 , t ) |
let t3 a b = Block ( 0 , [ a ; t1 ; t2 b ] ) |
let t4 t = t3 t t ; ; |
let t5 = Variant ( 3 , [ [ Var 1 ] ; [ Array Bool ] ; [ Var 2 ; Int ; Unit ] ] ) |
let t6 = Variant ( 3 , [ [ Var 2 ] ; [ Array Unit ] ; [ Float ; Var 1 ; Int ] ] ) |
let t7 = Block ( 0 , [ Var 1 ; Var 2 ; Int ] ) |
let t8 = Block ( 0 , [ Var 2 ; Float ; Var 1 ] ) |
let t9 a b = Fun ( a , b ) |
let b3 x y z = Block ( 0 , [ x ; y ; z ] ) |
let v3 a b c = Variant ( 0 , [ a ; b ; c ] ) |
let b2 n x y = Block ( n , [ x ; y ] ) |
let unifying a b = print_endline ( " " ^ string_of_subst ( unify [ ( a , b ) ] Subst . empty ) ) |
let merging a b = try print_endline ( " Merging " ^ string_of_ty a ^ " and " ^ string_of_ty b ) ; print_endline ( " " ^ string_of_ty ( merge_ty a b ) ) with Merge_failure -> print_endline " failed to merge " | Unification_failure -> print_endline " failed to unify " ; ; |
let testlib = Dl . ( dlopen ~ filename " : clib / libtest_functions . so " ~ flags [ : RTLD_NOW ] ) |
let test_inspecting_float _ = let module M = struct type u let utyp : u union typ = union " u " let ( ) -: ty label = field utyp label ty let f = double -: " f " let i = int64_t -: " i " let ( ) = seal utyp let pi = 3 . 14 let e = 2 . 718 let u = make utyp let ( ) = setf ... |
let test_endian_detection _ = let module M = struct type e let etyp : e union typ = union " e " let ( ) -: ty label = field etyp label ty let i = int64_t -: " i " let c = array ( sizeof int64_t ) uchar -: " c " let ( ) = seal etyp let updated_char_index = if Sys . big_endian then ... |
module Build_foreign_tests ( S : Cstubs . FOREIGN with type ' a result = ' a and type ' a return = ' a ) = struct open Functions module M = Common ( S ) open M let test_union_padding _ = let module M = struct let mkPadded : int64 -> padded union = fun x -> let u = make padded in setf u i ... |
module Build_stub_tests ( S : Cstubs . FOREIGN with type ' a result = ' a and type ' a return = ' a ) = struct open Functions include Build_foreign_tests ( S ) module N = Functions . Stubs ( S ) open N let test_passing_unions_by_value _ = let module M = struct let mkPadded : int64 -> p... |
module Build_struct_stub_tests ( S : Ctypes . TYPE with type ' a typ = ' a Ctypes . typ and type ( ' a , ' s ) field = ( ' a , ' s ) Ctypes . field ) = struct module M = Types . Struct_stubs ( S ) let retrieve_size name = let f = Foreign . foreign ~ from : testlib name... |
let test_union_address _ = let module M = struct type u let u : u union typ = union " u " let ( ) -: ty label = field u label ty let i = int64_t -: " i " let c = char -: " c " let s = ptr ( structure " incomplete " ) -: " s " let ( ) = seal u let up = addr ( make u ) l... |
let test_updating_sealed_union _ = let utyp = union " sealed " in let _ = field utyp " _ " int in let ( ) = seal utyp in assert_raises ( ModifyingSealedType " sealed " ) ( fun ( ) -> field utyp " _ " char ) |
let test_adding_fields_through_views _ = let module M = struct let union_u = union " union_u " let u = typedef union_u " u " let x = field u " x " int let y = field u " y " float let ( ) = seal u end in ( ) |
let test_sealing_empty_union _ = let empty = union " empty " in assert_raises ( Unsupported " union with no fields " ) ( fun ( ) -> seal empty ) |
let suite = " Union tests " >::: [ " inspecting float representation " >:: test_inspecting_float ; " detecting endianness " >:: test_endian_detection ; " union padding ( foreign ) " >:: Foreign_tests . test_union_padding ; " union padding ( stubs ) " >:: Stub_tests . test_u... |
let _ = run_test_tt_main suite |
let create x = let t = create x in assert ( is_compressed t ) ; t ; ; |
let union t1 t2 = union t1 t2 ; invariant ignore t1 ; invariant ignore t2 ; assert ( is_compressed t1 || is_compressed t2 ) ; ; |
let get t = let x = get t in assert ( is_compressed t ) ; x ; ; |
let set t x = set t x ; assert ( is_compressed t ) ; ; |
let same_class t1 t2 = let b = same_class t1 t2 in assert ( is_compressed t1 ) ; assert ( is_compressed t2 ) ; b ; ; let a = create 1 in let b = create 2 in assert ( not ( same_class a b ) ) ; union a b ; assert ( same_class a b ) ; let c = create 3 in assert ( not ( same_c... |
let impl_tests = let valid_test = { | |
let fooooooooooooooo = let fooooooooooooo = let foooooooooooooo = foooooooooooooo in fooooo , fooooooo in fooooooooooooooooo ; foooooooooooooo } | in let invalid_after_eq_test = { | let fooooooooooooooo } =| in let invalid_after_in_test = { | |
let fooooooooooooooooooooo = let foooooooooooooooooooo = let foooooooooooooooo = foooooooo in foooooo in } | in let invalid_seq_modules_test = { | |
module M = struct let foooooo = foooo let foooooooooooooo = let foooooooooooo = fooooo end } | in let not_closed_module_test = { | |
module M = struct let foo = foo let foo = } | in let not_closed_module_test_2 = { | |
module M = struct let foo = foo in let not_closed_sig = { | |
module K : sig type t let not_closed_begin = { | let x = if x then begin a } | in let not_closed_if = { | let x = if k } | in let not_closed_if_2 = { | let x = if k then } | in let invalid_if = { | let x = if k then else } | in let invalid_if_2 = { | let x = if k then x else } |... |
module K = struct let k ; ; begin let x = in ( ) ; ; |
let foooooo = fooooo foooooooo |
let k = } | in let _escape_error = { | let _expecting = { | |
let f = function | 3 as 3 -> ( ) ; ; |
let f = function | 3 :: -> ( ) ; ; |
let f = function | 3 | -> ( ) ; ; |
let f = function | List . ( -> ( ) ; ; |
let f = function | ( 3 : 3 ) -> ( ) ; ; |
let f = function | ( 3 , ) -> ( ) ; ; |
let f = function | ( -> ( ) ; ; |
let f = function | ( module -> ( ) ; ; } | in let _pr7847 = { | external x : unit -> ( int , int ) ` A . t = " x " } | in let unclosed_class_simpl_expr1 = { | method x = 1 let _unclosed_class_simpl_expr2 = { | class c = ( object end : object end } | in let _unc... |
let f = function | List . ( _ ; ; |
let f = function | ( _ ; ; |
let f = function | ( _ : int ; ; |
let f = function | ( module Foo : sig end ; ; |
let f = function | { foo ; bar ; ; ; |
let f = function | [ 1 ; 2 ; ; ; |
let f = function | [ | 3 ; 4 ; ; ; } | in let unclosed_struct = { | |
module M = struct type t = T [ ( " empty " , " " , [ ] ) ; ( " valid " , valid_test , [ ] ) ; ( " invalid after eq " , invalid_after_eq_test , [ ( ( 1 , 0 ) , ( 1 , 22 ) ) ] ) ; ( " invalid after in " , invalid_after_in_test , ... |
let intf_tests = let _unclosed_class_signature = { | class c : object } | in let _unclosed_paren_module_type = { | module M : ( sig end } | in let unclosed_sig = { | |
module M : sig type t = T } | in [ ( " empty " , " " , [ ] ) ; ( " unclosed sig " , unclosed_sig , [ ( ( 2 , 0 ) , ( 3 , 12 ) ) ] ) ; ] |
let check_tests checker tests = List . map ( fun ( name , input , locs ) -> ( name , ` Quick , fun ( ) -> checker ~ name ~ input ~ locs ) ) tests |
let tests = [ ( " impl " , check_tests Utils . check_impl impl_tests ) ; ( " intf " , check_tests Utils . check_intf intf_tests ) ; ( " use_file " , check_tests Utils . check_use_file impl_tests ) ; ] |
let ( ) = Alcotest . run " Parse_wyc " tests |
( module struct let size = Key . create ~ name " : size " Int . sexp_of_t let name = Key . create ~ name " : name " String . sexp_of_t let foo = Key . create ~ name " : foo " Float . sexp_of_t let kids = Key . create ~ name " : kids " ( List . sexp_of_t sexp_of_t ) let ... |
module With_default = struct open ! With_default let % test_unit _ = let key = Key . create ~ default : 0 ~ name " : default 0 " Int . sexp_of_t in assert ( find empty key = 0 ) ; let t = set empty key 1 in assert ( find t key = 1 ) ; let t = set empty key 2 in assert ( find t ... |
module With_fold = struct open ! With_fold let % test_unit _ = let key = Key . create ~ init : 5 ~ f ( : + ) ~ name " : init 5 " Int . sexp_of_t in assert ( find empty key = 5 ) ; let t = add empty key 3 in assert ( find t key = 8 ) ; let t = change t key ~ f ( : ~- ) ... |
module Multi = struct open ! Multi let % test_unit _ = let key = Key . create ~ name " : int list " Int . sexp_of_t in assert ( find empty key = [ ] ) ; let t = add empty key 1 in assert ( find t key = [ 1 ] ) ; let t = set t key [ 2 ; 3 ] in assert ( find t key = [ ... |
let test_udp_send_recv packet = let open Osc_unix . Udp in let localhost = Unix . inet_addr_of_string " 127 . 0 . 0 . 1 " in let port = 4568 in let addr = Unix . ADDR_INET ( localhost , port ) in let buffer_length = 1024 in bracket ( fun ( ) -> let client = Client . create ( ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.