text
stringlengths
0
601k
let _ = if Array . length Sys . argv = 1 then print_usage ( ) ; Printexc . record_backtrace true ; try run ( ) with | e -> Printf . eprintf " % s \ n % s \ n " %! ( Printexc . to_string e ) ( Printexc . get_backtrace ( ) )
let account_pair = function [ a1 ; a2 ] -> ( a1 , a2 ) | _ -> assert false
let wrap e = Lwt . return ( Environment . wrap_tzresult e )
let check_stake ~ loc ( b : Block . t ) ( account : Account . t ) = Context . Delegate . staking_balance ( B b ) account . pkh >>=? fun staking_balance -> Context . Delegate . full_balance ( B b ) account . pkh >>=? fun full_balance -> Assert . equal_tez ~ loc full_balance staking_balance >>=? fun ( ) -> Raw_context . ...
let check_no_stake ~ loc ( b : Block . t ) ( account : Account . t ) = Raw_context . prepare b . context ~ level : b . header . shell . level ~ predecessor_timestamp : b . header . shell . timestamp ~ timestamp : b . header . shell . timestamp >>= wrap >>=? fun ctxt -> Stake_storage . get ctxt account . pkh >>= wrap >>...
let test_simple_staking_rights ( ) = Context . init 2 >>=? fun ( b , accounts ) -> let ( a1 , _a2 ) = account_pair accounts in Context . Contract . balance ( B b ) a1 >>=? fun balance -> Context . Contract . pkh a1 >>=? fun delegate1 -> Context . Delegate . current_frozen_deposits ( B b ) delegate1 >>=? fun frozen_depo...
let test_simple_staking_rights_after_baking ( ) = Context . init ~ consensus_threshold : 0 2 >>=? fun ( b , accounts ) -> let ( a1 , a2 ) = account_pair accounts in Context . Contract . manager ( B b ) a1 >>=? fun m1 -> Context . Contract . manager ( B b ) a2 >>=? fun m2 -> Block . bake_n ~ policy ( : By_account m2 . p...
let check_active_staking_balance ~ loc ~ deactivated b ( m : Account . t ) = Context . Delegate . info ( B b ) m . pkh >>=? fun info -> Assert . equal_bool ~ loc info . deactivated deactivated >>=? fun ( ) -> if deactivated then check_no_stake ~ loc b m else check_stake ~ loc b m
let run_until_deactivation ( ) = Context . init ~ consensus_threshold : 0 2 >>=? fun ( b , accounts ) -> let ( a1 , a2 ) = account_pair accounts in Context . Contract . balance ( B b ) a1 >>=? fun balance_start -> Context . Contract . manager ( B b ) a1 >>=? fun m1 -> Context . Contract . manager ( B b ) a2 >>=? fun m2...
let test_deactivation_then_bake ( ) = run_until_deactivation ( ) >>=? fun ( b , ( ( _deactivated_contract , deactivated_account ) , _start_balance ) , ( _a2 , _m2 ) ) -> Block . bake ~ policy ( : By_account deactivated_account . pkh ) b >>=? fun b -> check_active_staking_balance ~ loc : __LOC__ ~ deactivated : false b ...
let test_a_really_deactivated_account_is_not_in_the_committee ( ) = run_until_deactivation ( ) >>=? fun ( b , ( ( _deactivated_contract , deactivated_account ) , _start_balance ) , ( _a2 , m2 ) ) -> let constants = Default_parameters . constants_test in Block . bake_until_n_cycle_end ( constants . preserved_cycles + 1 ...
let test_deactivation_then_self_delegation ( ) = run_until_deactivation ( ) >>=? fun ( b , ( ( deactivated_contract , deactivated_account ) , _start_balance ) , ( _a2 , m2 ) ) -> Op . delegation ( B b ) deactivated_contract ( Some deactivated_account . pkh ) >>=? fun self_delegation -> Block . bake ~ policy ( : By_acco...
let test_deactivation_then_empty_then_self_delegation ( ) = run_until_deactivation ( ) >>=? fun ( b , ( ( deactivated_contract , deactivated_account ) , _start_balance ) , ( _a2 , m2 ) ) -> Context . Contract . balance ( B b ) deactivated_contract >>=? fun balance -> let sink_account = Account . new_account ( ) in let ...
let test_deactivation_then_empty_then_self_delegation_then_recredit ( ) = run_until_deactivation ( ) >>=? fun ( b , ( ( deactivated_contract , deactivated_account ) , _start_balance ) , ( _a2 , m2 ) ) -> Context . Contract . balance ( B b ) deactivated_contract >>=? fun balance -> let sink_account = Account . new_accou...
let test_delegation ( ) = Context . init ~ consensus_threshold : 0 2 >>=? fun ( b , accounts ) -> let ( a1 , a2 ) = account_pair accounts in let m3 = Account . new_account ( ) in Account . add_account m3 ; Context . Contract . manager ( B b ) a1 >>=? fun m1 -> Context . Contract . manager ( B b ) a2 >>=? fun m2 -> let ...
let tests = [ Tztest . tztest " simple staking rights " ` Quick test_simple_staking_rights ; Tztest . tztest " simple staking rights after baking " ` Quick test_simple_staking_rights_after_baking ; Tztest . tztest " deactivation then bake " ` Quick test_deactivation_then_bake ; Tztest . tztest " deactivation then self ...
let return_type = Value . Type . sexpable ( module Sexp ) ~ name [ :% sexp " sexp " ]
let print_funcallN symbol args = print_s ( Value . Type . of_value_exn return_type ( Symbol . funcallN symbol args ) ) ; ; let symbol = Symbol . gensym ( ) in defun symbol here ~ docstring " : Returns its own arguments as a sexp . " ( Returns return_type ) ( let % map_open . Defun ( ) = return ( ) and i = required " in...
let x = " x " |> Symbol . intern in ignore ( defvar x [ % here ] ~ docstring " : some text " ~ type_ : Value . Type . int ~ initial_value : 13 ( ) : _ Var . t ) ; print_s [ % sexp ( Current_buffer . value_exn { symbol = x ; type_ = Value . Type . int } : int ) ] ; [ % expect { | 13 } ] ; | print_s [ % sexp ( Plist . of...
let a = Deg . Int 1 ; ;
let b = Deg . Float 1 . ; ;
let c = Deg . Big ( Big_int . big_int_of_int 1000 ) ; ;
let i = Deg . Float infinity ; ;
let m = Deg . Float neg_infinity ; ;
let e = Deg . Float ( 2 . ** 60 . ) ; ;
let s = function x -> Big_int . int_of_big_int ( Deg . big_demakeup x ) ; ;
let f x = x + 1
let rec fib = function | 1 | 2 -> 1 | n -> fib ( n - 1 ) + fib ( n - 2 ) 2
type intlist = | Nil | Cons of int * intlist
let cons x y = Cons ( Consx , y ) y
let rec map f = function | Nil -> Nil | Cons ( x , xs ) xs -> Cons ( f x , map f xs ) xs
let sum n = let v = ref 0 in for i = 0 to n do v := ! v + i done ; ! v
let f g x = let u = match g x with | " aabb " -> 0 | " bbc " -> 1 | _ -> 2 in u + 3
let f g x = let u = match g x with | " aabb " -> 0 | " bbc " -> 1 in u + 3
let v a ( ) : unit = while ignore true ; a 3 do ignore ( print_int 3 ) 3 done
type cxt = | A | B of int | C of int * string | D | E | F of string
let f ( x : cxt ) cxt = let u = match x with | A -> 0 | B _ -> 1 | C _ -> 2 | D -> 3 | E -> 4 | F _ -> 5 in u + 3
let f g ( x : cxt ) cxt = g @@ match x with | A -> 0 | B _ -> 1 | C _ -> 2 | D -> 3 | E -> 4 | F _ -> 5
let f h g x = h @@ try g x with Not_found -> 0
let f x y = fun z -> x + y + z
let g x y = let u = x + y in fun z -> u + z
let g1 x y = let u = x + y in fun xx yy -> xx + yy + u
let x = g 3 5 6
let v = g1 3 4 6
module Testable = struct include Testable let dep = let pp fmt dep = match ( dep : Mdx . Dep . t ) with | File f -> Fmt . pf fmt " File % S " f | Dir d -> Fmt . pf fmt " Dir % S " d in Alcotest . testable pp ( = ) end
let test_of_block = let make_test ~ block_des ~ block ~ expected ( ) = let test_name = Printf . sprintf " of_block : % S " block_des in let test_fun ( ) = let actual = Mdx . Dep . of_block block in Alcotest . ( check ( option Testable . dep ) ) test_name expected actual in ( test_name , ` Quick , test_fun ) in let bloc...
let test_of_line = let make_test ~ line_des ~ lines ~ expected ( ) = let test_name = Printf . sprintf " of_line : % S " line_des in let test_fun ( ) = let actual = Mdx . of_string Mdx . Normal lines >>| fun lines -> Mdx . Dep . of_lines lines in Alcotest . ( check ( result ( list Testable . dep ) Testable . msg ) ) tes...
let test_to_sexp = let make_test ~ name ~ input ~ expected ( ) = let test_name = Printf . sprintf " to_sexp : % s " name in let test_fun ( ) = let actual = Mdx . Dep . to_sexp input in Alcotest . ( check Testable . sexp test_name expected actual ) in ( test_name , ` Quick , test_fun ) in [ make_test ~ name " : file " ~...
let suite = ( " Dep " , test_of_block @ test_of_line @ test_to_sexp )
let cases = ( >::: )
let case = ( >:: )
let test_list_result_of_yojson = let test json expected ctxt = let got = Zeit . Deployment . Api_responses . list_result_of_yojson json in assert_equal ~ ctxt ~ cmp [ :% eq : ( Zeit . Deployment . t list , string ) result ] ~ printer [ :% show : ( Zeit . Deployment . t list , string ) result ] expected got in let name ...
let suite = cases " deployment " [ cases " api_responses " [ test_list_result_of_yojson ] ]
( module struct let binary_search = binary_search ~ compare : Int . compare let t = of_array [ | 1 ; 2 ; 3 ; 4 ] | let % test _ = [ % equal : int option ] ( binary_search t ` First_equal_to 2 ) ( Some 1 ) let % test _ = [ % equal : int option ] ( binary_search t ` First_equal_to 5 ) None let % test _ = [ % equal : int ...
module GP = Fitc_gp . Make_deriv ( Cov_se_fat . Deriv )
let main ( ) = Random . self_init ( ) ; let n_inducing = 5 in let training_inputs = Mat . random 3 10 in let training_targets = Vec . random 10 in let params = Cov_se_fat . Eval . Inputs . create_default_kernel_params ~ n_inducing training_inputs in let kernel = Cov_se_fat . Eval . Kernel . create params in let inducin...
let ( ) = main ( )
module M : sig type a = { a1 : int option ; a2 : int list ; a3 : int [ @ default 42 ] 42 ; a4s : ( int * int list ) list [ @ split ] split ; a5 : int ; } [ @@ deriving show , create ] create type b = { b1 : int option ; b2 : int list ; b3 : int [ @ default 42 ] 42 ; b4s : ( int * int list ) list [ @ split ] split ; b5 ...
let test_no_main ctxt = assert_equal ~ printer : M . show_a { M . a1 = None ; a2 = [ ] ; a3 = 42 ; a4s = 2 , [ ] ; a5 = 1 } ( M . create_a ~ a4 : 2 ~ a5 : 1 ( ) ) ; assert_equal ~ printer : M . show_a { M . a1 = Some 1 ; a2 = [ 2 ] 2 ; a3 = 3 ; a4s = 4 , [ 5 ] 5 ; a5 = 6 } ( M . create_a ~ a1 : 1 ~ a2 [ : 2 ] 2 ~ a3 : ...
let test_main ctxt = assert_equal ~ printer : M . show_b { M . b1 = None ; b2 = [ ] ; b3 = 42 ; b4s = 2 , [ ] ; b5 = 1 } ( M . create_b ~ b4 : 2 1 ) 1 ; assert_equal ~ printer : M . show_b { M . b1 = Some 1 ; b2 = [ 2 ] 2 ; b3 = 3 ; b4s = 4 , [ 5 ] 5 ; b5 = 6 } ( M . create_b ~ b1 : 1 ~ b2 [ : 2 ] 2 ~ b3 : 3 ~ b4 : 4 ~...
let suite = " Test deriving ( derivingcreate ) derivingcreate " >::: [ " test_no_main " >:: test_no_main ; " test_main " >:: test_main ; ]
let _ = run_test_tt_main suite
type a1 = int [ @@ deriving eq ] eq
type a2 = int32 [ @@ deriving eq ] eq
type a3 = int64 [ @@ deriving eq ] eq
type a4 = nativeint [ @@ deriving eq ] eq
type a5 = float [ @@ deriving eq ] eq
type a6 = bool [ @@ deriving eq ] eq
type a7 = char [ @@ deriving eq ] eq
type a8 = string [ @@ deriving eq ] eq
type a9 = bytes [ @@ deriving eq ] eq
type r1 = int ref [ @@ deriving eq ] eq
type r2 = int Stdlib . ref [ @@ deriving eq ] eq
type l = int list [ @@ deriving eq ] eq
type a = int array [ @@ deriving eq ] eq
type o = int option [ @@ deriving eq ] eq
type y = int lazy_t [ @@ deriving eq ] eq
let test_simple ctxt = assert_equal ~ printer true ( equal_a1 1 1 ) 1 ; assert_equal ~ printer false ( equal_a1 1 2 ) 2
let test_arr ctxt = assert_equal ~ printer true ( equal_a [ ] || [ ] ) ; || assert_equal ~ printer true ( equal_a [ | 1 ] | [ | 1 ] ) ; | assert_equal ~ printer false ( equal_a [ ] || [ | 1 ] ) ; | assert_equal ~ printer false ( equal_a [ | 2 ] | [ | 1 ] ) |
let test_ref1 ctxt = assert_equal ~ printer true ( equal_r1 ( ref 0 ) 0 ( ref 0 ) 0 ) 0
let test_ref2 ctxt = assert_equal ~ printer true ( equal_r2 ( ref 0 ) 0 ( ref 0 ) 0 ) 0
type v = Foo | Bar of int * string | Baz of string [ @@ deriving eq ] eq
type rv = RFoo | RBar of { x : int ; y : string ; } [ @@ deriving eq ] eq
type pv1 = [ ` Foo | ` Bar of int * string ] [ @@ deriving eq ] eq
type pv2 = [ ` Baz | pv1 ] [ @@ deriving eq ] eq
type ty = int * string [ @@ deriving eq ] eq
type re = { f1 : int ; f2 : string ;
module M : sig type t = int [ @@ deriving eq ] eq type t = int [ @@ deriving eq ] eq end
type z = M . t [ @@ deriving eq ] eq
type file = { name : string ; perm : int [ @ equal ( ) ] ; <>
let test_custom ctxt = assert_equal ~ printer false ( equal_file { name = " " ; perm = 1 } { name = " " ; perm = 1 } ) ; assert_equal ~ printer true ( equal_file { name = " " ; perm = 1 } { name = " " ; perm = 2 } )
type ' a pt = { v : ' a } [ @@ deriving eq ] eq
let test_placeholder ctxt = assert_equal ~ printer true ( [ % eq : _ ] _ 1 2 ) 2
type mrec_variant = | MrecFoo of string | MrecBar of int
let test_mrec ctxt = assert_equal ~ printer true ( equal_mrec_variant_list [ MrecFoo " foo " ; MrecBar 1 ] 1 [ MrecFoo " foo " ; MrecBar 1 ] 1 ) 1 ; assert_equal ~ printer false ( equal_mrec_variant_list [ MrecFoo " foo " ; MrecBar 1 ] 1 [ MrecFoo " bar " ; MrecBar 1 ] 1 ) 1
type e = Bool of be | Plus of e * e | IfE of ( be , e ) e if_e | Unit [ @@ deriving eq ] eq
let test_mut_rec ctxt = let e1 = IfE ( And ( False , True ) True , Unit , Plus ( Unit , Unit ) Unit ) Unit in let e2 = Plus ( Unit , Bool False ) False in assert_equal ~ printer true ( equal_e e1 e1 ) e1 ; assert_equal ~ printer true ( equal_e e2 e2 ) e2 ; assert_equal ~ printer false ( equal_e e1 e2 ) e2 ; assert_equa...
type es = | ESBool of ( bool [ @ nobuiltin ] nobuiltin ) nobuiltin | ESString of ( string [ @ nobuiltin ] nobuiltin ) nobuiltin | Bfoo of int * ( ( int -> int ) int [ @ equal fun _ _ -> true ] true ) true | Sfoo of ( String . t [ @ equal ( ) ] ) = * ( ( int -> int ) int [ @ equal fun _ _ -> true ] true ) true
let test_std_shadowing ctxt = let e1 = ESBool ( Bfoo ( 1 , ( ) + 1 ) 1 ) 1 in let e2 = ESString ( Sfoo ( " lalala " , ( ) + 3 ) 3 ) 3 in assert_equal ~ printer false ( equal_es e1 e2 ) e2 ; assert_equal ~ printer false ( equal_es e2 e1 ) e1 ; assert_equal ~ printer true ( equal_es e1 e1 ) e1 ; assert_equal ~ printer tr...
type poly_app = float poly_abs