]> matita.cs.unibo.it Git - fireball-separation.git/blobdiff - ocaml/test.ml
Copy ocaml folder from sacerdot's svn repository, rev 4907
[fireball-separation.git] / ocaml / test.ml
diff --git a/ocaml/test.ml b/ocaml/test.ml
new file mode 100644 (file)
index 0000000..2f6017a
--- /dev/null
@@ -0,0 +1,95 @@
+let three = Array.length Sys.argv = 1;;
+
+let discriminator =
+ if three
+ then (module Lambda3 : Discriminator.Discriminator)
+ else (module Lambda4);;
+
+module Pippo = (val discriminator);;
+open Pippo;;
+
+let acaso l =
+    let n = Random.int (List.length l) in
+    List.nth l n
+;;
+
+let acaso2 l1 l2 =
+  let n1 = List.length l1 in
+  let n = Random.int (n1 + List.length l2) in
+  if n >= n1 then List.nth l2 (n - n1) else List.nth l1 n
+;;
+
+let rec take l n =
+  if n = 0 then []
+  else match l with
+  | [] -> []
+  | x::xs -> x :: (take xs (n-1))
+;;
+
+let test3 n vars =
+  let rec aux n inerts lams =
+    if n = 0 then take (Util.sort_uniq inerts) 5
+    else let inerts, lams = if Random.int 2 = 0
+      then inerts, ("(" ^ acaso vars ^ ". " ^ acaso2 inerts lams ^ ")") :: lams
+      else ("(" ^ acaso inerts ^ " " ^ acaso2 inerts lams^ ")") :: inerts, lams
+    in aux (n-1) inerts lams
+  in aux (2*n) vars []
+;;
+
+let test4 n vars =
+  let rec take' l n =
+    if n = 0 then [], []
+    else match l with
+    | [] -> [], []
+    | [_] -> assert false
+    | x1::x2::xs -> let a, b = take' xs (n-1) in x1::a,x2::b in
+  let rec aux n inerts lams =
+    if n = 0 then List.hd inerts, take' (Util.sort_uniq (List.tl inerts)) 5
+    else let inerts, lams = if Random.int 2 = 0
+      then inerts, ("(" ^ acaso vars ^ ". " ^ acaso2 inerts lams ^ ")") :: lams
+      else ("(" ^ acaso inerts ^ " " ^ acaso2 inerts lams^ ")") :: inerts, lams
+    in aux (n-1) inerts lams
+  in aux (2*n) vars []
+;;
+
+
+let rec repeat f n =
+  prerr_endline "\n*************************** NEW TEST ***************************";
+  f () ;
+  if n > 0 then repeat f (n-1)
+;;
+
+let call_main3 tms =
+  let _ = (
+  List.iter prerr_endline tms; prerr_newline ();
+  ) in Lambda3.main [Lambda3.magic tms ["*"]]
+;;
+let call_main4 div convs nums =
+  let _ = (
+  (match div with Some div -> prerr_endline ("DIV: " ^ div) | None -> ());
+  print_endline "CONV:"; List.iter prerr_endline convs;
+  print_endline "NUMS:"; List.iter prerr_endline nums;
+  prerr_newline ();
+  ) in Lambda4.main [Lambda4.magic_conv div convs nums ["*"]]
+;;
+
+let main =
+  Random.self_init ();
+  let num = 100 in
+  let complex = 200 in
+  let vars = ["x"; "y"; "z"; "v" ; "w"; "a"; "b"; "c"] in
+
+  (* let open Parser in *)
+
+  if three then repeat (fun _ ->
+    let tms = test3 complex vars in
+    call_main3 tms
+  ) num
+  else repeat (fun _ ->
+    let div, (conv, nums) = test4 complex vars in
+    call_main4 (Some div) conv nums
+  ) num
+  ;
+
+  prerr_endline "\n---- ALL TESTS COMPLETED ----"
+;;