open Simple;; open Util;; let with_const = List.mem "--with-const" (Array.to_list Sys.argv) ;; 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 ;; let gen n vars = let rec take' l n = if n = 0 then [] else match l with | [] -> [] | [_] -> assert false | x::_::xs -> x :: take' xs (n-1) 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 let inerts = if with_const then "C" :: vars else vars in aux (2*n) inerts [] ;; let rec repeat f n = print_endline "\n########################### NEW TEST ###########################"; f () ; if n > 0 then repeat f (n-1) ;; let main = Random.self_init (); let num = 100 in let complex = 100 in let no_bound_vars = 10 in let vars = Array.to_list (Array.init no_bound_vars (fun x -> "x" ^ string_of_int x)) in let file = Filename.temp_file ~temp_dir:"./problems/" "simple.constants.auto." "" in let oc = open_out file in print_endline ("\n\n---- " ^ file) ; repeat (fun _ -> let div, convs = gen complex vars in let str = " \nD " ^ div ^ String.concat "\nC " convs ^ "\n" in print_endline str; try (solve ++ problem_of ++ Parser.problem_of_string) ("$" ^ str) with Simple.Fail _ as e -> let str = "$ failing test problem \n# Failed because: " ^ Printexc.to_string e ^ str in Printf.fprintf oc "%s\n" str ) num ; close_out oc; print_endline ("\n\n---- " ^ file); let filesize filename = let ic = open_in filename in let size = in_channel_length ic in close_in ic ; size in if filesize file = 0 then (print_endline "---- All tests succeeded."; Sys.remove file ) else (print_endline ("---- Not all tests succeeded. See " ^ file)) ;;