X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=ocaml%2Ftest.ml;fp=ocaml%2Ftest.ml;h=0000000000000000000000000000000000000000;hb=21c829a0b518a725f4db3d21250ad00dcf3bb889;hp=629bf894ac082d9dfe564b0a31c349c3e7e6b812;hpb=4c157f176c89dcb5633d60c5be8a444ae0529c29;p=fireball-separation.git diff --git a/ocaml/test.ml b/ocaml/test.ml deleted file mode 100644 index 629bf89..0000000 --- a/ocaml/test.ml +++ /dev/null @@ -1,109 +0,0 @@ -open Lambda4;; -open Util;; - -let acaso l = - let n = Random.int (List.length l) in - List.nth l n -;; - -let acaso2 l1 l2 = - let n1 = List.length l1 in - let n = Random.int (n1 + List.length l2) in - if n >= n1 then List.nth l2 (n - n1) else List.nth l1 n -;; - -(** with bombs and pacmans too *) -let acaso3 l1 l2 = - if Random.int 10 = 0 then ( - if Random.int 2 = 0 then "BOMB" else "PAC" - ) else - let n1 = List.length l1 in - let n = Random.int (n1 + List.length l2) in - if n >= n1 then List.nth l2 (n - n1) else List.nth l1 n -;; - -(* let rec take l n = - if n = 0 then [] - else match l with - | [] -> [] - | x::xs -> x :: (take xs (n-1)) -;; *) - -let gen n vars = - let rec take' l n = - if n = 0 then [], [] - else match l with - | [] -> [], [] - | [_] -> assert false - | x1::x2::xs -> let a, b = take' xs (n-1) in x1::a,x2::b in - let rec aux n inerts lams = - if n = 0 then List.hd inerts, take' (Util.sort_uniq (List.tl inerts)) 5 - else let inerts, lams = if Random.int 2 = 0 - then inerts, ("(" ^ acaso vars ^ ". " ^ acaso2 inerts lams ^ ")") :: lams - else ("(" ^ acaso inerts ^ " " ^ acaso2 inerts lams^ ")") :: inerts, lams - in aux (n-1) inerts lams - in aux (2*n) vars [] -;; - -let gen_pac n vars = - let rec take' l n = - if n = 0 then [], [] - else match l with - | [] -> [], [] - | [_] -> assert false - | x1::x2::xs -> let a, b = take' xs (n-1) in x1::a,x2::b in - let rec aux n inerts lams = - if n = 0 then List.hd inerts, take' (Util.sort_uniq (List.tl inerts)) 5 - else let inerts, lams = if Random.int 2 = 0 - then inerts, ("(" ^ acaso vars ^ ". " ^ acaso3 inerts lams ^ ")") :: lams - else ("(" ^ acaso inerts ^ " " ^ acaso3 inerts lams^ ")") :: inerts, lams - in aux (n-1) inerts lams - in aux (2*n) vars [] -;; - - -let rec repeat f n = - prerr_endline "\n########################### NEW TEST ###########################"; - f () ; - if n > 0 then repeat f (n-1) -;; - -let solve div convs nums label = - let p = String.concat "\n" ( - ("$! randomly generated test " ^ label) :: - ("D " ^ div) :: - List.map ((^) "C ") convs @ - List.map (fun s -> "N " ^ s ^ " Z") nums - ) in - prerr_endline p; - match (Lambda4.solve ++ Lambda4.problem_of ++ Parser.problem_of_string) p with - | `Uncomplete, `Unseparable _ -> - failwith ("Test4.solve: unseparable, and cannot tell if that's right or not.") - | _ -> () -;; - -let main = - Random.self_init (); - (* num = number of tests to run *) - let num = 100 in - (* if flag --with-pac active, then more general tests *) - let with_pac = List.mem "--with-pac" (Array.to_list Sys.argv) in - - let label, f = if with_pac - then ( - let complex = 10 in - let vars = ["x"; "y"; "z"; "v" ; "w"; "a"; "b"; "c"] in - "with pacmans & bombs", fun () -> gen_pac complex vars - ) else ( - let complex = 200 in - let vars = ["x"; "y"; "z"; "v" ; "w"; "a"; "b"; "c"] in - "", fun () -> gen complex vars - ) in - - repeat (fun _ -> - let div, (conv, nums) = f () in - solve div conv nums label - ) num; - - prerr_endline "\n---- ALL TESTS COMPLETED ----" -;;