text stringlengths 0 601k |
|---|
let curr_example_result = ref Ok |
let problem_queue = Queue . create ( ) |
let curr_problem_id = ref 1 |
let name spec = spec . name |
let example_description example = example . description |
let example_result example = example . result |
let specs ( ) = spec_queue |
let spec root = root . spec |
let problems root = root . problems |
let new_spec name = { name = name ; examples = Queue . create ( ) ; subspecs = Queue . create ( ) ; before_each = Queue . create ( ) ; before_all = Queue . create ( ) ; after_each = Queue . create ( ) ; after_all = Queue . create ( ) } |
let new_root_spec spec = { spec = spec ; num_examples = 0 ; num_pending = 0 ; problems = Queue . create ( ) } |
let curr_root_spec = ref ( new_root_spec ( new_spec " " ) ) |
let iter_examples f spec = Queue . iter f spec . examples |
let iter_subspecs f spec = Queue . iter f spec . subspecs |
let num_examples root = root . num_examples |
let num_pending root = root . num_pending |
let failure_id failure = failure . failure_id |
let failure_operation failure = failure . operation |
let failure_expected_result failure = failure . expected |
let failure_actual_result failure = failure . actual |
let positive_failure failure = match failure . kind with | Positive -> true | Negative -> false |
let error_id error = error . error_id |
let error_message error = error . message |
let add_example example = let spec = Stack . top spec_stack in Queue . push example spec . examples |
let inherit_hooks spec parent = spec . before_each <- Queue . copy parent . before_each ; spec . before_all <- Queue . copy parent . before_all ; spec . after_each <- Queue . copy parent . after_each ; spec . after_all <- Queue . copy parent . after_all |
let start spec = if Stack . is_empty spec_stack then begin curr_root_spec := new_root_spec spec ; Stack . push spec spec_stack ; None end else begin let parent = Stack . top spec_stack in inherit_hooks spec parent ; Stack . push spec spec_stack ; Some parent end |
let remove_spec spec parent = ignore ( Stack . pop spec_stack ) ; match parent with | Some p -> Queue . push spec p . subspecs ; | None -> ! curr_root_spec . spec <- spec ; Queue . push ! curr_root_spec spec_queue |
let new_example description = let ex = { description = description ; result = ! curr_example_result } in ! curr_root_spec . num_examples <- ! curr_root_spec . num_examples + 1 ; curr_example_result := Ok ; ex |
let new_pending_example description = let ex = { description = description ; result = Pending } in ! curr_root_spec . num_pending <- ! curr_root_spec . num_pending + 1 ; ex |
let incr_problem_id ( ) = incr curr_problem_id |
let current_problem_id ( ) = ! curr_problem_id |
let add_before_each hook = let spec = Stack . top spec_stack in Queue . push hook spec . before_each |
let run_before_each_hooks ( ) = let spec = Stack . top spec_stack in Queue . iter ( fun f -> f ( ) ) spec . before_each |
let add_after_each hook = let spec = Stack . top spec_stack in Queue . push hook spec . after_each |
let run_after_each_hooks ( ) = let spec = Stack . top spec_stack in Queue . iter ( fun f -> f ( ) ) spec . after_each |
let add_after_all hook = let spec = Stack . top spec_stack in Queue . push hook spec . after_all |
let run_after_all_hooks ( ) = let spec = Stack . top spec_stack in Queue . iter ( fun f -> f ( ) ) spec . after_all |
let cleanup ( ) = Queue . clear spec_queue ; Queue . clear problem_queue ; curr_example_result := Ok ; curr_problem_id := 1 |
let set_example_failure id = curr_example_result := match ! curr_example_result with | Ok -> Fail ( id , id ) | Fail ( i , _ ) -> Fail ( i , id ) | Err _ -> failwith " Shouldn ' t fail after an error " | Pending -> failwith " A Pending example can ' t fail " |
let set_example_error id = curr_example_result := Err id |
let add_failure operation actual expected kind = let id = current_problem_id ( ) in let failure = { failure_id = id ; operation = operation ; actual = actual ; expected = expected ; kind = kind } in set_example_failure id ; Queue . push ( Failure failure ) ! curr_root_spec . problems ; incr_problem_id ( ) |
let add_error err = let id = current_problem_id ( ) in let error = { error_id = id ; message = err } in set_example_error id ; Queue . push ( Error error ) ! curr_root_spec . problems ; incr_problem_id ( ) |
type lval = Ptr of lval | Var of string | Ident of string |
type fcall = { fname : string ; args : exp list } Fun of fcall | Exp_ | Lval of lval | Regex of string | String of string | Bool of bool | Int of int | Float of float | Binop of string * exp * exp | Unop of string * exp |
type stmt = { lval : lval option ; exp : exp } |
type def = Node of ( string * string ) | Edge of ( string * string list * bool * string * stmt ) |
let fname_is fname stmt = match stmt . exp with | Fun x -> x . fname = fname | _ -> false |
let is_wildcard stmt = stmt . exp = Exp_ |
let branch_exp stmt = match stmt . exp with | Fun { fname " = branch " ; args [ = exp ; Bool tv ] } -> Some ( exp , tv ) | _ -> None |
let is_branch stmt = branch_exp stmt <> None |
let startnode edges = let a , ws , fwd , b , c = List . hd edges in a |
let warning state nodes = try Some ( snd ( List . find ( fun x -> fst x = state ) nodes ) ) with | Not_found -> None |
let get_lval stmt = let f = function | Ptr x -> ` Ptr | Var s -> ` Var | Ident s -> ` Ident in Option . map f stmt . lval |
let get_exp = function | Regex x -> ` Regex x | String x -> ` String x | Bool x -> ` Bool x | Int x -> ` Int x | Float x -> ` Float x | Lval ( Var x ) -> ` Var x | Lval ( Ident x ) -> ` Ident x | Fun x -> ` Error " Functions aren ' t allowed to have functions as an argument ( put the function as a previous state instea... |
let get_rval stmt = get_exp stmt . exp |
let get_key_variant stmt = let rec get_from_exp = function | Fun f -> get_from_args f . args | Lval ( Var s ) -> ` Rval s | _ -> ` None and get_from_argsi i = function | [ ] -> ` None | x :: xs -> match get_from_exp x with | ` Rval s -> ` Arg ( s , i ) | _ -> get_from_argsi ( i + 1 ) xs and get_from_args args = get_fro... |
let equal_form lval stmt = match lval , stmt . lval with | Some _ , Some _ | None , None -> true | _ -> false |
let get_fun_args stmt = match stmt . exp with | Fun f -> List . map get_exp f . args | _ -> [ ] |
let rec lval_to_string = function | Ptr x -> " " ( *^ lval_to_string x ) | Var x -> " " $^ x | Ident x -> x |
let rec exp_to_string = function | Fun x -> x . fname " ( " ^^ String . concat " , " ( List . map exp_to_string x . args ) " ) " ^ | Exp_ -> " _ " | Lval x -> lval_to_string x | Regex x -> " r " " \^ x " " " ^\ | String x -> " " " \^ x " " " ^\ | Bool x -> string_of_bool x | Int x -> string_of_int x | Float x -> string... |
let stmt_to_string stmt = match stmt . lval , stmt . exp with | Some lval , exp -> lval_to_string lval " ^ = " ^ exp_to_string exp | None , exp -> exp_to_string exp |
let arrow_to_string ws fwd = ( String . concat " , " ws ) ^ if fwd then " " > else " " |
let def_to_string = function | Node ( n , m ) -> n " ^\ t " " \^ m " " " ^\ | Edge ( a , ws , fwd , b , s ) -> a " ^ " -^ arrow_to_string ws fwd " ^> " ^ b " ^\ t " ^ stmt_to_string s |
let to_dot_graph defs = let no_warnings = true in let def_to_string = function | Node ( n , m ) -> if no_warnings then " " else n " ^\ t [ style = filled , fillcolor = orange , label " " =\^ n " ^: " ^ m " " ] ; " ^\ | Edge ( a , ws , fwd , b , s ) -> let style = if fwd then " style = dotted , " else " " in let ws = if... |
let all op1 op2 = let r = M . log op1 in printf " % s % s \ n " ( M . get_formatted_str r ) ( rounding_to_string r ) ; let r = try M . log_int ( M . get_int op1 ) with M . Invalid_integer_input _ -> M . make_nan ( ) in printf " % s % s \ n " ( M . get_formatted_str r ) ( rounding_to_string r ) ; let r = M . log2 op1 in... |
let _ = all ( M . make_from_float ( 1 . . / 3 . ) ) ( M . make_from_float ( 1 . . / 10 . ) ) ; printf " \ n " ; all ( M . make_from_float ( ( . ~- 4 . ) . / 3 . ) ) ( M . make_from_float ( 1 . . / 10 . ) ) ; printf " \ n " ; all ( M . make_from_float ( 1 . . / 3 . ) ) ( M . make_from_float ( ( . ~- 113 . ) . / 10 . ) )... |
let hide_until_round_2 init_in_hide f_in_hide = let x1_in_hide = match init_in_hide with | 0 -> true | _ -> false in ignore ( Sys . opaque_identity x1_in_hide ) ; let x2_in_hide = match init_in_hide with | 0 -> true | _ -> false in ignore ( Sys . opaque_identity x2_in_hide ) ; f_in_hide |
let foo bar init a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 = let f_outer = let baz = bar + 1 in let rec f_inner x_in_f y_in_f b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 = let dec = b1 + b2 + b3 + b4 + b5 + b6 + b7 + b8 + b9 + b10 + b11 + b12 + b13 in match x_in_f with | Some _ -> g_inner x_in_f ( y_in_f - dec ) | None... |
let rec function_cardinality info x acc = get_approx info ( fun x -> match info . info_defs . ( Var . idx x ) with | Expr ( Closure ( l , _ ) ) -> Some ( List . length l ) | Expr ( Prim ( Extern " % closure " , [ Pc ( NativeString prim ) ] ) ) -> ( try Some ( Primitive . arity prim ) with Not_found -> None ) | Expr ( A... |
let specialize_instr info ( acc , free_pc , extra ) i = match i with | Let ( x , Apply ( f , l , _ ) ) when Config . Flag . optcall ( ) -> ( let n ' = List . length l in match function_cardinality info f [ ] with | None -> i :: acc , free_pc , extra | Some n when n = n ' -> Let ( x , Apply ( f , l , true ) ) :: acc , f... |
let specialize_instrs info p = let blocks , free_pc = Addr . Map . fold ( fun pc block ( blocks , free_pc ) -> let body , free_pc , extra = List . fold_right block . body ~ init ( [ ] , : free_pc , [ ] ) ~ f ( : fun i acc -> specialize_instr info acc i ) in let blocks = List . fold_left extra ~ init : blocks ~ f ( : fu... |
let f info p = specialize_instrs info p |
let specialize_instr info i = match i with | Let ( x , Prim ( Extern " caml_format_int " , [ y ; z ] ) ) -> ( match the_string_of info y with | Some " % d " -> ( match the_int info z with | Some i -> Let ( x , Constant ( String ( Int32 . to_string i ) ) ) | None -> Let ( x , Prim ( Extern " % caml_format_int_special " ... |
let specialize_instrs info l = let rec aux info checks l acc = match l with | [ ] -> List . rev acc | i :: r -> ( match i with | Let ( x , Prim ( Extern " caml_array_get " , [ y ; z ] ) ) | Let ( x , Prim ( Extern " caml_array_get_float " , [ y ; z ] ) ) | Let ( x , Prim ( Extern " caml_array_get_addr " , [ y ; z ] ) )... |
let specialize_all_instrs info p = let blocks = Addr . Map . map ( fun block -> { block with Code . body = specialize_instrs info block . body } ) p . blocks in { p with blocks } |
let f info p = specialize_all_instrs info p |
let f_once p = let rec loop acc l = match l with | [ ] -> List . rev acc | i :: r -> ( match i with | Let ( x , ( Prim ( Extern ( " caml_array_set " | " caml_array_unsafe_set " | " caml_array_set_float " | " caml_array_set_addr " | " caml_array_unsafe_set_float " | " caml_floatarray_unsafe_set " ) , [ _ ; _ ; _ ] ) as ... |
let strip_quotes s = String . drop_prefix s 1 |> Fn . flip String . drop_suffix 1 |
let two_elt_list_to_tuple ( j : json ) : string = match j with | ` List [ ` Int x1 ; ` Int x2 ] -> Printf . sprintf " ( % d , % d ) " x1 x2 | _ -> failwith " two element list expected , but got " ^ ( json_to_string j ) |
let map_elements ( to_str : json -> string ) ( parameters : ( string * json ) list ) : ( string * string ) list = List . map parameters ~ f ( : fun ( k , j ) -> ( k , to_str j ) ) |
let optional_int ( ~ none : int ) = function | ` Int n when n = none -> " None " | ` Int n -> " ( Some " ^ Int . to_string n ^ " ) " | x -> json_to_string x |
let optional_int_list = function | ` List xs -> " ( Some [ " ^ String . concat ~ sep " ; : " ( List . map ~ f : json_to_string xs ) ^ " ] ) " | _ -> " None " |
let optional_int_or_string ( ~ none : int ) = function | ` String s -> " ( Some " " \ ^ s ^ " " ) " \ | ` Int n when n = none -> " None " | x -> json_to_string x |
let default_value ( ~ key : string ) ( ~ value : string ) ( parameters : ( string * string ) list ) : ( string * string ) list = if List . exists ~ f ( : fun ( k , _ ) -> String . ( k = key ) ) parameters then parameters else ( key , value ) :: parameters |
let optional_strings ( ~ f : string -> bool ) ( parameters : ( string * json ) list ) : ( string * string ) list = let replace parameter = let ( k , v ) = parameter in if f k then ( k , " ( Some " ^ json_to_string v ^ " ) " ) else ( k , json_to_string v ) in List . map ~ f : replace parameters |
let option_of_null ( value : json ) : string = match value with | ` Null -> " None " | ` String s -> " ( Some " " \ ^ s ^ " " ) " \ | ` List _ as l -> " ( Some " ^ ( json_to_string l ) ^ " ) " | x -> failwith " cannot handle this type : " ^ json_to_string x |
let is_empty_string ( value : json ) : bool = match value with | ` String s -> String . is_empty s | _ -> false |
let edit_phone_number_expected ( value : json ) = match value with | ` String s -> " ( Ok " " \ ^ s ^ " " ) " \ | ` Assoc [ ( " error " , v ) ] -> " ( Error " ^ json_to_string v ^ " ) " | x -> failwith " Bad json value in change " ^ json_to_string x |
let edit_hamming_expected = function | ` Int n -> " ( Ok " ^ Int . to_string n ^ " ) " | ` Assoc [ ( " error " , ` String m ) ] " -> ( Error " " \ ^ m ^ " " ) " \ | x -> json_to_string x |
let edit_change_expected ( value : json ) = match value with | ` List xs -> " ( Some [ " ^ ( String . concat ~ sep " ; : " ( List . map ~ f : json_to_string xs ) ) ^ " ] ) " | ` Assoc [ ( " error " , _ ) ] -> " None " | ` Int ( - 1 ) -> " None " | _ -> failwith " Bad json value in change " |
let edit_bowling_expected ( value : json ) = match value with | ` Int n -> " ( Ok " ^ ( Int . to_string n ) ^ " ) " | ` Assoc [ ( k , v ) ] -> if String . ( k = " error " ) then " ( Error " ^ json_to_string v ^ " ) " else failwith ( " Can only handle error value but got " ^ k ) | _ -> failwith " Bad json value in bowli... |
let edit_forth_expected ( value : json ) = match value with | ` List xs -> " ( Some [ " ^ ( String . concat ~ sep " ; : " ( List . map ~ f : json_to_string xs ) ) ^ " ] ) " | ` Assoc [ ( " error " , _ ) ] -> " None " | x -> failwith " Bad json value in change " ^ json_to_string x |
let edit_beer_song_expected = function | ` List xs -> xs |> List . map ~ f ( : function | ` String s -> s | x -> json_to_string x ) |> String . concat ~ sep ( : String . escaped " \ n " ) |> Printf . sprintf " " \% s " " \ | x -> json_to_string x |> Printf . sprintf " Bad json value in beer - song % s " |> failwith |
let edit_say ( ps : ( string * json ) list ) = let edit = function | ( " number " , ` Int v ) when v >= 0 -> ( " number " , Printf . sprintf " % iL " v ) | ( " number " , ` Int v ) when v < 0 -> ( " number " , Printf . sprintf " ( % iL ) " v ) | ( " expected " , ` Assoc [ ( " error " , v ) ] ) -> ( " expected " , " ( E... |
let edit_triangle ( ps : ( string * json ) list ) : ( string * string ) list option = let edit = function | ( " sides " , ` List l ) -> ( " sides " , l |> List . map ~ f : json_to_string |> String . concat ~ sep " : " ) | ( k , v ) -> ( k , json_to_string v ) in let int_sides = function | ( " sides " , ` List l ) -> l ... |
let edit_all_your_base ( ps : ( string * json ) list ) : ( string * string ) list = let edit = function | ( " outputBase " , v ) -> let v = json_to_string v in ( " outputBase " , if Int . of_string v >= 0 then v else " ( " ^ v ^ " ) " ) | ( " inputBase " , v ) -> let v = json_to_string v in ( " inputBase " , if Int . o... |
let edit_allergies ( ps : ( string * json ) list ) : ( string * string ) list = let has_key key ( k , _ ) = String . ( k = key ) in let filtered = List . filter ps ~ f ( : fun p -> has_key " score " p || has_key " item " p ) in let by_key k = List . find filtered ~ f ( : has_key k ) in let params = [ " score " ; " item... |
let edit_connect ( ps : ( string * json ) list ) : ( string * string ) list = let format_board l = if List . length l > 1 then l |> List . map ~ f ( : json_to_string ) |> String . concat ~ sep " ; :\ n " |> Printf . sprintf " [ \ n % s ; \ n ] " else json_to_string ( ` List l ) in let edit = function | ( " expected " ,... |
let edit_dominoes ( ps : ( string * json ) list ) : ( string * string ) list = let edit ( p : ( string * json ) ) = match p with | ( " dominoes " , ` List j ) -> ( " dominoes " , " [ " ^ ( List . map ~ f : two_elt_list_to_tuple j |> String . concat ~ sep " ; : " ) ^ " ] " ) | ( k , v ) -> ( k , json_to_string v ) in Li... |
let edit_minesweeper ( ps : ( string * json ) list ) : ( string * string ) list = let format_board l = if List . length l > 1 then l |> List . map ~ f : json_to_string |> String . concat ~ sep " ; :\ n " |> Printf . sprintf " [ \ n % s ; \ n ] " else json_to_string ( ` List l ) in let edit = function | ( " minefield " ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.