if n >= n1 then List.nth l2 (n - n1) else List.nth l1 n
;;
-let rec take l 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 test3 n vars =
- let rec aux n inerts lams =
- if n = 0 then take (Util.sort_uniq 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 test4 n vars =
+let gen n vars =
let rec take' l n =
if n = 0 then [], []
else match l with
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 ***************************";
+ prerr_endline "\n########################### NEW TEST ###########################";
f () ;
if n > 0 then repeat f (n-1)
;;
-(* let call_main3 tms =
- let _ = (
- List.iter prerr_endline tms; prerr_newline ();
- ) in Lambda3.main [Lambda3.magic tms ["*"]]
-;; *)
-let call_main4 div convs nums =
+let solve div convs nums =
let p = String.concat "\n" (
"$! randomly generated test" ::
("D " ^ div) ::
;;
let main =
- Random.self_init ();
- let num = 100 in
- let complex = 200 in
- let vars = ["x"; "y"; "z"; "v" ; "w"; "a"; "b"; "c"] in
+ 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 open Parser in *)
+ let f = if with_pac
+ then (
+ let complex = 10 in
+ let vars = ["x"; "y"; "z"; "v" ; "w"; "a"; "b"; "c"] in
+ 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
- (* if three then repeat (fun _ ->
- let tms = test3 complex vars in
- call_main3 tms
- ) num
- else *)
- repeat (fun _ ->
- let div, (conv, nums) = test4 complex vars in
- call_main4 div conv nums
- ) num
- ;
+ repeat (fun _ ->
+ let div, (conv, nums) = f () in
+ solve div conv nums
+ ) num;
- prerr_endline "\n---- ALL TESTS COMPLETED ----"
+ prerr_endline "\n---- ALL TESTS COMPLETED ----"
;;