equal
deleted
inserted
replaced
3 header {* A simple counterexample generator performing random testing *} |
3 header {* A simple counterexample generator performing random testing *} |
4 |
4 |
5 theory Quickcheck |
5 theory Quickcheck |
6 imports Random Code_Evaluation Enum |
6 imports Random Code_Evaluation Enum |
7 uses |
7 uses |
8 "Tools/Quickcheck/quickcheck_common.ML" |
8 ("Tools/Quickcheck/quickcheck_common.ML") |
9 ("Tools/Quickcheck/random_generators.ML") |
9 ("Tools/Quickcheck/random_generators.ML") |
10 begin |
10 begin |
11 |
11 |
12 notation fcomp (infixl "\<circ>>" 60) |
12 notation fcomp (infixl "\<circ>>" 60) |
13 notation scomp (infixl "\<circ>\<rightarrow>" 60) |
13 notation scomp (infixl "\<circ>\<rightarrow>" 60) |
14 |
14 |
|
15 setup {* Code_Target.extend_target ("Quickcheck", (Code_Runtime.target, K I)) *} |
|
16 |
|
17 subsection {* Catching Match exceptions *} |
|
18 |
|
19 definition catch_match :: "term list option => term list option => term list option" |
|
20 where |
|
21 [code del]: "catch_match t1 t2 = (SOME t. t = t1 \<or> t = t2)" |
|
22 |
|
23 code_const catch_match |
|
24 (Quickcheck "(_) handle Match => _") |
15 |
25 |
16 subsection {* The @{text random} class *} |
26 subsection {* The @{text random} class *} |
17 |
27 |
18 class random = typerep + |
28 class random = typerep + |
19 fixes random :: "code_numeral \<Rightarrow> Random.seed \<Rightarrow> ('a \<times> (unit \<Rightarrow> term)) \<times> Random.seed" |
29 fixes random :: "code_numeral \<Rightarrow> Random.seed \<Rightarrow> ('a \<times> (unit \<Rightarrow> term)) \<times> Random.seed" |
126 assumes "random_aux 0 = rhs 0" |
136 assumes "random_aux 0 = rhs 0" |
127 and "\<And>k. random_aux (Suc_code_numeral k) = rhs (Suc_code_numeral k)" |
137 and "\<And>k. random_aux (Suc_code_numeral k) = rhs (Suc_code_numeral k)" |
128 shows "random_aux k = rhs k" |
138 shows "random_aux k = rhs k" |
129 using assms by (rule code_numeral.induct) |
139 using assms by (rule code_numeral.induct) |
130 |
140 |
|
141 subsection {* Deriving random generators for datatypes *} |
|
142 |
|
143 use "Tools/Quickcheck/quickcheck_common.ML" |
131 use "Tools/Quickcheck/random_generators.ML" |
144 use "Tools/Quickcheck/random_generators.ML" |
132 setup Random_Generators.setup |
145 setup Random_Generators.setup |
133 |
146 |
134 |
147 |
135 subsection {* Code setup *} |
148 subsection {* Code setup *} |