author | bulwahn |
Mon, 22 Nov 2010 11:35:00 +0100 | |
changeset 40654 | a716071ec306 |
parent 40645 | 03ce94672ee6 |
child 40655 | 5fb74f66efa4 |
permissions | -rw-r--r-- |
14592 | 1 |
(* Title: HOL/ex/Quickcheck_Examples.thy |
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
2 |
Author: Stefan Berghofer, Lukas Bulwahn |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
3 |
Copyright 2004 - 2010 TU Muenchen |
14592 | 4 |
*) |
5 |
||
6 |
header {* Examples for the 'quickcheck' command *} |
|
7 |
||
28314 | 8 |
theory Quickcheck_Examples |
9 |
imports Main |
|
10 |
begin |
|
14592 | 11 |
|
12 |
text {* |
|
13 |
The 'quickcheck' command allows to find counterexamples by evaluating |
|
40654 | 14 |
formulae. |
15 |
Currently, there are two different exploration schemes: |
|
16 |
- random testing: this is incomplete, but explores the search space faster. |
|
17 |
- exhaustive testing: this is complete, but increasing the depth leads to |
|
18 |
exponentially many assignments. |
|
19 |
||
20 |
quickcheck can handle quantifiers on finite universes. |
|
21 |
||
14592 | 22 |
*} |
23 |
||
24 |
subsection {* Lists *} |
|
25 |
||
26 |
theorem "map g (map f xs) = map (g o f) xs" |
|
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
27 |
quickcheck[size = 3] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
28 |
quickcheck[generator = random, expect = no_counterexample] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
29 |
quickcheck[generator = small, size = 3, iterations = 1, report = false, expect = no_counterexample] |
14592 | 30 |
oops |
31 |
||
32 |
theorem "map g (map f xs) = map (f o g) xs" |
|
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
33 |
quickcheck[generator = random, expect = counterexample] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
34 |
quickcheck[generator = small, report = false] |
14592 | 35 |
oops |
36 |
||
37 |
theorem "rev (xs @ ys) = rev ys @ rev xs" |
|
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
38 |
quickcheck[expect = no_counterexample] |
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
39 |
quickcheck[generator = small, expect = no_counterexample, report = false] |
14592 | 40 |
oops |
41 |
||
42 |
theorem "rev (xs @ ys) = rev xs @ rev ys" |
|
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
43 |
quickcheck[generator = small, expect = counterexample, report = false] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
44 |
quickcheck[generator = random, expect = counterexample] |
14592 | 45 |
oops |
46 |
||
47 |
theorem "rev (rev xs) = xs" |
|
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
48 |
quickcheck[expect = no_counterexample] |
14592 | 49 |
oops |
50 |
||
51 |
theorem "rev xs = xs" |
|
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
52 |
quickcheck[generator = small] |
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
53 |
quickcheck[expect = counterexample] |
14592 | 54 |
oops |
55 |
||
25891 | 56 |
text {* An example involving functions inside other data structures *} |
57 |
||
28314 | 58 |
primrec app :: "('a \<Rightarrow> 'a) list \<Rightarrow> 'a \<Rightarrow> 'a" where |
25891 | 59 |
"app [] x = x" |
28314 | 60 |
| "app (f # fs) x = app fs (f x)" |
25891 | 61 |
|
62 |
lemma "app (fs @ gs) x = app gs (app fs x)" |
|
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
63 |
quickcheck[generator = random, expect = no_counterexample] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
64 |
quickcheck[generator = small, iterations = 1, size = 4, expect = no_counterexample] |
25891 | 65 |
by (induct fs arbitrary: x) simp_all |
66 |
||
67 |
lemma "app (fs @ gs) x = app fs (app gs x)" |
|
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
68 |
quickcheck[generator = random, expect = counterexample] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
69 |
quickcheck[generator = small, expect = counterexample] |
25891 | 70 |
oops |
71 |
||
28314 | 72 |
primrec occurs :: "'a \<Rightarrow> 'a list \<Rightarrow> nat" where |
14592 | 73 |
"occurs a [] = 0" |
28314 | 74 |
| "occurs a (x#xs) = (if (x=a) then Suc(occurs a xs) else occurs a xs)" |
14592 | 75 |
|
28314 | 76 |
primrec del1 :: "'a \<Rightarrow> 'a list \<Rightarrow> 'a list" where |
14592 | 77 |
"del1 a [] = []" |
28314 | 78 |
| "del1 a (x#xs) = (if (x=a) then xs else (x#del1 a xs))" |
14592 | 79 |
|
25891 | 80 |
text {* A lemma, you'd think to be true from our experience with delAll *} |
14592 | 81 |
lemma "Suc (occurs a (del1 a xs)) = occurs a xs" |
82 |
-- {* Wrong. Precondition needed.*} |
|
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
83 |
quickcheck[generator = small] |
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
84 |
quickcheck[expect = counterexample] |
14592 | 85 |
oops |
86 |
||
87 |
lemma "xs ~= [] \<longrightarrow> Suc (occurs a (del1 a xs)) = occurs a xs" |
|
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
88 |
quickcheck[generator = small] |
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
89 |
quickcheck[expect = counterexample] |
14592 | 90 |
-- {* Also wrong.*} |
91 |
oops |
|
92 |
||
93 |
lemma "0 < occurs a xs \<longrightarrow> Suc (occurs a (del1 a xs)) = occurs a xs" |
|
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
94 |
quickcheck[generator = small] |
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
95 |
quickcheck[expect = no_counterexample] |
28314 | 96 |
by (induct xs) auto |
14592 | 97 |
|
28314 | 98 |
primrec replace :: "'a \<Rightarrow> 'a \<Rightarrow> 'a list \<Rightarrow> 'a list" where |
14592 | 99 |
"replace a b [] = []" |
28314 | 100 |
| "replace a b (x#xs) = (if (x=a) then (b#(replace a b xs)) |
14592 | 101 |
else (x#(replace a b xs)))" |
102 |
||
103 |
lemma "occurs a xs = occurs b (replace a b xs)" |
|
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
104 |
quickcheck[generator = small] |
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
105 |
quickcheck[expect = counterexample] |
14592 | 106 |
-- {* Wrong. Precondition needed.*} |
107 |
oops |
|
108 |
||
109 |
lemma "occurs b xs = 0 \<or> a=b \<longrightarrow> occurs a xs = occurs b (replace a b xs)" |
|
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
110 |
quickcheck[expect = no_counterexample] |
28314 | 111 |
by (induct xs) simp_all |
14592 | 112 |
|
113 |
||
114 |
subsection {* Trees *} |
|
115 |
||
116 |
datatype 'a tree = Twig | Leaf 'a | Branch "'a tree" "'a tree" |
|
117 |
||
28314 | 118 |
primrec leaves :: "'a tree \<Rightarrow> 'a list" where |
14592 | 119 |
"leaves Twig = []" |
28314 | 120 |
| "leaves (Leaf a) = [a]" |
121 |
| "leaves (Branch l r) = (leaves l) @ (leaves r)" |
|
14592 | 122 |
|
28314 | 123 |
primrec plant :: "'a list \<Rightarrow> 'a tree" where |
14592 | 124 |
"plant [] = Twig " |
28314 | 125 |
| "plant (x#xs) = Branch (Leaf x) (plant xs)" |
14592 | 126 |
|
28314 | 127 |
primrec mirror :: "'a tree \<Rightarrow> 'a tree" where |
14592 | 128 |
"mirror (Twig) = Twig " |
28314 | 129 |
| "mirror (Leaf a) = Leaf a " |
130 |
| "mirror (Branch l r) = Branch (mirror r) (mirror l)" |
|
14592 | 131 |
|
132 |
theorem "plant (rev (leaves xt)) = mirror xt" |
|
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
133 |
quickcheck[expect = counterexample] |
14592 | 134 |
--{* Wrong! *} |
135 |
oops |
|
136 |
||
137 |
theorem "plant((leaves xt) @ (leaves yt)) = Branch xt yt" |
|
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
138 |
quickcheck[expect = counterexample] |
14592 | 139 |
--{* Wrong! *} |
140 |
oops |
|
141 |
||
142 |
datatype 'a ntree = Tip "'a" | Node "'a" "'a ntree" "'a ntree" |
|
143 |
||
28314 | 144 |
primrec inOrder :: "'a ntree \<Rightarrow> 'a list" where |
14592 | 145 |
"inOrder (Tip a)= [a]" |
28314 | 146 |
| "inOrder (Node f x y) = (inOrder x)@[f]@(inOrder y)" |
14592 | 147 |
|
28314 | 148 |
primrec root :: "'a ntree \<Rightarrow> 'a" where |
14592 | 149 |
"root (Tip a) = a" |
28314 | 150 |
| "root (Node f x y) = f" |
14592 | 151 |
|
28314 | 152 |
theorem "hd (inOrder xt) = root xt" |
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
153 |
quickcheck[generator = small] |
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
154 |
quickcheck[expect = counterexample] |
14592 | 155 |
--{* Wrong! *} |
156 |
oops |
|
157 |
||
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
158 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
159 |
subsection {* Exhaustive Testing beats Random Testing *} |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
160 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
161 |
text {* Here are some examples from mutants from the List theory |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
162 |
where exhaustive testing beats random testing *} |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
163 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
164 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
165 |
"[] ~= xs ==> hd xs = last (x # xs)" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
166 |
quickcheck[generator = random] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
167 |
quickcheck[generator = small, report = false, expect = counterexample] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
168 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
169 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
170 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
171 |
assumes "!!i. [| i < n; i < length xs |] ==> P (xs ! i)" "n < length xs ==> ~ P (xs ! n)" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
172 |
shows "drop n xs = takeWhile P xs" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
173 |
quickcheck[generator = random, iterations = 10000, report = false, quiet] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
174 |
quickcheck[generator = small, iterations = 1, report = false, expect = counterexample] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
175 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
176 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
177 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
178 |
"i < length (List.transpose (List.transpose xs)) ==> xs ! i = map (%xs. xs ! i) [ys<-xs. i < length ys]" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
179 |
quickcheck[generator = random, iterations = 10000, report = false, quiet] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
180 |
quickcheck[generator = small, iterations = 1, report = false, expect = counterexample] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
181 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
182 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
183 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
184 |
"i < n - m ==> f (lcm m i) = map f [m..<n] ! i" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
185 |
quickcheck[generator = random, iterations = 10000, report = false, quiet] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
186 |
quickcheck[generator = small, expect = counterexample] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
187 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
188 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
189 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
190 |
"i < n - m ==> f (lcm m i) = map f [m..<n] ! i" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
191 |
quickcheck[generator = random, iterations = 1000, report = false, quiet] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
192 |
quickcheck[generator = small, expect = counterexample] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
193 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
194 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
195 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
196 |
"ns ! k < length ns ==> k <= listsum ns" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
197 |
quickcheck[generator = random, iterations = 10000, report = true, quiet] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
198 |
quickcheck[generator = small, expect = counterexample] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
199 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
200 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
201 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
202 |
"[| ys = x # xs1; zs = xs1 @ xs |] ==> ys @ zs = x # xs" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
203 |
quickcheck[generator = random, iterations = 10000, report = true] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
204 |
quickcheck[generator = small, expect = counterexample] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
205 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
206 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
207 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
208 |
"i < length xs ==> take (Suc i) xs = [] @ xs ! i # take i xs" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
209 |
quickcheck[generator = random] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
210 |
quickcheck[generator = small, expect = counterexample] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
211 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
212 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
213 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
214 |
"i < length xs ==> take (Suc i) xs = (xs ! i # xs) @ take i []" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
215 |
quickcheck[generator = random] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
216 |
quickcheck[generator = small, expect = counterexample] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
217 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
218 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
219 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
220 |
"[| sorted (rev (map length xs)); i < length xs |] ==> xs ! i = map (%ys. ys ! i) [ys<-remdups xs. i < length ys]" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
221 |
quickcheck[generator = random] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
222 |
quickcheck[generator = small] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
223 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
224 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
225 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
226 |
"[| sorted (rev (map length xs)); i < length xs |] ==> xs ! i = map (%ys. ys ! i) [ys<-List.transpose xs. {..<i} (length ys)]" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
227 |
quickcheck[generator = random] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
228 |
quickcheck[generator = small, expect = counterexample] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
229 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
230 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
231 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
232 |
"(ys = zs) = (xs @ ys = splice xs zs)" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
233 |
quickcheck[generator = random] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
234 |
quickcheck[generator = small, expect = counterexample] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
235 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
236 |
|
40654 | 237 |
section {* Examples with quantifiers *} |
238 |
||
239 |
text {* |
|
240 |
These examples show that we can handle quantifiers. |
|
241 |
*} |
|
242 |
||
243 |
lemma "(\<exists>x. P x) \<longrightarrow> (\<forall>x. P x)" |
|
244 |
quickcheck[expect = counterexample] |
|
245 |
oops |
|
246 |
||
247 |
lemma "(\<forall>x. \<exists>y. P x y) \<longrightarrow> (\<exists>y. \<forall>x. P x y)" |
|
248 |
quickcheck[expect = counterexample] |
|
249 |
oops |
|
250 |
||
251 |
lemma "(\<exists>x. P x) \<longrightarrow> (EX! x. P x)" |
|
252 |
quickcheck[expect = counterexample] |
|
253 |
oops |
|
254 |
||
14592 | 255 |
end |