equal
deleted
inserted
replaced
35 type constant_table = (string * string) list |
35 type constant_table = (string * string) list |
36 |
36 |
37 val generate : Predicate_Compile_Aux.mode option * bool -> |
37 val generate : Predicate_Compile_Aux.mode option * bool -> |
38 Proof.context -> string -> (logic_program * constant_table) |
38 Proof.context -> string -> (logic_program * constant_table) |
39 val write_program : logic_program -> string |
39 val write_program : logic_program -> string |
40 val run : (Time.time * prolog_system) -> logic_program -> (string * prol_term list) -> string list -> int option -> prol_term list list |
40 val run : (Time.time * prolog_system) -> logic_program -> (string * prol_term list) -> |
41 |
41 string list -> int option -> prol_term list list |
42 val quickcheck : Proof.context -> (term * term list) list -> int list -> term list option * Quickcheck.report option |
42 |
|
43 val active : bool Config.T |
|
44 val test_goals : |
|
45 Proof.context -> (bool * bool) -> (string * typ) list -> (term * term list) list -> |
|
46 Quickcheck.result list |
43 |
47 |
44 val trace : bool Unsynchronized.ref |
48 val trace : bool Unsynchronized.ref |
45 |
49 |
46 val replace : ((string * string) * string) -> logic_program -> logic_program |
50 val replace : ((string * string) * string) -> logic_program -> logic_program |
47 end; |
51 end; |
1007 |
1011 |
1008 (* quickcheck generator *) |
1012 (* quickcheck generator *) |
1009 |
1013 |
1010 (* FIXME: a small clone of Predicate_Compile_Quickcheck - maybe refactor out commons *) |
1014 (* FIXME: a small clone of Predicate_Compile_Quickcheck - maybe refactor out commons *) |
1011 |
1015 |
1012 fun quickcheck ctxt [(t, [])] [_, size] = |
1016 val active = Attrib.setup_config_bool @{binding quickcheck_prolog_active} (K true); |
|
1017 |
|
1018 fun test_term ctxt (limit_time, is_interactive) (t, eval_terms) = |
1013 let |
1019 let |
1014 val t' = list_abs_free (Term.add_frees t [], t) |
1020 val t' = list_abs_free (Term.add_frees t [], t) |
1015 val options = code_options_of (Proof_Context.theory_of ctxt) |
1021 val options = code_options_of (Proof_Context.theory_of ctxt) |
1016 val thy = Theory.copy (Proof_Context.theory_of ctxt) |
1022 val thy = Theory.copy (Proof_Context.theory_of ctxt) |
1017 val ((((full_constname, constT), vs'), intro), thy1) = |
1023 val ((((full_constname, constT), vs'), intro), thy1) = |
1025 val _ = tracing "Running prolog program..." |
1031 val _ = tracing "Running prolog program..." |
1026 val system_config = System_Config.get (Context.Proof ctxt) |
1032 val system_config = System_Config.get (Context.Proof ctxt) |
1027 val tss = run (#timeout system_config, #prolog_system system_config) |
1033 val tss = run (#timeout system_config, #prolog_system system_config) |
1028 p (translate_const constant_table full_constname, map (Var o fst) vs') (map fst vs') (SOME 1) |
1034 p (translate_const constant_table full_constname, map (Var o fst) vs') (map fst vs') (SOME 1) |
1029 val _ = tracing "Restoring terms..." |
1035 val _ = tracing "Restoring terms..." |
1030 val res = |
1036 val counterexample = |
1031 case tss of |
1037 case tss of |
1032 [ts] => SOME (map (restore_term ctxt' constant_table) (ts ~~ map snd vs')) |
1038 [ts] => SOME (map (restore_term ctxt' constant_table) (ts ~~ map snd vs')) |
1033 | _ => NONE |
1039 | _ => NONE |
1034 in |
1040 in |
1035 (res, NONE) |
1041 Quickcheck.Result |
1036 end; |
1042 {counterexample = Option.map ((curry (op ~~)) (Term.add_free_names t [])) counterexample, |
1037 |
1043 evaluation_terms = Option.map (K []) counterexample, timings = [], reports = []} |
|
1044 end; |
|
1045 |
|
1046 fun test_goals ctxt (limit_time, is_interactive) insts goals = |
|
1047 let |
|
1048 val correct_inst_goals = Quickcheck.instantiate_goals ctxt insts goals |
|
1049 in |
|
1050 Quickcheck.collect_results (test_term ctxt (limit_time, is_interactive)) (maps (map snd) correct_inst_goals) [] |
|
1051 end |
|
1052 |
|
1053 |
1038 end; |
1054 end; |