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