text
stringlengths
12
786k
let fail = Fail None
let error msg = Fail ( Some msg )
let test_infer = [ ]
let test_infer_and_syntax = [ ]
let normalize ty_str = string_of_s_ty ( Parser . ty_forall_eof Lexer . token ( Lexing . from_string ty_str ) )
let cmp_result result1 result2 = match ( result1 , result2 ) with
let make_single_test_case check_typed_syntax ( code , expected_result ) = try in try end
let extract_exact model = match exact_inference model with | Primitive xs -> let supp = match Primitive . support xs with | DiscreteFinite xs -> xs | _ -> raise Undefined in List . map supp ~ f ( : fun x -> ( x , ( Primitive . pdf xs ) x ) ) | _ -> [ ]
let test_exact_inference_grass ( ) = let grass_model ' = let * cloudy = bernoulli 0 . 5 in let * rain = bernoulli ( if cloudy then 0 . 8 else 0 . 2 ) in let * sprinkler = bernoulli ( if cloudy then 0 . 1 else 0 . 5 ) in let wet_grass = rain || sprinkler in condition wet_grass...
let test_exact_inference_adding ( ) = let model = let * x = discrete_uniform [ 0 ; 1 ] in let * y = discrete_uniform [ 0 ; 1 ] in condition ( x = 1 ) ( return ( x + y ) ) in let x = extract_exact model in let x = List . sort x ~ compare ( : fun ( a , _ ) ( b , ...
let test_exact_inference_no_condition ( ) = let dist = bernoulli 0 . 5 in let model = let * x = dist in return x in let x = extract_exact model in let x = List . sort x ~ compare ( : fun ( a , _ ) ( b , _ ) -> Bool . compare a b ) in Alcotest . ( check ( list ( pair bool ...
let infer_strats = [ MH 100 ; PC 100 ; Prior ; SMC 100 ; PIMH 100 ; Importance 100 ; Rejection ( 100 , Hard ) ; Rejection ( 100 , Soft ) ; Prior ; Enum ; Forward ; ]
let inf_with_desc = List . map infer_strats ~ f ( : fun x -> ( x , show_infer_strat x ) )
let inferred = sample @@ mh_sampler 100 Unit_test_models . single_coin
let inferred ' = sample @@ mh ' ' 100 Unit_test_models . single_coin
type model = F of float dist | B of bool dist
let models = Unit_test_models . [ ( B grass_model , " sprinkler " ) ; ( F single_coin , " coin " ) ]
let isf = function F _ -> true | _ -> false
let isb = function B _ -> true | _ -> false
let inference_tests = List . map models ~ f ( : fun ( model , model_desc ) -> List . map inf_with_desc ~ f ( : fun ( inf , desc ) -> ( desc ^ " , model " : ^ model_desc , ` Quick , fun ( ) -> if Poly . ( ( isf model && inf = Enum ) || ( isb model && inf = ...
let test_print ( ) = Alcotest . ( check pass ) " printing " ( List . map infer_strats ~ f ( : fun i -> ( print_infer_strat i , print_infer_strat_short i ) ) ) [ ]
let tests : unit Alcotest . test list = [ ( " exact inference " , [ ( " adding model " , ` Quick , test_exact_inference_adding ) ; ( " grass model " , ` Quick , test_exact_inference_grass ) ; ( " no conditioning " , ` Quick , test_exact_inference_no_condition ...
print_endline ( to_string_hum ( of_exn ( Failure " foo " ) ) ) ; [ % expect { | ( Failure foo ) } ] | ; ; print_endline ( to_string_hum ( tag ( of_string " b " ) ~ tag " : a " ) ) ; [ % expect { | ( a b ) } ] | ; ; print_endline ( to_stri...
let of_strings strings = of_list ( List . map ~ f : of_string strings )
let nested = of_list ( List . map ~ f : of_strings [ [ " a " ; " b " ; " c " ] ; [ " d " ; " e " ; " f " ] ; [ " g " ; " h " ; " i " ] ] ) ; ; print_endline ( to_string_hum nested ) ; [ % expect { | ( a b c d e f g h i ) } ...
let round t = let sexp = sexp_of_t t in require [ % here ] ( Sexp . ( = ) sexp ( sexp_of_t ( t_of_sexp sexp ) ) ) ; ; tag_arg ( of_string " hello " ) " tag " 13 [ % sexp_of : int ] |> sexp_of_t |> print_s ; [ % expect { | ( tag 13 hello ) } ] | ; ; ...
let test_s_create ctxt = let tmpdir = bracket_tmpdir ctxt in let inotify = Inotify . create ( ) in Unix . set_nonblock inotify ; let watch = Inotify . add_watch inotify tmpdir [ Inotify . S_Create ] in FileUtil . touch ( Printf . sprintf " % s / test " tmpdir ) ; assert_equal [ w...
let test_s_create_blocking ctxt = let tmpdir = bracket_tmpdir ctxt in let inotify = Inotify . create ( ) in let watch = Inotify . add_watch inotify tmpdir [ Inotify . S_Create ] in ( ) |> Thread . create ( fun ( ) -> Unix . sleep 1 ; FileUtil . touch ( Printf . sprintf " % ...
let test_s_move ctxt = let tmpdir = bracket_tmpdir ctxt in let inotify = Inotify . create ( ) in Unix . set_nonblock inotify ; let watch = Inotify . add_watch inotify tmpdir [ Inotify . S_Move ] in FileUtil . touch ( Printf . sprintf " % s / foo " tmpdir ) ; FileUtil . mv ( Pri...
let test_error ctxt = let tmpdir = bracket_tmpdir ctxt in let inotify = Inotify . create ( ) in let tmpfile = Printf . sprintf " % s / nonexistent " tmpdir in assert_raises ( Unix . Unix_error ( Unix . ENOENT , " inotify_add_watch " , tmpfile ) ) ( fun ( ) -> Inotify . add...
let test_nonblock ctxt = let tmpdir = bracket_tmpdir ctxt in let inotify = Inotify . create ( ) in Unix . set_nonblock inotify ; let _ = Inotify . add_watch inotify tmpdir [ Inotify . S_Create ] in assert_raises ( Unix . Unix_error ( Unix . EAGAIN , " read " , " " ) ) ( ...
let suite = " Test Inotify " >::: [ " Test S_Create watch " >:: test_s_create ; " Test blocking watch " >:: test_s_create_blocking ; " Test S_Move watch " >:: test_s_move ; " Test error handling " >:: test_error ; " Test nonblocking mode " >:: test_nonblock ; ]
let _ = run_test_tt_main suite
let ok = wrong_k " failed "
let tests = [ ( " input . xml " >:: fun _ -> expect_error ( 4 , 2 ) ( ` Bad_token ( " U + 0000 " , " input " , " out of range " ) ) begin fun report -> let s , get_location = string " fo \ no \ xc2 \ xa0ba \ rr \ xa0ba \ r \ nz \ x00quux " |> utf_8 |> ...
let examples = [ " C - c " ; " C - M - q " ; " < f5 " ; > " C -< f5 " ; > " C -< right " ; > " < mouse - 2 " ; > " C -< down - mouse - 3 " > ] ; ; List . iter examples ~ f ( : fun example -> print_s [ % message " " ~ _ : example ~ _ (...
let start_timer label = print_endline [ % string " start { -% label } " ]
let stop_timer label = print_endline [ % string " stop { -% label } " ]
let test_location_reference_point = ref [ % here ]
let test_start here = test_location_reference_point := here
let add_graph_info_nodes buffer graph_info = Map . iteri graph_info . Graph_info . info ~ f ( : fun ~ key ~ data -> let node_type = data . Graph_info . Node_info . node_type in let node_id = [ % string " " { \% Node_path . to_string key } " " ] \ in Buffer . add_string buffe...
let graph_info_to_dot filename graph_info = let buffer = Buffer . create 1024 in Buffer . add_string buffer " digraph { \ n " ; add_graph_info_nodes buffer graph_info ; Map . iteri graph_info . Graph_info . dag ~ f ( : fun ~ key : from ~ data : to_ -> List . iter to_ ~ f ( : fun t...
let print_graph_info ( graph_info : Graph_info . t ) = let with_line_and_column_string id = let id_string = Node_path . to_string id in match Map . find graph_info . info id with | Some { node_type ; here } -> ( match here with | Some { Source_code_position . pos_lnum ; pos_cnum ; pos...
let write_computation_to_dot filename component = let graph_info = ref Graph_info . empty in let ( _ : _ Private . Computation . packed ) = Graph_info . iter_graph_updates_packed ( Bonsai . Private . reveal_computation component ) ~ on_update ( : fun gm -> graph_info := gm ) in graph_i...
let instrument_computation component = let graph_info = ref Graph_info . empty in let print_graph_info_on_update = ref false in let c = Graph_info . iter_graph_updates_packed ( Bonsai . Private . reveal_computation component ) ~ on_update ( : fun gm -> graph_info := gm ; if ! print_graph_info_o...
let many_aliases ( ) = test_start [ % here ] ; let % sub a = Bonsai . const 1 in let % sub a = return a in let % sub a = return a in let % sub _ = Bonsai . const 1 in let % sub a = return a in let % sub a = return a in let % sub a = return a in return a ; ; let ( _ : int Computa...
let subst_tree ( ) = test_start [ % here ] ; let % sub a = Bonsai . const 1 in let % sub b = Bonsai . const 2 in let % sub c = Bonsai . const 3 in let % sub d = Bonsai . const 4 in let % sub e = Bonsai . const 5 in let % arr a = a and b = b and c = c and d = d and e = e in a ...
let diamond ( ) = test_start [ % here ] ; let % sub a = Bonsai . const 0 in let % sub b = Bonsai . pure Fn . id a in let % sub c = Bonsai . pure Fn . id a in let % arr b = b and c = c in b + c ; ; let ( _ : int Computation . t ) = instrument_computation ( diamond ( ) ...
let state ( ) = test_start [ % here ] ; let % sub state = Bonsai . state [ % here ] ( module Int ) ~ default_model : 0 in return state ; ; let c = instrument_computation ( state ( ) ) in [ % expect { | tree : 1_1 leaf0 -> _1 subst_stateless_into @ 1 : 2 2_1 return...
let dynamic_state ( ) = test_start [ % here ] ; let % sub state = Bonsai . state_machine1 [ % here ] ( module Int ) ( module Unit ) ~ default_model : 0 ~ apply_action ( : fun ~ inject : _ ~ schedule_event : _ ( ) model ( ) -> model + 1 ) ( Value . return ( ) ...
let dynamic_scope ( ) = test_start [ % here ] ; let dynamic_var = Bonsai . Dynamic_scope . create ~ name " : a " ~ fallback : 0 ( ) in Bonsai . Dynamic_scope . set dynamic_var ( Bonsai . Value . return 10 ) ~ inside : ( let % sub a = Bonsai . Dynamic_scope . lookup d...
let cutoff ( ? var = Bonsai . Var . create 0 ) ( ) = test_start [ % here ] ; let value = Bonsai . Var . value var in return ( Value . cutoff value ~ equal ( : fun _ _ -> false ) ) ; ; let var = Bonsai . Var . create 0 in let c = instrument_computation ( cutoff ~ ...
let assoc_simpl ( ) = test_start [ % here ] ; Bonsai . assoc ( module Int ) ( Value . return ( Int . Map . of_alist_exn [ - 1 , ( ) ; 1 , ( ) ] ) ) ~ f ( : fun i _ -> return i ) ; ; let c = instrument_computation ( assoc_simpl ( ) ) in [ % exp...
let assoc ( ) = test_start [ % here ] ; let % sub a = Bonsai . const 0 in Bonsai . assoc ( module Int ) ( Value . return ( Int . Map . of_alist_exn [ - 1 , ( ) ; 1 , ( ) ] ) ) ~ f ( : fun _ _ -> let % arr a = a in a ) ; ; let c = instrument_compu...
let nested_values ( ? a = Value . return 0 ) ( ) = test_start [ % here ] ; return ( let % map a = let % map a = let % map a = a in a in a in a ) ; ; let a_var = Bonsai . Var . create 0 in let a = Bonsai . Var . value a_var in let c = instrument_computation ( nested_value...
let enum ( ? a = Value . return 0 ) ( ? match_ = Value . return true ) ( ) = test_start [ % here ] ; Bonsai . enum ( module Bool ) ~ match_ ~ with_ ( : function | true -> let % arr a = a in a > 0 | false -> return match_ ) ; ; let match_var = Bonsai . Var . cre...
let lazy_computation ( ? match_ = Value . return true ) ( ) = test_start [ % here ] ; let a = Bonsai . Value . return 0 in Bonsai . enum ( module Bool ) ~ match_ ~ with_ ( : function | true -> return a | false -> Bonsai . lazy_ ( lazy ( return a ) ) ) ; ; let mat...
let shared = let % sub ( ) = Bonsai . const ( ) in Bonsai . const ( ) ; ;
let name_used_twice ( ) = test_start [ % here ] ; let % sub ( ) = shared in let % sub ( ) = shared in Bonsai . const ( ) ; ; let ( _ : unit Computation . t ) = instrument_computation ( name_used_twice ( ) ) in [ % expect { | tree : 1 - 1_1 return -> 1_1 sub...
type packed = T : ( unit -> ' a Computation . t ) -> packed
let command = Command . async ~ summary " : Run tests for bonsai instrumentation " ( Command . Param . return ( fun ( ) -> Writer . with_file " tests . md " ~ f ( : fun writer -> Writer . write_line writer " " ; --- Writer . write_line writer " title : Bonsai instrumenta...
let eval_int_var string = Form . Blocking . eval ( string |> Symbol . intern |> Form . symbol )
let most_negative_fixnum_value = eval_int_var " most - negative - fixnum "
let most_positive_fixnum_value = eval_int_var " most - positive - fixnum "
let most_positive_fixnum = Value . emacs_max_int print_s [ % sexp ( most_negative_fixnum_value : Value . t ) ] ; [ % expect { | - 2305843009213693952 } ] ; | print_s [ % sexp ( most_negative_fixnum : int ) ] ; [ % expect { | - 2_305_843_009_213_693_952 } ] ; | ...
let of_ints = List . map ~ f : of_int_exn
let examples = of_ints [ - 1 ; 0 ; 1 ; 2 ; 3 ; 4 ; 5 ; 7 ; 8 ; 9 ; 63 ; 64 ; 65 ]
let examples_64_bit = [ min_value ; succ min_value ; pred max_value ; max_value ]
let print_for ints f = List . iter ints ~ f ( : fun i -> print_s [ % message " " ~ _ ( : i : int32 ) ~ _ ( : Or_error . try_with ( fun ( ) -> f i ) : int Or_error . t ) ] ) ; ; print_for examples floor_log2 ; [ % expect { | ( - 1 ( Error ( " [ Int3...
check_int_hash_coherence [ % here ] ( module Int63 ) ; [ % expect { | } ] | ; ; [ % test_result : t ] min_value ~ expect ( : of_int64_exn ( - 4611686018427387904L ) ) ; ; [ % test_result : t ] ( of_int32_exn Int32 . min_value ) ~ expect ( : of_int32 Int32 ...
check_int_hash_coherence [ % here ] ( module Int64 ) ; [ % expect { | } ] | ; ;
let numbers = [ 0x0000_0000_0000_1020L ; 0x0000_0000_0011_2233L ; 0x0000_0000_1122_3344L ; 0x0000_0011_2233_4455L ; 0x0000_1122_3344_5566L ; 0x0011_2233_4455_6677L ; 0x1122_3344_5566_7788L ] ; ;
let test = test_conversion ~ to_string : Int64 . Hex . to_string_hum List . iter numbers ~ f ( : test bswap16 ) ; [ % expect { | 0x1020 --> 0x2010 0x11_2233 --> 0x3322 0x1122_3344 --> 0x4433 0x11_2233_4455 --> 0x5544 0x1122_3344_5566 --> 0x6655 0x11_2233_4455_6677 --> 0x7766 0x1...
let examples = [ - 1L ; 0L ; 1L ; 2L ; 3L ; 4L ; 5L ; 7L ; 8L ; 9L ; 63L ; 64L ; 65L ]
let examples_64_bit = [ min_value ; succ min_value ; pred max_value ; max_value ]
let print_for ints f = List . iter ints ~ f ( : fun i -> print_s [ % message " " ~ _ ( : i : int64 ) ~ _ ( : Or_error . try_with ( fun ( ) -> f i ) : int Or_error . t ) ] ) ; ; print_for examples floor_log2 ; [ % expect { | ( - 1 ( Error ( " [ Int6...
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_max_caml_int _ = assert_equal max_int ( max_caml_int ( ) ) ~ printer : string_of_int end
let test_uint64_of_int _ = begin assert_equal max_int ( UInt64 . to_int ( UInt64 . of_int max_int ) ) ~ printer : string_of_int end
let test_store_caml_int _ = begin let p = allocate camlint max_int in assert_equal max_int !@ p ~ printer : string_of_int end
let suite = " Integer tests " >::: [ " UInt64 . of_int " >:: test_uint64_of_int ; " max_caml_int ( foreign ) " >:: Foreign_tests . test_max_caml_int ; " max_caml_int ( stubs ) " >:: Stub_tests . test_max_caml_int ; " storing camlint " >:: test_store_caml_int ; ]
let _ = run_test_tt_main suite
let tests = [ ( " integration . xml " >:: fun _ -> " <? xml version ' = 1 . 0 ' encoding ' = windows - 1252 ' ?>< root >\ xa0 </ root >< a ></ a " > |> string |> parse_xml |> signals |> write_xml |> to_string |> assert_equal ( " <? xml version " =\ 1 . 0 " \...
module Interface ( R : Idl . RPC ) RPC = struct open R let int_p = Idl . Param . mk Rpc . Types . int let string_p = Idl . Param . mk Rpc . Types . string let int_p_named_1 = Idl . Param . mk ~ name " : int1 " ~ description [ : " first int param " ] Rpc . Types . int let int_p_named_2 = ...
let asexp = { ( ( | matrix ( ( Wub ( Doj 0 . 2uf Doj_min ) ) 0 . 017678127290832395 ) ( ( Wub ( Doj 0 . 2uf Doj_roral ) ) 0 . 0048403389770755555 ) ( ( Wub ( Doj 0 . 5uf Doj_min ) ) 0 . 014466863493201646 ) ( ( Wub ( Doj 0 . 5uf Doj_roral ) ...
let bsexp = { ( ( | matrix ( ( Wub ( Doj 0 . 2uf Doj_min ) ) 0 . 018567212015996211 ) ( ( Wub ( Doj 0 . 2uf Doj_roral ) ) 0 . 018367577773486032 ) ( ( Wub ( Doj 0 . 5uf Doj_min ) ) 0 . 010881217012225865 ) ( ( Wub ( Doj 0 . 5uf Doj_roral ) ...
type test_config = { ml_port : int ; sclang_path : string ; sc_port : int ; sc_script_path : string ; }
let ping_sclang config packet = let open Osc . Types in let open Osc_unix . Udp in let localhost = Unix . inet_addr_of_string " 127 . 0 . 0 . 1 " in let ml_addr = Unix . ADDR_INET ( localhost , config . ml_port ) in let sc_addr = Unix . ADDR_INET ( localhost , config . sc_port ...
let test_ping_sclang config = " test_ping_sclang " >::: ( List . map ( fun ( name , packet ) -> name >:: ( fun ( ) -> ping_sclang config packet ) ) Test_common . test_packets_sclang )
let test_interop_sclang config = " test_interop_sclang " >::: [ test_ping_sclang config ; ]
let write_ml_port ml_port = let data_file_path = " test . data " in let chan = open_out data_file_path in begin try output_binary_int chan ml_port ; with e -> close_out chan ; raise e end ; close_out chan
let usage ( ) = Printf . printf " Usage :\ n " ; %! Printf . printf " % s < ml - port > < sclang - path > < sc - port > < sc - script - path >\ n " %! Sys . executable_name
let ( ) = match Sys . argv with | [ | _ ; ml_port_string ; sclang_path ; sc_port_string ; sc_script_path ] | -> begin try let ml_port = int_of_string ml_port_string in let sc_port = int_of_string sc_port_string in write_ml_port ml_port ; print_endline " -------- SuperCollider interoperabi...
let test_context ( ) = Context . init 3 >>=? fun ( b , _cs ) -> Incremental . begin_construction b >>=? fun v -> return ( Incremental . alpha_ctxt v )
let logger = Script_typed_ir . { log_interp = ( fun _ _ _ _ _ -> ( ) ) ; log_entry = ( fun _ _ _ _ _ -> ( ) ) ; log_exit = ( fun _ _ _ _ _ -> ( ) ) ; log_control = ( fun _ -> ( ) ) ; get_log = ( fun ( ) -> Lwt . return ( Ok None ) ) ; ...
let run_step ctxt code accu stack = let open Script_interpreter in let open Contract_helpers in step None ctxt default_step_constants code accu stack >>=? fun ( ( _ , _ , ctxt ' ) as r ) -> step ( Some logger ) ctxt default_step_constants code accu stack >>=? fun ( _ , _ , ctxt ' ' )...
let test_bad_contract_parameter ( ) = test_context ( ) >>=? fun ctx -> Contract_helpers . run_script ctx " { parameter unit ; storage unit ; code { CAR ; NIL operation ; PAIR } } " ~ storage " : Unit " ~ parameter " : 0 " ( ) >>= function | Ok _ -> Alcotest . fail...
let test_multiplication_close_to_overflow_passes ( ) = test_context ( ) >>=? fun ctx -> Contract_helpers . run_script ctx " { parameter unit ; storage unit ; code { DROP ; PUSH mutez 2944023901536524477 ; \ PUSH nat 2 ; MUL ; DROP ; UNIT ; NIL operation ; PAIR } } " ~ stor...
let read_file filename = let ch = open_in filename in let s = really_input_string ch ( in_channel_length ch ) in close_in ch ; s
let test_stack_overflow ( ) = let open Script_typed_ir in test_context ( ) >>=? fun ctxt -> let ctxt = Gas . update_remaining_operation_gas ctxt @@ Gas . fp_of_milligas_int ( Saturation_repr . saturated :> int ) in let stack = Bot_t in let descr kinstr = { kloc = 0 ; kbef = stack ; ka...
let test_stack_overflow_in_lwt ( ) = let open Script_typed_ir in test_context ( ) >>=? fun ctxt -> let ctxt = Gas . update_remaining_operation_gas ctxt @@ Gas . fp_of_milligas_int ( Saturation_repr . saturated :> int ) in let stack = Bot_t in let item ty s = Item_t ( ty , s ) in let unit...