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