264 Attrib.empty_binding, random_def))) random_defs') |
264 Attrib.empty_binding, random_def))) random_defs') |
265 |> snd |
265 |> snd |
266 |> Class.prove_instantiation_exit (K (Class.intro_classes_tac [])) |
266 |> Class.prove_instantiation_exit (K (Class.intro_classes_tac [])) |
267 end; |
267 end; |
268 |
268 |
|
269 |
269 (** building and compiling generator expressions **) |
270 (** building and compiling generator expressions **) |
270 |
271 |
271 (* FIXME just one data slot (record) per program unit *) |
272 structure Data = Proof_Data |
272 |
|
273 structure Counterexample = Proof_Data |
|
274 ( |
273 ( |
275 type T = unit -> Code_Numeral.natural -> bool -> Code_Numeral.natural -> seed -> (bool * term list) option * seed |
274 type T = |
276 fun init _ () = raise Fail "Counterexample" |
275 (unit -> Code_Numeral.natural -> bool -> Code_Numeral.natural -> seed -> |
|
276 (bool * term list) option * seed) * |
|
277 (unit -> Code_Numeral.natural -> bool -> Code_Numeral.natural -> seed -> |
|
278 ((bool * term list) option * (bool list * bool)) * seed); |
|
279 val empty: T = |
|
280 (fn () => raise Fail "counterexample", |
|
281 fn () => raise Fail "counterexample_report"); |
|
282 fun init _ = empty; |
277 ); |
283 ); |
278 val put_counterexample = Counterexample.put; |
284 |
279 |
285 val get_counterexample = #1 o Data.get; |
280 structure Counterexample_Report = Proof_Data |
286 val get_counterexample_report = #2 o Data.get; |
281 ( |
287 |
282 type T = unit -> Code_Numeral.natural -> bool -> Code_Numeral.natural -> seed -> ((bool * term list) option * (bool list * bool)) * seed |
288 val put_counterexample = Data.map o @{apply 2(1)} o K; |
283 fun init _ () = raise Fail "Counterexample_Report" |
289 val put_counterexample_report = Data.map o @{apply 2(2)} o K; |
284 ); |
|
285 val put_counterexample_report = Counterexample_Report.put; |
|
286 |
290 |
287 val target = "Quickcheck"; |
291 val target = "Quickcheck"; |
288 |
292 |
289 fun mk_generator_expr ctxt (t, _) = |
293 fun mk_generator_expr ctxt (t, _) = |
290 let |
294 let |
405 val iterations = Config.get ctxt Quickcheck.iterations |
409 val iterations = Config.get ctxt Quickcheck.iterations |
406 in |
410 in |
407 if Config.get ctxt Quickcheck.report then |
411 if Config.get ctxt Quickcheck.report then |
408 let |
412 let |
409 val t' = mk_parametric_reporting_generator_expr ctxt ts; |
413 val t' = mk_parametric_reporting_generator_expr ctxt ts; |
410 val compile = Code_Runtime.dynamic_value_strict |
414 val compile = |
411 (Counterexample_Report.get, put_counterexample_report, "Random_Generators.put_counterexample_report") |
415 Code_Runtime.dynamic_value_strict |
412 ctxt (SOME target) |
416 (get_counterexample_report, put_counterexample_report, |
413 (fn proc => fn g => fn c => fn b => fn s => g c b s |
417 "Random_Generators.put_counterexample_report") |
414 #>> (apfst o Option.map o apsnd o map) proc) t' []; |
418 ctxt (SOME target) |
|
419 (fn proc => fn g => fn c => fn b => fn s => |
|
420 g c b s #>> (apfst o Option.map o apsnd o map) proc) |
|
421 t' []; |
415 fun single_tester c b s = compile c b s |> Random_Engine.run |
422 fun single_tester c b s = compile c b s |> Random_Engine.run |
416 fun iterate_and_collect _ _ 0 report = (NONE, report) |
423 fun iterate_and_collect _ _ 0 report = (NONE, report) |
417 | iterate_and_collect genuine_only (card, size) j report = |
424 | iterate_and_collect genuine_only (card, size) j report = |
418 let |
425 let |
419 val (test_result, single_report) = apsnd Run (single_tester card genuine_only size) |
426 val (test_result, single_report) = apsnd Run (single_tester card genuine_only size) |
427 apsnd SOME (iterate_and_collect genuine_only (card, size) iterations empty_report) |
434 apsnd SOME (iterate_and_collect genuine_only (card, size) iterations empty_report) |
428 end |
435 end |
429 else |
436 else |
430 let |
437 let |
431 val t' = mk_parametric_generator_expr ctxt ts; |
438 val t' = mk_parametric_generator_expr ctxt ts; |
432 val compile = Code_Runtime.dynamic_value_strict |
439 val compile = |
433 (Counterexample.get, put_counterexample, "Random_Generators.put_counterexample") |
440 Code_Runtime.dynamic_value_strict |
434 ctxt (SOME target) |
441 (get_counterexample, put_counterexample, "Random_Generators.put_counterexample") |
435 (fn proc => fn g => fn c => fn b => fn s => g c b s |
442 ctxt (SOME target) |
436 #>> (Option.map o apsnd o map) proc) t' []; |
443 (fn proc => fn g => fn c => fn b => fn s => |
|
444 g c b s #>> (Option.map o apsnd o map) proc) |
|
445 t' []; |
437 fun single_tester c b s = compile c b s |> Random_Engine.run |
446 fun single_tester c b s = compile c b s |> Random_Engine.run |
438 fun iterate _ _ 0 = NONE |
447 fun iterate _ _ 0 = NONE |
439 | iterate genuine_only (card, size) j = |
448 | iterate genuine_only (card, size) j = |
440 case single_tester card genuine_only size of |
449 case single_tester card genuine_only size of |
441 NONE => iterate genuine_only (card, size) (j - 1) |
450 NONE => iterate genuine_only (card, size) (j - 1) |