Skip to content

Commit 0816f95

Browse files
authored
Merge pull request #568 from AltGr/noloop
fix(grading): avoid failing on sampling arrays with unique elements
2 parents cad060f + 6a3ce07 commit 0816f95

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/grader/test_lib.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1762,7 +1762,7 @@ module Make
17621762
if dups then sample else
17631763
let prev = Hashtbl.create max_size in
17641764
let rec sample_new steps =
1765-
if steps = 0 then invalid_arg "sample_array" else
1765+
if steps = 0 then sample () else
17661766
let s = sample () in
17671767
try Hashtbl.find prev s ; sample_new (steps - 1)
17681768
with Not_found -> Hashtbl.add prev s () ; s in

src/grader/test_lib.mli

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,9 @@ module type S = sig
466466
sorted.
467467
468468
If [~dups:false] ([true] by default), all elements of generated
469-
array are unique.*)
469+
arrays are unique, or at least try hard to be in a reasonable time:
470+
if the codomain of [sampler] is too small there might still be
471+
duplicates.*)
470472
val sample_array :
471473
?min_size: int -> ?max_size: int -> ?dups: bool -> ?sorted: bool
472474
-> 'a sampler

0 commit comments

Comments
 (0)