]> matita.cs.unibo.it Git - fireball-separation.git/blob - ocaml/simple_test.ml
New interesting example
[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 = 100 in
42   let no_bound_vars = 10 in
43   let vars = Array.to_list
44    (Array.init no_bound_vars (fun x -> "x" ^ string_of_int x)) in
45
46   repeat (fun _ ->
47     let div, convs = gen complex vars in
48     let str = "$ random simple test \nD " ^ div ^ String.concat "\nC " convs ^ "\n" in
49     print_endline str;
50     let open Simple in
51     (solve ++ problem_of ++ Parser.problem_of_string) str
52   ) num ;
53
54   prerr_endline "\n---- ALL TESTS COMPLETED ----"
55 ;;