text stringlengths 12 786k |
|---|
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 ) ( ) ; Serv... |
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... |
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 ... |
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... |
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 . ... |
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 . ... |
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 ~ timestam... |
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 ... |
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 ( ) ... |
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 ;... |
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... |
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 " ) ... |
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_ed... |
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... |
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... |
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 " ... |
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 no... |
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_unle... |
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 ' sat... |
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 satur... |
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 " " ) ) ) ... |
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 . ... |
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 _ -> fa... |
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 shi... |
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 \ x0... |
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... |
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 . ... |
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 . ... |
type tree = | Node of ( int * tree list ) | Leaf of int |
let node , leaf = Schema . ( fix ( fun recursive -> recursive . obj " Node " ~ fields ( : fun ( node , _leaf ) -> [ field " children " ~ typ ( : non_null ( list ( non_null node ) ) ) ~ args [ ] : ~ resolve ( : fun { ctx = ( ) } t -> match t with | Nod... |
let list_to_seq n l = let rec aux n l ( ) = match ( n , l ) with | _ , [ ] | 0 , _ -> Seq . Nil | _ , x :: tail -> Seq . Cons ( x , aux ( n - 1 ) tail ) in aux n l |
let schema = Schema . ( schema [ field " tree " ~ typ ( : non_null node ) ~ args [ ] : ~ resolve ( : fun _ ( ) -> Node ( 0 , [ Node ( 1 , [ Leaf 2 ] ) ] ) ) ; field " users " ~ typ ( : non_null ( list ( non_null user ) ) ) ~ args : Arg . ... |
let a = Sci . format [ | Sci . num_2 ; Sci . num_1 ; Sci . num_0 ] | ; ; |
let b = Sci . format [ | Sci . num_1 ; Sci . num_2 ; Sci . num_0 ] | ; ; |
let c = Sci . format [ | Sci . num_4 ; Sci . num_0 ; Sci . num_4 ] | ; ; |
let d = Sci . format [ | Sci . num_2 ; Sci . num_1 ; Num . minus_num Sci . num_1 ] | ; ; |
let e = Sci . format [ | Sci . num_1 ; Sci . num_2 ; Num . minus_num Sci . num_1 ] | ; ; |
let m = Sci . square_module a ; ; |
let n = Sci . plus a b ; ; |
let o = Sci . plus b a ; ; |
let p = Sci . plus a d ; ; |
let q = Sci . minus a d ; ; |
let r = Sci . mult a d ; ; |
let s = Sci . div a d ; ; |
let t = Sci . int_pow 800 a ; ; |
let u = Sci . sci_fact ( Num . num_of_int 69 ) ; ; |
let pi = Sci . sci_approx_pi 50 ; ; |
let ipi = Sci . sci_approx_ipi 50 ; ; |
let v = Sci . sci_of_complex [ | [ | 1 . ; 2 . ] | ; [ | - 2 . ; 1 . ] | ] | ; ; |
let maf = Sci . sci_of_num Sci . num_2_pow_1024 ; ; |
let mmff = Sci . int_pow 65536 maf ; ; |
let r = Sci . real_sqrt_1024 Sci . sci_2 ; ; |
let r0 = Sci . complex_of_sci ( Sci . sqrt_1024 Sci . sci_2i ) ; ; |
let r1 = Sci . complex_of_sci ( Sci . sqrt_1024 ( Sci . sci_of_float ( - 0 . 75 ) ) ) ; ; |
let sol = Sci . solve_degree_2_1024 Sci . sci_1 Sci . sci_1 Sci . sci_1 ; ; |
let sol0 = Array . map Sci . complex_of_sci sol ; ; |
let z = Sci . plus_1024 Sci . half_pi_1000_10 Sci . half_pi_1000_10 ; ; |
let y = Sci . mult_1024 Sci . half_pi_1000_10 Sci . pi_1000_10 ; ; |
let x = Sci . mult Sci . pi_1000_10 Sci . half_pi_1000_10 ; ; |
let rr = Sci . int_pow_1024 2 r ; ; |
let a0 = [ [ || 0 . 999537131586786143 ; - 1 . 22955137826996658e - 19 ] | ; [ | 1 . 22955137826996658e - 19 ; 0 . 999537131586786143 ] ] ; ; || |
let b0 = [ [ || 0 . 999845450393193 ; - 4 . 10992935015358837e - 20 ] | ; [ | 4 . 10992935015358837e - 20 ; 0 . 999845450393193 ] ] || ; ; |
let c0 = [ [ || 0 . 999948456937 ; - 1 . 37138697602e - 20 ] | ; [ | 1 . 37138697602e - 20 ; 0 . 999948456937 ] ] || ; ; |
let aA = Sci . sci_of_complex a0 ; ; |
let bB = Sci . sci_of_complex b0 ; ; |
let cC = Sci . sci_of_complex c0 ; ; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.