]> matita.cs.unibo.it Git - fireball-separation.git/blob - ocaml/test1.ml
424ec72304b5f9b31352858ed9cda6a07558aa98
[fireball-separation.git] / ocaml / test1.ml
1
2
3 let acaso l =
4     let n = Random.int (List.length l) in
5     List.nth l n
6 ;;
7
8 let acaso2 l1 l2 =
9   let n1 = List.length l1 in
10   let n = Random.int (n1 + List.length l2) in
11   if n >= n1 then List.nth l2 (n - n1) else List.nth l1 n
12 ;;
13
14 let rec take l n =
15   if n = 0 then []
16   else match l with
17   | [] -> []
18   | x::xs -> x :: (take xs (n-1))
19 ;;
20
21 let test1 n vars =
22   let rec aux n l =
23     if n = 0
24       then take (Util.sort_uniq l) 3
25       else aux (n-1) (("(" ^ (acaso l) ^ " " ^ (acaso l) ^ ")") :: l)
26   in aux n vars
27 ;;
28
29 let test2 n vars =
30   let rec aux n ins lams =
31     if n = 0 then take (Util.sort_uniq ins) 5
32     else let ins, lams = if Random.int 2 = 0
33       then ins, ("(" ^ acaso vars ^ ". " ^ acaso2 ins lams ^ ")") :: lams
34       else ("(" ^ acaso ins ^ " " ^ acaso2 ins lams^ ")") :: ins, lams
35     in aux (n-1) ins lams
36   in aux (2*n) vars []
37 ;;
38
39
40 let rec repeat f n = f () ; if n > 0 then repeat f (n-1);;
41
42 let call_main tms =
43   let _ = (
44   prerr_endline "\n*************************** NEW TEST ***************************";
45   List.iter prerr_endline tms; prerr_endline "";
46   ) in Lambda3.main [Lambda3.magic tms ["*"]]
47 ;;
48
49 let main =
50   Random.self_init ();
51   (*Random.init 1000;*)
52   let num = 100 in
53   let complex = 200 in
54   let vars = ["x"; "y"; "z"; "v" ; "w"; "a"; "b"; "c"] in
55
56   let open Parser in
57   let open Lambda3 in
58
59   (* test1 *)
60   repeat (fun _ ->
61     let tms = test1 complex vars in
62     call_main tms
63   ) num
64   ;
65
66   (* test2 *)
67   repeat (fun _ ->
68     call_main (test2 complex vars)
69   ) num
70   ;
71
72   prerr_endline "\n---- ALL TESTS COMPLETED ----"
73 ;;