text stringlengths 12 786k |
|---|
let equal_float x y = match classify_float x , classify_float y with | FP_infinite , FP_infinite -> x = y | FP_nan , FP_nan -> true | _ , _ -> abs_float ( x . - y ) <= epsilon . * ( abs_float x . + abs_float y ) ; ; |
module Alcotest_ext = struct let hstore = Alcotest . testable pp_hstore equal_hstore let inet = Alcotest . testable pp_inet equal_inet let value = Alcotest . testable pp_value equal_value let uuid = Alcotest . testable Uuidm . pp Uuidm . equal let our_float = Alcotest . testable Format . pp_print_... |
let make_test name typ to_value of_value of_value_exn values fail_values = let fail_tests = Alcotest . test_case " null required input " ` Quick ( fun ( ) -> Alcotest . check_raises " non - null conversion " ( Conversion_failure " Expected not - null but got null " ) ( fun ( ) ->... |
let ( ) = let all_chars = String . init 255 char_of_int in Alcotest . run " Pgx . Value " [ make_test " binary " Alcotest . string of_binary to_binary to_binary_exn [ " " ; " normal string " ; " string with null \ x00 in the midddle " ; all_chars ] [ ] ; make_test "... |
let time_roundtrip str = Value . of_string str |> Value . to_time_exn |
let printer = Time . to_string_abs ~ zone : Time . Zone . utc |
let time_testable = Alcotest . testable ( fun ppf t -> Format . pp_print_string ppf ( printer t ) ) Time . equal ; ; |
let check_time = Alcotest . check time_testable |
let check_string = Alcotest . ( check string ) |
let test_time_of_string _ = let expected = Time . of_string " 2016 - 03 - 15 19 : 55 : 18 . 123456 - 04 : 00 " in check_time " without TZ " expected ( time_roundtrip " 2016 - 03 - 15 23 : 55 : 18 . 123456 " ) ; check_time " zulu " expected ( time_roundtrip " ... |
let test_time_of_string_no_ms _ = let expected = Time . of_string " 2016 - 03 - 15 19 : 55 : 18 - 04 : 00 " in check_time " without TZ " expected ( time_roundtrip " 2016 - 03 - 15 23 : 55 : 18 " ) ; check_time " zulu " expected ( time_roundtrip " 2016 - 03 - 15... |
let test_time_conversion_roundtrip _ = let expected_str = " 2016 - 03 - 15 23 : 55 : 18 . 123456Z " in check_string " parse - print " expected_str ( time_roundtrip expected_str |> printer ) ; let expected_time = Time . of_string expected_str in check_time " print - parse " expect... |
let time_tests = [ Alcotest . test_case " test time_of_string " ` Quick test_time_of_string ; Alcotest . test_case " test time_of_string no milliseconds " ` Quick test_time_of_string_no_ms ; Alcotest . test_case " test time conversion roundtrip " ` Quick test_time_conversion_roundtrip ] ... |
let ( ) = Alcotest . run " pgx_async_conversions " [ " time " , time_tests ] |
let print_time ( t , tz_offset_s ) = let sec = Ptime . to_float_s t and txt = Ptime . to_rfc3339 t ~ tz_offset_s ~ frac_s : 6 in Printf . sprintf " <% s | Seconds : % f , Offset : % d " > txt sec tz_offset_s ; ; |
let value_testable = let print_time value = match Pgx . Value . to_string value with | Some text -> text | None -> " < None " > in let formatter ppf value = Format . pp_print_string ppf ( print_time value ) in Alcotest . testable formatter ( = ) ; ; |
let check_value = Alcotest . check value_testable |
let test_to_date _ = let check_date = Alcotest . ( check ( triple int int int ) ) in let value = Pgx . Value . of_string " 2021 - 11 - 14 " in let expected = 2021 , 11 , 14 in check_date " check date parsing " expected ( Value . to_date_exn value ) ; let value = Pgx . V... |
let test_of_date _ = let date = 2021 , 11 , 14 in let expected = Pgx . Value . of_string " 2021 - 11 - 14 " in check_value " check date rendering " expected ( Value . of_date date ) ; let date = 900 , 6 , 13 in let expected = Pgx . Value . of_string " 0900 - 06 - 1... |
let date_tests = [ Alcotest . test_case " of_date renders a Ptime date to a Pgx Value " ` Quick test_of_date ; Alcotest . test_case " to_date parses a Pgx Value to a Ptime date " ` Quick test_to_date ] ; ; |
let check_time = let compare_times ( t1 , o1 ) ( t2 , o2 ) = let tf1 = Ptime . to_float_s t1 and tf2 = Ptime . to_float_s t2 in abs_float ( tf1 . - tf2 ) < 1 . 0e - 6 && o1 = o2 in let time_testable = Alcotest . testable ( fun ppf t -> Format . pp_print_string ppf ( print_t... |
let test_time_of_string _ = let hour = 3600 in let hourf = 3600 . in let to_pt x = Ptime . of_float_s x |> Option . value ~ default : Ptime . min in check_time " minimum time parses " ( Ptime . min , 0 ) ( Value . time_of_string " 0000 - 01 - 01T00 : 00 : 00Z " ) ; le... |
let time_roundtrip str = Value . of_string str |> Value . to_time_exn |
let test_time_tz_handling _ = let utc_t , tz_offset_s = Value . time_of_string " 2016 - 03 - 15 19 : 55 : 18 - 04 : 00 " in check_time " without TZ " ( utc_t , 0 ) ( time_roundtrip " 2016 - 03 - 15 23 : 55 : 18 " ) ; check_time " zulu " ( utc_t , 0 ) ( ... |
let test_time_conversion_roundtrip _ = let print_time ( t , tz_offset_s ) = Ptime . to_rfc3339 t ~ tz_offset_s ~ frac_s : 6 in let expected_str = " 2016 - 03 - 15T23 : 55 : 18 . 123456Z " in Alcotest . ( check string ) " parse - print " expected_str ( time_roundtrip expected... |
let time_tests = [ Alcotest . test_case " test time_of_string " ` Quick test_time_of_string ; Alcotest . test_case " test time_of_string time zone handling " ` Quick test_time_tz_handling ; Alcotest . test_case " test time conversion roundtrip " ` Quick test_time_conversion_roundtrip ] ... |
let ( ) = Alcotest . run " pgx_async_conversions " [ " date " , date_tests ; " time " , time_tests ] |
let count = Some 1000 |
let test_flush ( ) = let l = QCheck2 . Gen . generate ~ n ( : Option . value ~ default : 1 count ) ( QCheck2 . Gen . pair Generators . filter_state_with_operation_gen QCheck2 . Gen . bool ) in List . iter_es ( fun ( ( filter_state , ( ( op_info : manager_op_info ) , ... |
let ( ) = Alcotest_lwt . run " Plugin " [ ( " on_flush " , [ Tztest . tztest " [ on_flush ~ validation_state . . . ] yields an empty state " ` Quick test_flush ; ] ) ; ] |> Lwt_main . run |
let show ( ) = print_s [ % message " " ~ point ( : get ( ) : Position . t ) ] Current_buffer . set_temporarily_to_temp_buffer Sync ( fun ( ) -> show ( ) ; [ % expect { | ( point 1 ) } ] ; | print_s [ % sexp ( Current_buffer . get ( ) : Buffer . t... |
let testlib = Dl . ( dlopen ~ filename " : clib / libtest_functions . so " ~ flags [ : RTLD_NOW ] ) |
module Common_tests ( S : Cstubs . FOREIGN with type ' a result = ' a and type ' a return = ' a ) = struct module M = Functions . Stubs ( S ) open M let test_passing_pointers _ = assert_equal ~ msg " : Passing pointers to various numeric types " ~ printer : string_of_int ( 1 + 2 ... |
let test_pointer_assignment_with_primitives _ = let open Signed in let open Unsigned in let p_char = allocate char ' 1 ' and p_uchar = allocate uchar ( UChar . of_int 2 ) and p_bool = allocate bool false and p_schar = allocate schar 3 and p_float = allocate float 4 . 0 and p_double = allocate d... |
let test_dereferencing_pointers_to_incomplete_types _ = begin assert_raises IncompleteType ( fun ( ) -> !@ null ) ; assert_raises IncompleteType ( fun ( ) -> ( !@ from_voidp ( structure " incomplete " ) null ) ) ; assert_raises IncompleteType ( fun ( ) -> ( !@ from_voidp ... |
let test_writing_through_pointer_to_abstract_type _ = let module Array = CArray in let arra = Array . make int 2 in let arrb = Array . make int 2 in let absptr a = from_voidp ( abstract ~ name " : absptr " ~ size ( : 2 * sizeof int ) ~ alignment ( : alignment ( array 2 int ) ) ) ... |
let test_reading_and_writing_global_value _ = let ptr = foreign_value " global " int ~ from : testlib in let ptr ' = foreign_value " global " int ~ from : testlib in assert_equal ( !@ ptr ) 100 ; ptr <-@ 200 ; assert_equal ( !@ ptr ) 200 ; assert_equal ( !@ ptr ' ) 200 ; ... |
let test_reading_strings _ = let p = allocate_n char 26 in begin StringLabels . iteri " abcdefghijklmnoprwstuvwxyz " ~ f ( : fun i c -> ( p +@ i ) <-@ c ) ; assert_equal ( string_from_ptr p 5 ) " abcde " ; assert_equal ( string_from_ptr p 26 ) " abcdefghijklmnoprwstuvwxyz " ... |
let test_pointer_arithmetic _ = let module Array = CArray in let arr = Array . of_list int [ 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ] in let p = Array . start arr in for i = 0 to 7 do assert_equal ( !@ p +@ i ) ( succ i ) done ; let twoints = structure " s " in let i1 = fi... |
let test_pointer_comparison _ = let canonicalize p = let buf = allocate_n ~ count : 1 ( ptr void ) in buf <-@ ( to_voidp p ) ; !@ buf in let ( ) < l r = ptr_compare l r < 0 and ( ) > l r = ptr_compare l r > 0 and ( ) = l r = ptr_compare l r = 0 in let p = allocate int 10 in ... |
let test_pointer_differences _ = let canonicalize p = let buf = allocate_n ~ count : 1 ( ptr void ) in buf <-@ ( to_voidp p ) ; !@ buf in let s = structure " s " in let ( ) -: ty label = field s label ty in let i = int -: " i " in let j = array 17 char -: " j " in let k = dou... |
let test_raw_pointers _ = let p : float ptr = allocate double 1 . 0 in let p ' = p +@ 3 in let praw = raw_address_of_ptr ( to_voidp p ) in let praw ' = raw_address_of_ptr ( to_voidp p ' ) in assert_equal praw ' Nativeint . ( add praw ( of_int ( 3 * sizeof double ) ) ) |
let suite = " Pointer tests " >::: [ " passing pointers ( foreign ) " >:: Foreign_tests . test_passing_pointers ; " passing pointers ( stubs ) " >:: Stub_tests . test_passing_pointers ; " passing pointers to pointers ( foreign ) " >:: Foreign_tests . test_passing_pointers_to... |
let _ = run_test_tt_main suite |
module Node = P2p . Node . Make ( Node_id ) |
module Group = P2p . Group . Make ( Group_id ) |
module View = P2p . View . Make ( Node_id ) ( Node ) |
module Ringcast = P2p_ringcast . Make ( Node_id ) ( Node ) ( View ) ( Msg_id ) |
module Poldercast = P2p_poldercast . Make ( Node_id ) ( Group_id ) ( Node ) ( Group ) ( View ) ( Msg_id ) ( Ringcast ) |
let test_sub _ctx = printf " \ nPOLDERCAST SUB \ n " ; let sub = Sub . add ( Group . init ( u64 11L ) ) ( ) ( Sub . add ( Group . init ( u64 23L ) ) ( ) ( Sub . add ( Group . init ( u64 37L ) ) ( ) ( Sub . add ( Group . init ( u64 41L ) ) ... |
let suite = " suite " >::: [ " sub " >:: test_sub ; ] |
let ( ) = Nocrypto_entropy_unix . initialize ( ) ; run_test_tt_main suite |
module Node = P2p . Node . Make ( Node_id ) |
module Group = P2p . Group . Make ( Group_id ) |
module View = P2p . View . Make ( Node_id ) ( Node ) |
module Ringcast = P2p_ringcast . Make ( Node_id ) ( Node ) ( View ) ( Msg_id ) |
module Poldercast = P2p_poldercast . Make ( Node_id ) ( Group_id ) ( Node ) ( Group ) ( View ) ( Msg_id ) ( Ringcast ) |
let sent_msgs = Hashtbl . create 3 |
module UView = struct type t = { rings : ( Group_id . t , View . t ) Hashtbl . t ; } let create = { rings = Hashtbl . create 10 } let set_ring t gid view = Hashtbl . replace t . rings gid view let view t = Hashtbl . fold ( fun _gid view uview -> View . union uview view ) t ... |
module Io = struct module IoMap = Map . Make ( Node ) type t = { group : Group . t ; me : Node . t ; uview : UView . t ; io : ( Lwt_io . input_channel * Lwt_io . output_channel ) IoMap . t ; } let init me uview = ( fun group -> { group ; me ; uview ; io = IoMap . ... |
module Ringcast_lwt = P2p_ringcast_lwt . Make ( Node_id ) ( Node ) ( View ) ( Msg_id ) ( Ringcast ) ( Io ) |
module Poldercast_lwt = P2p_poldercast_lwt . Make ( Node_id ) ( Group_id ) ( Node ) ( Group ) ( View ) ( Msg_id ) ( Ringcast ) ( Io ) ( Ringcast_lwt ) ( Poldercast ) |
let _ = Nocrypto_entropy_lwt . initialize ( ) |
let ( ) = let view_len = 8 in let xchg_len = 4 in let period = 1 . 0 in let fanout = 5 in let seen_len = 10 in let me = Node . init ( u64 100L ) in let group1 = Group . init ( u64 1000L ) in let view1 = View . add ( Node . init ( u64 110L ) ) ( View . add ( Node . ... |
type flt_temp = [ ` FLT_TEMP of int ] int |
type vec_temp = [ ` VEC_TEMP of int ] int |
type any_temp = [ flt_temp | vec_temp ] vec_temp |
let any1 : any_temp -> string = function | ` FLT_TEMP x -> sprintf " t % d : float " x | ` VEC_TEMP x -> sprintf " t % d : vector " x |
let any2 : [ < any_temp ] any_temp -> string = function | ` FLT_TEMP x -> sprintf " t % d : float " x | ` VEC_TEMP x -> sprintf " t % d : vector " x |
type operation = [ ` DIVISION of flt_temp * flt_temp ` | DOT_PRODUCT of vec_temp * vec_temp ] |
let e2 : operation -> any_temp list = function | ` DIVISION ( DIVISIONa , b ) b -> [ ( a :> any_temp ) any_temp ; ( b :> any_temp ) any_temp ] | ` DOT_PRODUCT ( DOT_PRODUCTa , b ) b -> [ ( a :> any_temp ) any_temp ; ( b :> any_temp ) any_temp ] |
type gen_operation = [ ` DIVISION of any_temp * any_temp ` | DOT_PRODUCT of any_temp * any_temp ] |
let e3 ( x : operation ) operation = match ( x : operation :> gen_operation ) gen_operation with | ` DOT_PRODUCT ( DOT_PRODUCTa , b ) b | ` DIVISION ( DIVISIONa , b ) b -> [ a ; b ] b |
module Records_we_can_handle = struct type ( ' a , ' b ) t = { not_first_class_tick_a : ' a ; b : ' a . ' b ; int : ' a . int ; either : ' a . ' a option ; polymorphic_variant : ' a . [ ` A of ' a | ` B of ' b | ` Int of int ] } [ @@ deriving_inline ... |
module Impossible_record = struct type t = { a : ' a . ' a } [ @@ deriving_inline sexp_grammar ] let _ = fun ( _ : t ) -> ( ) let ( t_sexp_grammar : Ppx_sexp_conv_lib . Sexp . Private . Raw_grammar . t ) = let ( _the_generic_group : Ppx_sexp_conv_lib . Sexp . Private... |
module Inline_record = struct type ' a t = | Non_poly of { a : ' a } | Poly of { a : ' a . ' a } [ @@ deriving_inline sexp_grammar ] let _ = fun ( _ : ' a t ) -> ( ) let ( t_sexp_grammar : Ppx_sexp_conv_lib . Sexp . Private . Raw_grammar . t ) = let ( _the_gen... |
module Nullary = struct type ' a t = [ ` A | ` B ] [ @@ deriving_inline sexp_grammar ] let _ = fun ( _ : ' a t ) -> ( ) let ( t_sexp_grammar : Ppx_sexp_conv_lib . Sexp . Private . Raw_grammar . t ) = let ( _the_generic_group : Ppx_sexp_conv_lib . Sexp . Private . ... |
module With_arguments = struct module With_sexp = struct type t = [ ` A of int * int | ` B of string ] [ @@ deriving sexp_of ] end type t = [ ` A of int * int | ` B of string ] [ @@ deriving_inline sexp_grammar ] let _ = fun ( _ : t ) -> ( ) let ( t_sexp_grammar : Ppx_s... |
module Sexp_list = struct module With_sexp = struct type t = [ ` Int of int | ` List of int list | ` Sexp_dot_list of int list [ @ sexp . list ] | ` Sexp_list of int sexp_list [ @ warning " - 3 " ] ] [ @@ deriving sexp ] end type t = [ ` Int of int | ` List of int list ... |
type ' a t = ' a Array_wrap . t |
let write__1 write__a = ( Atdgen_runtime . Oj_run . write_list ( write__a ) ) |
let string_of__1 write__a ( ? len = 1024 ) x = let ob = Bi_outbuf . create len in write__1 write__a ob x ; Bi_outbuf . contents ob |
let read__1 read__a = ( Atdgen_runtime . Oj_run . read_list ( read__a ) ) |
let _1_of_string read__a s = read__1 read__a ( Yojson . Safe . init_lexer ( ) ) ( Lexing . from_string s ) |
let write__2 write__a = ( fun ob x -> ( let x = ( Array_wrap . unwrap ) x in ( write__1 write__a ) ob x ) ) |
let string_of__2 write__a ( ? len = 1024 ) x = let ob = Bi_outbuf . create len in write__2 write__a ob x ; Bi_outbuf . contents ob |
let read__2 read__a = ( fun p lb -> let x = ( read__1 read__a ) p lb in ( Array_wrap . wrap ) x ) |
let _2_of_string read__a s = read__2 read__a ( Yojson . Safe . init_lexer ( ) ) ( Lexing . from_string s ) |
let write_t write__a = ( write__2 write__a ) |
let string_of_t write__a ( ? len = 1024 ) x = let ob = Bi_outbuf . create len in write_t write__a ob x ; Bi_outbuf . contents ob |
let read_t read__a = ( read__2 read__a ) |
let t_of_string read__a s = read_t read__a ( Yojson . Safe . init_lexer ( ) ) ( Lexing . from_string s ) |
( module struct module Hashtbl = Pooled_hashtbl . Make ( struct include Int let hash x = x end ) let % test_unit " growing test / copy test " = let n = 100_000 in let tbl = Hashtbl . create ~ size : 16 ( ) in for i = 0 to n - 1 do Hashtbl . set tbl ~ key : i ~ data : i done ; le... |
module Resource = struct let ht = Hashtbl . create 17 let c = ref 0 let create ( ) = if Random . int 4 = 0 then Lwt . return_error ( ) else begin c := succ ! c ; Hashtbl . add ht ! c ( ) ; Lwt . return_ok ! c end let free i = assert ( Hashtbl . mem ht i ) ; Hashtbl . re... |
let test_n n = let max_idle_size = Random . int 11 in let max_size = max 1 ( max_idle_size + Random . int 5 ) in let pool = Pool . create ~ max_idle_size ~ max_size Resource . create Resource . free in let wakers = Array . make n None in let wait_count = ref 0 in let wait_count_cond = Lwt_... |
let test _ ( ) = test_n 0 >>= fun ( ) -> test_n 1 >>= fun ( ) -> let rec loop n_it = if n_it = 0 then Lwt . return_unit else test_n ( Random . int ( 1 lsl Random . int 12 ) ) >>= fun ( ) -> loop ( n_it - 1 ) in loop 500 |
let test_cases = [ Alcotest_lwt . V1 . test_case " basic usage " ` Quick test ; ] |
let test ~ op ~ op_name ~ to_string x = printf " % s % s = % d \ n " op_name ( to_string x ) ( op x ) let open Int64 in let numbers = [ 0L ; 1L ; 7L ; max_value ; min_value ; - 1L ] in let f = test ~ op : Ocaml_intrinsics . Int64 . count_set_bits ~ op_name " : popcnt ... |
let test_int n bits = [ % test_result : int ] ( Int . popcount n ) ~ expect : bits |
let test_int32 n bits = [ % test_result : int ] ( Int32 . popcount n ) ~ expect : bits |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.