Skip to content

add some tests for random #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions jscomp/test/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions jscomp/test/list_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion jscomp/test/list_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down
20 changes: 20 additions & 0 deletions jscomp/test/mt_global.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] = /* :: */[
Expand All @@ -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 */
4 changes: 4 additions & 0 deletions jscomp/test/mt_global.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand Down
4 changes: 4 additions & 0 deletions jscomp/test/mt_global.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
170 changes: 153 additions & 17 deletions jscomp/test/random_test.js
Original file line number Diff line number Diff line change
@@ -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 */
44 changes: 37 additions & 7 deletions jscomp/test/random_test.ml
Original file line number Diff line number Diff line change
@@ -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