Commits

Yit Phang Khoo  committed f329d1b

Add array and option generators to MyOUnit.QC.

  • Participants
  • Parent commits 2e87049

Comments (0)

Files changed (1)

File Test/TestUtil/MyOUnit.ml

 let list_printer printer sep ff list =
     ignore (List.fold_left (fun b x -> Format.fprintf ff "%(%)@[%a@]" b printer x; sep) "" list)
 
+let array_printer printer sep ff arr =
+    ignore (Array.fold_left (fun b x -> Format.fprintf ff "%(%)@[%a@]" b printer x; sep) "" arr)
+
 
 (*
  * QuickCheck
             make (Random.State.int rng size) []
         method print ff = Format.fprintf ff "[@[%a@]@,]" (list_printer gx#print sep)
     end
+    let array ?(sep=format_of_string ";@ ") gx = object
+        method generate rng size = Array.init (Random.State.int rng size) (fun k -> gx#generate rng size)
+        method print ff = Format.fprintf ff "[|@[%a@]@,|]" (array_printer gx#print sep)
+    end
+    let option gx = object
+        method generate rng size = if Random.State.bool rng then Some (gx#generate rng size) else None
+        method print ff = option_printer gx#print ff
+    end
 
     (* test predicate *)
     let forall ?(rng=Random.State.make_self_init ()) ?(count=100) ?(size=fun n -> 3 + n / 2) ?(incl=[]) ?(where=fun _ -> true) input testfn = fun () ->