File: binary_string_roundtrip.ml

package info (click to toggle)
ocaml-stdlib-random 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 332 kB
  • sloc: ml: 1,767; ansic: 42; makefile: 3
file content (27 lines) | stat: -rw-r--r-- 696 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module type state = sig
  type t
  val to_binary_string : t -> string
  val of_binary_string : string -> t
end

module type random = sig
  module State: state
  val init: int -> unit
  val get_state: unit -> State.t
end

let test name (module R: random) =
  let init n = R.init n; R.get_state () in

  let roundtrip seed =
    let s = init seed in
    s = R.State.(of_binary_string @@ to_binary_string s)
  in
  if not @@ List.for_all roundtrip (List.init 100 Fun.id) then
    failwith (Format.asprintf "Roundtrip failed for %s generator" name)

let () =
  test "random3" (module Random3);
  test "random4" (module Random4);
  test "random5" (module Random5);
  test "random5o" (module Random5o)