diff --git a/jscomp/test/.depend b/jscomp/test/.depend index d51609c4d4..1a9bc89be6 100644 --- a/jscomp/test/.depend +++ b/jscomp/test/.depend @@ -300,8 +300,10 @@ qcc.cmx : ../stdlib/sys.cmx ../stdlib/string.cmx ../stdlib/printf.cmx \ ../stdlib/array.cmx queue_test.cmo : ../stdlib/queue.cmi mt.cmi ../stdlib/array.cmi queue_test.cmx : ../stdlib/queue.cmx mt.cmx ../stdlib/array.cmx -random_test.cmo : ../stdlib/random.cmi -random_test.cmx : ../stdlib/random.cmx +random_test.cmo : ../stdlib/random.cmi ../stdlib/printf.cmi mt_global.cmi \ + mt.cmi ../stdlib/int64.cmi ../stdlib/array.cmi +random_test.cmx : ../stdlib/random.cmx ../stdlib/printf.cmx mt_global.cmx \ + mt.cmx ../stdlib/int64.cmx ../stdlib/array.cmx rec_module_test.cmo : ../stdlib/set.cmi ../stdlib/pervasives.cmi mt.cmi rec_module_test.cmx : ../stdlib/set.cmx ../stdlib/pervasives.cmx mt.cmx rec_value_test.cmo : mt.cmi ../stdlib/list.cmi ../stdlib/lazy.cmi @@ -836,8 +838,10 @@ qcc.cmj : ../stdlib/sys.cmj ../stdlib/string.cmj ../stdlib/printf.cmj \ ../stdlib/array.cmj queue_test.cmo : ../stdlib/queue.cmi mt.cmi ../stdlib/array.cmi queue_test.cmj : ../stdlib/queue.cmj mt.cmj ../stdlib/array.cmj -random_test.cmo : ../stdlib/random.cmi -random_test.cmj : ../stdlib/random.cmj +random_test.cmo : ../stdlib/random.cmi ../stdlib/printf.cmi mt_global.cmi \ + mt.cmi ../stdlib/int64.cmi ../stdlib/array.cmi +random_test.cmj : ../stdlib/random.cmj ../stdlib/printf.cmj mt_global.cmj \ + mt.cmj ../stdlib/int64.cmj ../stdlib/array.cmj rec_module_test.cmo : ../stdlib/set.cmi ../stdlib/pervasives.cmi mt.cmi rec_module_test.cmj : ../stdlib/set.cmj ../stdlib/pervasives.cmj mt.cmj rec_value_test.cmo : mt.cmi ../stdlib/list.cmi ../stdlib/lazy.cmi diff --git a/jscomp/test/list_test.js b/jscomp/test/list_test.js index dc51d229b0..f4728227da 100644 --- a/jscomp/test/list_test.js +++ b/jscomp/test/list_test.js @@ -59,8 +59,8 @@ var list_suites_001 = /* :: */[ "long_length", function () { return /* Eq */{ - 0: 100000, - 1: List.length($$Array.to_list($$Array.init(100000, function () { + 0: 30000, + 1: List.length($$Array.to_list($$Array.init(30000, function () { return 0; }))), length: 2, diff --git a/jscomp/test/list_test.ml b/jscomp/test/list_test.ml index 38f856e3df..9998fdfe5b 100644 --- a/jscomp/test/list_test.ml +++ b/jscomp/test/list_test.ml @@ -8,7 +8,7 @@ let list_suites = Mt.[ Eq (5 , List.length [0;1;2;3;4]) (* This is tuple haha*) ) ; "long_length", (fun _ -> - let v = 100000 in + let v = 30_000 in Eq (v , (List.length (Array.to_list (Array.init v (fun _ -> 0)))) diff --git a/jscomp/test/mt_global.js b/jscomp/test/mt_global.js index 74cd9abfbf..5153f98097 100644 --- a/jscomp/test/mt_global.js +++ b/jscomp/test/mt_global.js @@ -21,6 +21,25 @@ function collect_eq(test_id, suites, loc, x, y) { return /* () */0; } +function collect_neq(test_id, suites, loc, x, y) { + test_id[0] = test_id[0] + 1 | 0; + suites[0] = /* :: */[ + /* tuple */[ + loc + (" id " + test_id[0]), + function () { + return /* Neq */{ + 0: x, + 1: y, + length: 2, + tag: 1 + }; + } + ], + suites[0] + ]; + return /* () */0; +} + function collect_approx(test_id, suites, loc, x, y) { test_id[0] = test_id[0] + 1 | 0; suites[0] = /* :: */[ @@ -41,5 +60,6 @@ function collect_approx(test_id, suites, loc, x, y) { } exports.collect_eq = collect_eq; +exports.collect_neq = collect_neq; exports.collect_approx = collect_approx; /* No side effect */ diff --git a/jscomp/test/mt_global.ml b/jscomp/test/mt_global.ml index c1697c3155..d26ee388c5 100644 --- a/jscomp/test/mt_global.ml +++ b/jscomp/test/mt_global.ml @@ -4,6 +4,10 @@ let collect_eq test_id suites loc x y = incr test_id ; suites := (loc ^" id " ^ (string_of_int !test_id), (fun _ -> Mt.Eq(x,y))) :: !suites +let collect_neq test_id suites loc x y = + incr test_id ; + suites := + (loc ^" id " ^ (string_of_int !test_id), (fun _ -> Mt.Neq(x,y))) :: !suites let collect_approx test_id suites loc x y = incr test_id ; diff --git a/jscomp/test/mt_global.mli b/jscomp/test/mt_global.mli index e6f5a8b099..9c43b26b21 100644 --- a/jscomp/test/mt_global.mli +++ b/jscomp/test/mt_global.mli @@ -3,6 +3,10 @@ val collect_eq : int ref -> Mt.pair_suites ref -> string -> 'b -> 'b -> unit +val collect_neq : + int ref -> Mt.pair_suites ref + -> string -> 'b -> 'b -> unit + val collect_approx : int ref -> Mt.pair_suites ref -> string -> float -> float -> unit diff --git a/jscomp/test/random_test.js b/jscomp/test/random_test.js index d2c213197f..730df83b51 100644 --- a/jscomp/test/random_test.js +++ b/jscomp/test/random_test.js @@ -1,22 +1,158 @@ // Generated CODE, PLEASE EDIT WITH CARE 'use strict'; -var Random = require("../stdlib/random"); - -function f() { - Random.self_init(/* () */0); - var x = Random.$$int(10000); - Random.self_init(/* () */0); - var y = Random.$$int(1000); - if (x === y) { - console.log("FAILED"); - return /* () */0; - } - else { - console.log("PASSED"); - return /* () */0; - } +var Mt = require("./mt"); +var Mt_global = require("./mt_global"); +var Printf = require("../stdlib/printf"); +var Int64 = require("../stdlib/int64"); +var Caml_array = require("../runtime/caml_array"); +var Caml_curry = require("../runtime/caml_curry"); +var Random = require("../stdlib/random"); + +var id = [0]; + +var suites = [/* [] */0]; + +function eq(f) { + return function (param, param$1) { + return Mt_global.collect_eq(id, suites, f, param, param$1); + }; +} + +function neq(f) { + return function (param, param$1) { + return Mt_global.collect_neq(id, suites, f, param, param$1); + }; +} + +function approx(f) { + return function (param, param$1) { + return Mt_global.collect_approx(id, suites, f, param, param$1); + }; } -exports.f = f; -/* No side effect */ +Random.self_init(/* () */0); + +var param = Random.$$int(1000); + +Random.self_init(/* () */0); + +var param$1 = Random.$$int(10000); + +Mt_global.collect_neq(id, suites, 'File "random_test.ml", line 12, characters 6-13', param$1, param); + +Random.init(0); + +var v = Caml_array.caml_make_vect(10, /* false */0); + +for(var i = 0; i<= 9; ++i){ + v[i] = Random.bool(/* () */0); +} + +var param$2 = /* array */[ + /* true */1, + /* true */1, + /* true */1, + /* true */1, + /* true */1, + /* false */0, + /* true */1, + /* true */1, + /* true */1, + /* false */0 +]; + +Mt_global.collect_eq(id, suites, 'File "random_test.ml", line 26, characters 5-12', v, param$2); + +var f = Random.int64(Int64.max_int); + +var h = Random.int64(/* int64 */[ + 0, + 3 + ]); + +var vv = Random.bits(/* () */0); + +var xx = Random.$$float(3.0); + +var xxx = Random.int32(103); + +Caml_curry.app5(Printf.printf(/* Format */[ + /* Int64 */{ + 0: /* Int_d */0, + 1: /* No_padding */0, + 2: /* No_precision */0, + 3: /* Char_literal */{ + 0: /* " " */32, + 1: /* Int64 */{ + 0: /* Int_d */0, + 1: /* No_padding */0, + 2: /* No_precision */0, + 3: /* Char_literal */{ + 0: /* " " */32, + 1: /* Int */{ + 0: /* Int_d */0, + 1: /* No_padding */0, + 2: /* No_precision */0, + 3: /* Char_literal */{ + 0: /* " " */32, + 1: /* Float */{ + 0: /* Float_f */0, + 1: /* No_padding */0, + 2: /* No_precision */0, + 3: /* Char_literal */{ + 0: /* " " */32, + 1: /* Int32 */{ + 0: /* Int_d */0, + 1: /* No_padding */0, + 2: /* No_precision */0, + 3: /* String_literal */{ + 0: " \n", + 1: /* End_of_format */0, + length: 2, + tag: 11 + }, + length: 4, + tag: 5 + }, + length: 2, + tag: 12 + }, + length: 4, + tag: 8 + }, + length: 2, + tag: 12 + }, + length: 4, + tag: 4 + }, + length: 2, + tag: 12 + }, + length: 4, + tag: 7 + }, + length: 2, + tag: 12 + }, + length: 4, + tag: 7 + }, + "%Ld %Ld %d %f %ld \n" + ]), f, h, vv, xx, xxx); + +Mt.from_pair_suites("random_test.ml", suites[0]); + +exports.id = id; +exports.suites = suites; +exports.eq = eq; +exports.neq = neq; +exports.approx = approx; +exports.v = v; +exports.f = f; +exports.h = h; +exports.vv = vv; +exports.xx = xx; +exports.xxx = xxx; +/* Not a pure module */ diff --git a/jscomp/test/random_test.ml b/jscomp/test/random_test.ml index 8fdd9b51c7..77a2ae52f6 100644 --- a/jscomp/test/random_test.ml +++ b/jscomp/test/random_test.ml @@ -1,7 +1,37 @@ -(** TODO: need [caml_md5_string] support *) -let f () = - Random.self_init (); - let x = Random.int 10000 in - Random.self_init (); - let y = Random.int 1000 in - if x = y then print_endline "FAILED" else print_endline "PASSED" + +let id = ref 0 +let suites = ref [] + +let eq f = Mt_global.collect_eq id suites f +let neq f = Mt_global.collect_neq id suites f +let approx f = Mt_global.collect_approx id suites f + + +let () + = + neq __LOC__ + (Random.self_init (); Random.int 10000) + (Random.self_init (); Random.int 1000 ) + +(* determinism acutally *) +let v = Random.init 0 + +let v = Array.make 10 false + +let () = + for i = 0 to 9 do + v.(i) <- Random.bool () + done +let () = + eq __LOC__ v [| true; true; true; true; true; false; true; true; true; false |] + +let f = Random.int64 Int64.max_int +let h = Random.int64 3L +let vv = Random.bits () +let xx = Random.float 3.0 +let xxx = Random.int32 103l +let () = + Printf.printf "%Ld %Ld %d %f %ld \n" f h vv xx xxx + +let () = + Mt.from_pair_suites __FILE__ !suites