Skip to content

Commit

Permalink
Tests: Fix some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo committed Jan 23, 2025
1 parent e3bdaa8 commit 3527686
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
10 changes: 4 additions & 6 deletions compiler/tests-ocaml/lib-floatarray/floatarray.ml
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ module Test (A : S) : sig end = struct
check_inval (fun i -> A.set a i 1.0) (-1);
check_inval (fun i -> A.set a i 1.0) 1000;
check_inval A.create (-1);
(* check_inval A.create (A.max_length + 1);*)
check_inval A.create (A.max_length + 1);
check_inval (fun i -> A.make i 1.0) (-1);
(* check_inval (fun i -> A.make i 1.0) (A.max_length + 1); *)
check_inval (fun i -> A.make i 1.0) (A.max_length + 1);

(* [length] *)
let test_length l = assert (l = (A.length (A.create l))) in
Expand All @@ -125,8 +125,7 @@ module Test (A : S) : sig end = struct
let a = A.init 1000 Float.of_int in
check_i a;
check_inval (fun i -> A.init i Float.of_int) (-1);
(* check_inval (fun i -> A.init i Float.of_int) (A.max_length + 1); *)

check_inval (fun i -> A.init i Float.of_int) (A.max_length + 1);

(* [make_matrix] *)
let check_make_matrix m n =
Expand Down Expand Up @@ -641,8 +640,7 @@ module Test (A : S) : sig end = struct
assert (compare value value' = 0)
in
let l = [0.; 0.25; -4.; 3.14159265; nan; infinity; neg_infinity; neg_zero] in
(* js_of_ocaml doesn't marshal floats *)
if false then test_structured_io (A.of_list l);
test_structured_io (A.of_list l);

(* map_inplace *)
let a = A.init 4 (fun i -> Float.of_int (i + 1)) in
Expand Down
21 changes: 13 additions & 8 deletions runtime/js/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function caml_check_bound(array, index) {
//Provides: caml_array_make const (const, mutable)
//Requires: caml_array_bound_error
function caml_array_make(len, init) {
if (len < 0) caml_array_bound_error();
if (len < 0 || (len >= 0x7fffffff / 4) | 0) caml_array_bound_error();
var len = (len + 1) | 0;
var b = new Array(len);
b[0] = 0;
Expand All @@ -175,7 +175,7 @@ function caml_make_vect(len, init) {
//Provides: caml_make_float_vect const (const)
//Requires: caml_array_bound_error
function caml_make_float_vect(len) {
if (len < 0) caml_array_bound_error();
if (len < 0 || (len >= 0x7fffffff / 8) | 0) caml_array_bound_error();
var len = (len + 1) | 0;
var b = new Array(len);
b[0] = 254;
Expand All @@ -187,7 +187,7 @@ function caml_make_float_vect(len) {
//Requires: caml_array_bound_error
//Version: >= 5.3
function caml_array_create_float(len) {
if (len < 0) caml_array_bound_error();
if (len < 0 || (len >= 0x7fffffff / 8) | 0) caml_array_bound_error();
var len = (len + 1) | 0;
var b = new Array(len);
b[0] = 254;
Expand All @@ -197,7 +197,7 @@ function caml_array_create_float(len) {
//Provides: caml_floatarray_create const (const)
//Requires: caml_array_bound_error
function caml_floatarray_create(len) {
if (len < 0) caml_array_bound_error();
if (len < 0 || (len >= 0x7fffffff / 8) | 0) caml_array_bound_error();
var len = (len + 1) | 0;
var b = new Array(len);
b[0] = 254;
Expand All @@ -206,17 +206,22 @@ function caml_floatarray_create(len) {
}

//Provides: caml_floatarray_make const (const)
//Requires: caml_array_make
//Requires: caml_array_bound_error
//Version: >= 5.3
function caml_floatarray_make(len, init) {
return caml_array_make(len, init);
if (len < 0 || (len >= 0x7fffffff / 8) | 0) caml_array_bound_error();
var len = (len + 1) | 0;
var b = new Array(len);
b[0] = 254;
for (var i = 1; i < len; i++) b[i] = init;
return b;
}

//Provides: caml_floatarray_make_unboxed const (const)
//Requires: caml_array_make
//Requires: caml_floatarray_make
//Version: >= 5.3
function caml_floatarray_make_unboxed(len, init) {
return caml_array_make(len, init);
return caml_floatarray_make(len, init);
}

//Provides: caml_uniform_array_make const (const)
Expand Down

0 comments on commit 3527686

Please sign in to comment.