]> matita.cs.unibo.it Git - fireball-separation.git/blob - ocaml/test.ml
Copy ocaml folder from sacerdot's svn repository, rev 4907
[fireball-separation.git] / ocaml / test.ml
1 let three = Array.length Sys.argv = 1;;
2
3 let discriminator =
4  if three
5  then (module Lambda3 : Discriminator.Discriminator)
6  else (module Lambda4);;
7
8 module Pippo = (val discriminator);;
9 open Pippo;;
10
11 let acaso l =
12     let n = Random.int (List.length l) in
13     List.nth l n
14 ;;
15
16 let acaso2 l1 l2 =
17   let n1 = List.length l1 in
18   let n = Random.int (n1 + List.length l2) in
19   if n >= n1 then List.nth l2 (n - n1) else List.nth l1 n
20 ;;
21
22 let rec take l n =
23   if n = 0 then []
24   else match l with
25   | [] -> []
26   | x::xs -> x :: (take xs (n-1))
27 ;;
28
29 let test3 n vars =
30   let rec aux n inerts lams =
31     if n = 0 then take (Util.sort_uniq inerts) 5
32     else let inerts, lams = if Random.int 2 = 0
33       then inerts, ("(" ^ acaso vars ^ ". " ^ acaso2 inerts lams ^ ")") :: lams
34       else ("(" ^ acaso inerts ^ " " ^ acaso2 inerts lams^ ")") :: inerts, lams
35     in aux (n-1) inerts lams
36   in aux (2*n) vars []
37 ;;
38
39 let test4 n vars =
40   let rec take' l n =
41     if n = 0 then [], []
42     else match l with
43     | [] -> [], []
44     | [_] -> assert false
45     | x1::x2::xs -> let a, b = take' xs (n-1) in x1::a,x2::b in
46   let rec aux n inerts lams =
47     if n = 0 then List.hd inerts, take' (Util.sort_uniq (List.tl inerts)) 5
48     else let inerts, lams = if Random.int 2 = 0
49       then inerts, ("(" ^ acaso vars ^ ". " ^ acaso2 inerts lams ^ ")") :: lams
50       else ("(" ^ acaso inerts ^ " " ^ acaso2 inerts lams^ ")") :: inerts, lams
51     in aux (n-1) inerts lams
52   in aux (2*n) vars []
53 ;;
54
55
56 let rec repeat f n =
57   prerr_endline "\n*************************** NEW TEST ***************************";
58   f () ;
59   if n > 0 then repeat f (n-1)
60 ;;
61
62 let call_main3 tms =
63   let _ = (
64   List.iter prerr_endline tms; prerr_newline ();
65   ) in Lambda3.main [Lambda3.magic tms ["*"]]
66 ;;
67 let call_main4 div convs nums =
68   let _ = (
69   (match div with Some div -> prerr_endline ("DIV: " ^ div) | None -> ());
70   print_endline "CONV:"; List.iter prerr_endline convs;
71   print_endline "NUMS:"; List.iter prerr_endline nums;
72   prerr_newline ();
73   ) in Lambda4.main [Lambda4.magic_conv div convs nums ["*"]]
74 ;;
75
76 let main =
77   Random.self_init ();
78   let num = 100 in
79   let complex = 200 in
80   let vars = ["x"; "y"; "z"; "v" ; "w"; "a"; "b"; "c"] in
81
82   (* let open Parser in *)
83
84   if three then repeat (fun _ ->
85     let tms = test3 complex vars in
86     call_main3 tms
87   ) num
88   else repeat (fun _ ->
89     let div, (conv, nums) = test4 complex vars in
90     call_main4 (Some div) conv nums
91   ) num
92   ;
93
94   prerr_endline "\n---- ALL TESTS COMPLETED ----"
95 ;;