Skip to content

Instantly share code, notes, and snippets.

@zshipko
Created June 7, 2016 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zshipko/6fcadc9f11c6eeb4b85dc2318b5c82c4 to your computer and use it in GitHub Desktop.
Save zshipko/6fcadc9f11c6eeb4b85dc2318b5c82c4 to your computer and use it in GitHub Desktop.
(* compile with: ocamlopt -a otest.ml -o otest.cmxa *)
class test = object(self)
val mutable pass : int = 0
val mutable fail : int = 0
val start_time = Unix.gettimeofday ()
method private pass_test name s =
pass <- pass + 1;
Printf.printf "PASSED: %s (%fs)\n" name (Unix.gettimeofday () -. s)
method private fail_test name s =
fail <- fail + 1;
Printf.printf "FAILED: %s (%fs)\n" name (Unix.gettimeofday () -. s)
method check name fn =
let res = fn () in
let t = Unix.gettimeofday () in
if res then self#pass_test name t
else self#fail_test name t
method finish () =
print_endline "----------";
Printf.printf "Passed: %d\n" pass;
Printf.printf "Failed: %d\n" fail;
print_endline "----------";
Printf.printf "Total: %d (%fs)\n" (pass + fail) (Unix.gettimeofday () -. start_time);
print_endline "----------";
end;;
Random.self_init ();;
let random_int start finish =
start + (Random.int (finish - start));;
let random_float start finish =
start +. (Random.float (finish -. start));;
let random_bool () =
Random.bool ();;
let create () =
new test;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment