]> matita.cs.unibo.it Git - fireball-separation.git/blob - ocaml/simple_test.ml
9618113794f6c7ad9c25982ee67924b947c755a4
[fireball-separation.git] / ocaml / simple_test.ml
1 open Simple;;
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 gen n vars =
16   let rec take' l n =
17     if n = 0 then []
18     else match l with
19     | [] -> []
20     | [_] -> assert false
21     | x::_::xs -> x :: take' xs (n-1) in
22   let rec aux n inerts lams =
23     if n = 0 then List.hd inerts, take' (Util.sort_uniq (List.tl inerts)) 5
24     else let inerts, lams = if Random.int 2 = 0
25       then inerts, ("(" ^ acaso vars ^ ". " ^ acaso2 inerts lams ^ ")") :: lams
26       else ("(" ^ acaso inerts ^ " " ^ acaso2 inerts lams^ ")") :: inerts, lams
27     in aux (n-1) inerts lams
28   in aux (2*n) vars []
29 ;;
30
31
32 let rec repeat f n =
33   prerr_endline "\n########################### NEW TEST ###########################";
34   f () ;
35   if n > 0 then repeat f (n-1)
36 ;;
37
38 let main =
39   Random.self_init ();
40   let num = 100 in
41   let complex = 200 in
42   let vars = ["x"; "y"; "z"; "v" ; "w"; "a"; "b"; "c"] in
43
44   repeat (fun _ ->
45     let div, convs = gen complex vars in
46     Simple.solve div convs
47   ) num ;
48
49   prerr_endline "\n---- ALL TESTS COMPLETED ----"
50 ;;