4 Exhaustive generators for various types. |
4 Exhaustive generators for various types. |
5 *) |
5 *) |
6 |
6 |
7 signature EXHAUSTIVE_GENERATORS = |
7 signature EXHAUSTIVE_GENERATORS = |
8 sig |
8 sig |
9 val exhaustive_interpretation: string |
9 val exhaustive_plugin: string |
10 val bounded_forall_interpretation: string |
10 val bounded_forall_plugin: string |
11 val full_exhaustive_interpretation: string |
11 val full_exhaustive_plugin: string |
12 |
12 |
13 val compile_generator_expr: |
13 val compile_generator_expr: |
14 Proof.context -> (term * term list) list -> bool -> int list -> (bool * term list) option * Quickcheck.report option |
14 Proof.context -> (term * term list) list -> bool -> int list -> (bool * term list) option * Quickcheck.report option |
15 val compile_generator_exprs: Proof.context -> term list -> (int -> term list option) list |
15 val compile_generator_exprs: Proof.context -> term list -> (int -> term list option) list |
16 val compile_validator_exprs: Proof.context -> term list -> (int -> bool) list |
16 val compile_validator_exprs: Proof.context -> term list -> (int -> bool) list |
37 structure Exhaustive_Generators : EXHAUSTIVE_GENERATORS = |
37 structure Exhaustive_Generators : EXHAUSTIVE_GENERATORS = |
38 struct |
38 struct |
39 |
39 |
40 (* basics *) |
40 (* basics *) |
41 |
41 |
42 val exhaustive_interpretation = "exhaustive" |
42 val exhaustive_plugin = "exhaustive" |
43 val bounded_forall_interpretation = "bounded_forall" |
43 val bounded_forall_plugin = "bounded_forall" |
44 val full_exhaustive_interpretation = "full_exhaustive" |
44 val full_exhaustive_plugin = "full_exhaustive" |
45 |
45 |
46 |
46 |
47 (** dynamic options **) |
47 (** dynamic options **) |
48 |
48 |
49 val smart_quantifier = Attrib.setup_config_bool @{binding quickcheck_smart_quantifier} (K true) |
49 val smart_quantifier = Attrib.setup_config_bool @{binding quickcheck_smart_quantifier} (K true) |
541 Quickcheck_Common.generator_test_goal_terms ("exhaustive", (size_matters_for, compile_generator_expr)); |
541 Quickcheck_Common.generator_test_goal_terms ("exhaustive", (size_matters_for, compile_generator_expr)); |
542 |
542 |
543 (* setup *) |
543 (* setup *) |
544 |
544 |
545 val setup_exhaustive_datatype_interpretation = |
545 val setup_exhaustive_datatype_interpretation = |
546 Quickcheck_Common.datatype_interpretation exhaustive_interpretation |
546 Quickcheck_Common.datatype_interpretation exhaustive_plugin |
547 (@{sort exhaustive}, instantiate_exhaustive_datatype) |
547 (@{sort exhaustive}, instantiate_exhaustive_datatype) |
548 |
548 |
549 val setup_bounded_forall_datatype_interpretation = |
549 val setup_bounded_forall_datatype_interpretation = |
550 BNF_LFP_Compat.interpretation bounded_forall_interpretation BNF_LFP_Compat.Keep_Nesting |
550 BNF_LFP_Compat.interpretation bounded_forall_plugin BNF_LFP_Compat.Keep_Nesting |
551 (Quickcheck_Common.ensure_sort |
551 (Quickcheck_Common.ensure_sort |
552 (((@{sort type}, @{sort type}), @{sort bounded_forall}), |
552 (((@{sort type}, @{sort type}), @{sort bounded_forall}), |
553 (fn thy => BNF_LFP_Compat.the_descr thy BNF_LFP_Compat.Keep_Nesting, instantiate_bounded_forall_datatype))) |
553 (fn thy => BNF_LFP_Compat.the_descr thy BNF_LFP_Compat.Keep_Nesting, instantiate_bounded_forall_datatype))) |
554 |
554 |
555 val active = Attrib.setup_config_bool @{binding quickcheck_exhaustive_active} (K true); |
555 val active = Attrib.setup_config_bool @{binding quickcheck_exhaustive_active} (K true); |
556 |
556 |
557 val setup = |
557 val setup = |
558 Quickcheck_Common.datatype_interpretation full_exhaustive_interpretation |
558 Quickcheck_Common.datatype_interpretation full_exhaustive_plugin |
559 (@{sort full_exhaustive}, instantiate_full_exhaustive_datatype) |
559 (@{sort full_exhaustive}, instantiate_full_exhaustive_datatype) |
560 #> Context.theory_map (Quickcheck.add_tester ("exhaustive", (active, test_goals))) |
560 #> Context.theory_map (Quickcheck.add_tester ("exhaustive", (active, test_goals))) |
561 #> Context.theory_map (Quickcheck.add_batch_generator ("exhaustive", compile_generator_exprs)) |
561 #> Context.theory_map (Quickcheck.add_batch_generator ("exhaustive", compile_generator_exprs)) |
562 #> Context.theory_map (Quickcheck.add_batch_validator ("exhaustive", compile_validator_exprs)); |
562 #> Context.theory_map (Quickcheck.add_batch_validator ("exhaustive", compile_validator_exprs)); |
563 |
563 |