author | wenzelm |
Sat, 22 Aug 2020 14:48:00 +0200 | |
changeset 72190 | 8009c4b5db5e |
parent 69593 | 3dda49e08b9d |
child 73387 | 3b5196dac4c8 |
permissions | -rw-r--r-- |
55203 | 1 |
(* Title: HOL/Tools/Nitpick/nitpick_tests.ML |
33192 | 2 |
Author: Jasmin Blanchette, TU Muenchen |
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34287
diff
changeset
|
3 |
Copyright 2008, 2009, 2010 |
33192 | 4 |
|
5 |
Unit tests for Nitpick. |
|
6 |
*) |
|
7 |
||
8 |
signature NITPICK_TESTS = |
|
9 |
sig |
|
10 |
val run_all_tests : unit -> unit |
|
35866
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
35388
diff
changeset
|
11 |
end; |
33192 | 12 |
|
55203 | 13 |
structure Nitpick_Tests : NITPICK_TESTS = |
33192 | 14 |
struct |
15 |
||
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33192
diff
changeset
|
16 |
open Nitpick_Util |
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33192
diff
changeset
|
17 |
open Nitpick_Peephole |
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33192
diff
changeset
|
18 |
open Nitpick_Rep |
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33192
diff
changeset
|
19 |
open Nitpick_Nut |
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33192
diff
changeset
|
20 |
open Nitpick_Kodkod |
33192 | 21 |
|
35388
42d39948cace
use SAT4J for "Tests_Nits.thy" for safety (this should solve the Isatest failures) + minor changes
blanchet
parents:
35333
diff
changeset
|
22 |
val settings = [("solver", "\"DefaultSAT4J\"")] |
33192 | 23 |
|
24 |
fun cast_to_rep R u = Op1 (Cast, type_of u, R, u) |
|
25 |
||
69593 | 26 |
val dummy_T = \<^typ>\<open>'a\<close> |
33192 | 27 |
|
28 |
val atom1_v1 = FreeName ("atom1_v1", dummy_T, Atom (1, 0)) |
|
29 |
val atom2_v1 = FreeName ("atom2_v1", dummy_T, Atom (2, 0)) |
|
30 |
val atom6_v1 = FreeName ("atom6_v1", dummy_T, Atom (6, 0)) |
|
31 |
val atom16_v1 = FreeName ("atom16_v1", dummy_T, Atom (16, 0)) |
|
32 |
val atom24_v1 = FreeName ("atom24_v1", dummy_T, Atom (24, 0)) |
|
33 |
val atom36_v1 = FreeName ("atom36_v1", dummy_T, Atom (36, 0)) |
|
34 |
val struct_atom1_atom1_v1 = |
|
35 |
FreeName ("struct_atom1_atom1_v1", dummy_T, Struct [Atom (1, 0), Atom (1, 0)]) |
|
36 |
||
37 |
(* |
|
38190
b02e204b613a
get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents:
38186
diff
changeset
|
38 |
Formula Atom Struct Vect Func |
b02e204b613a
get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents:
38186
diff
changeset
|
39 |
Formula X X X N/A N/A |
b02e204b613a
get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents:
38186
diff
changeset
|
40 |
Atom X X X X X |
b02e204b613a
get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents:
38186
diff
changeset
|
41 |
Struct N/A X X N/A N/A |
b02e204b613a
get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents:
38186
diff
changeset
|
42 |
Vect N/A X N/A X X |
b02e204b613a
get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents:
38186
diff
changeset
|
43 |
Func N/A X N/A X X |
33192 | 44 |
*) |
45 |
||
46 |
val tests = |
|
47 |
[("rep_conversion_formula_formula", |
|
48 |
Op2 (Eq, bool_T, Formula Neut, |
|
49 |
cast_to_rep (Formula Neut) |
|
50 |
(cast_to_rep (Formula Neut) atom2_v1), atom2_v1)), |
|
51 |
("rep_conversion_atom_atom", |
|
52 |
Op2 (Eq, bool_T, Formula Neut, |
|
53 |
cast_to_rep (Atom (16, 0)) (cast_to_rep (Atom (16, 0)) atom16_v1), |
|
54 |
atom16_v1)), |
|
55 |
("rep_conversion_struct_struct_1", |
|
56 |
Op2 (Eq, bool_T, Formula Neut, |
|
57 |
cast_to_rep (Struct [Atom (4, 0), Atom (6, 0)]) |
|
58 |
(cast_to_rep (Struct [Atom (4, 0), Atom (6, 0)]) atom24_v1), |
|
59 |
atom24_v1)), |
|
60 |
("rep_conversion_struct_struct_2", |
|
61 |
Op2 (Eq, bool_T, Formula Neut, |
|
62 |
cast_to_rep (Struct [Atom (4, 0), Struct [Atom (2, 0), Atom (3, 0)]]) |
|
63 |
(cast_to_rep (Struct [Atom (4, 0), Atom (6, 0)]) atom24_v1), |
|
64 |
atom24_v1)), |
|
65 |
("rep_conversion_struct_struct_3", |
|
66 |
Op2 (Eq, bool_T, Formula Neut, |
|
67 |
cast_to_rep (Struct [Atom (4, 0), Atom (6, 0)]) |
|
68 |
(cast_to_rep (Struct [Atom (4, 0), |
|
69 |
Struct [Atom (2, 0), Atom (3, 0)]]) |
|
70 |
atom24_v1), |
|
71 |
atom24_v1)), |
|
72 |
("rep_conversion_vect_vect_1", |
|
73 |
Op2 (Eq, bool_T, Formula Neut, |
|
74 |
cast_to_rep (Atom (16, 0)) |
|
75 |
(cast_to_rep (Vect (2, Atom (4, 0))) |
|
76 |
(cast_to_rep (Vect (2, Struct [Atom (2, 0), Atom (2, 0)])) |
|
77 |
atom16_v1)), |
|
78 |
atom16_v1)), |
|
79 |
("rep_conversion_vect_vect_2", |
|
80 |
Op2 (Eq, bool_T, Formula Neut, |
|
81 |
cast_to_rep (Atom (16, 0)) |
|
82 |
(cast_to_rep (Vect (2, Struct [Atom (2, 0), Atom (2, 0)])) |
|
83 |
(cast_to_rep (Vect (2, Atom (4, 0))) atom16_v1)), |
|
84 |
atom16_v1)), |
|
85 |
("rep_conversion_vect_vect_3", |
|
86 |
Op2 (Eq, bool_T, Formula Neut, |
|
87 |
cast_to_rep (Atom (16, 0)) |
|
88 |
(cast_to_rep (Vect (2, Atom (4, 0))) |
|
89 |
(cast_to_rep (Vect (2, Vect (2, Atom (2, 0)))) atom16_v1)), |
|
90 |
atom16_v1)), |
|
91 |
("rep_conversion_vect_vect_4", |
|
92 |
Op2 (Eq, bool_T, Formula Neut, |
|
93 |
cast_to_rep (Atom (16, 0)) |
|
94 |
(cast_to_rep (Vect (2, Vect (2, Atom (2, 0)))) |
|
95 |
(cast_to_rep (Vect (2, Atom (4, 0))) atom16_v1)), |
|
96 |
atom16_v1)), |
|
97 |
("rep_conversion_func_func_1", |
|
98 |
Op2 (Eq, bool_T, Formula Neut, |
|
99 |
cast_to_rep (Atom (36, 0)) |
|
100 |
(cast_to_rep (Func (Atom (2, 0), |
|
101 |
Struct [Atom (2, 0), Atom (3, 0)])) |
|
102 |
(cast_to_rep (Func (Atom (2, 0), Atom (6, 0))) atom36_v1)), |
|
103 |
atom36_v1)), |
|
104 |
("rep_conversion_func_func_2", |
|
105 |
Op2 (Eq, bool_T, Formula Neut, |
|
106 |
cast_to_rep (Atom (36, 0)) |
|
107 |
(cast_to_rep (Func (Atom (2, 0), Atom (6, 0))) |
|
108 |
(cast_to_rep (Func (Atom (2, 0), |
|
109 |
Struct [Atom (2, 0), Atom (3, 0)])) |
|
110 |
atom36_v1)), |
|
111 |
atom36_v1)), |
|
112 |
("rep_conversion_atom_formula_atom", |
|
113 |
Op2 (Eq, bool_T, Formula Neut, |
|
114 |
cast_to_rep (Atom (2, 0)) (cast_to_rep (Formula Neut) atom2_v1), |
|
115 |
atom2_v1)), |
|
116 |
("rep_conversion_atom_struct_atom1", |
|
117 |
Op2 (Eq, bool_T, Formula Neut, |
|
118 |
cast_to_rep (Atom (6, 0)) |
|
119 |
(cast_to_rep (Struct [Atom (3, 0), Atom (2, 0)]) atom6_v1), |
|
120 |
atom6_v1)), |
|
121 |
("rep_conversion_atom_struct_atom_2", |
|
122 |
Op2 (Eq, bool_T, Formula Neut, |
|
123 |
cast_to_rep (Atom (24, 0)) |
|
124 |
(cast_to_rep (Struct [Struct [Atom (3, 0), Atom (4, 0)], |
|
125 |
Atom (2, 0)]) atom24_v1), |
|
126 |
atom24_v1)), |
|
127 |
("rep_conversion_atom_vect_func_atom_1", |
|
128 |
Op2 (Eq, bool_T, Formula Neut, |
|
129 |
cast_to_rep (Atom (16, 0)) |
|
130 |
(cast_to_rep (Vect (4, Atom (2, 0))) |
|
131 |
(cast_to_rep (Func (Atom (4, 0), Atom (2, 0))) atom16_v1)), |
|
132 |
atom16_v1)), |
|
133 |
("rep_conversion_atom_vect_func_atom_2", |
|
134 |
Op2 (Eq, bool_T, Formula Neut, |
|
135 |
cast_to_rep (Atom (16, 0)) |
|
136 |
(cast_to_rep (Vect (4, Atom (2, 0))) |
|
137 |
(cast_to_rep (Func (Atom (4, 0), Atom (2, 0))) atom16_v1)), |
|
138 |
atom16_v1)), |
|
139 |
("rep_conversion_atom_vect_func_atom_3", |
|
140 |
Op2 (Eq, bool_T, Formula Neut, |
|
141 |
cast_to_rep (Atom (16, 0)) |
|
142 |
(cast_to_rep (Vect (4, Atom (2, 0))) |
|
143 |
(cast_to_rep (Func (Atom (4, 0), Formula Neut)) atom16_v1)), |
|
144 |
atom16_v1)), |
|
145 |
("rep_conversion_atom_func_vect_atom_1", |
|
146 |
Op2 (Eq, bool_T, Formula Neut, |
|
147 |
cast_to_rep (Atom (16, 0)) |
|
148 |
(cast_to_rep (Func (Atom (4, 0), Atom (2, 0))) |
|
149 |
(cast_to_rep (Vect (4, Atom (2, 0))) atom16_v1)), |
|
150 |
atom16_v1)), |
|
151 |
("rep_conversion_atom_func_vect_atom_2", |
|
152 |
Op2 (Eq, bool_T, Formula Neut, |
|
153 |
cast_to_rep (Atom (16, 0)) |
|
154 |
(cast_to_rep (Func (Atom (4, 0), Atom (2, 0))) |
|
155 |
(cast_to_rep (Vect (4, Atom (2, 0))) atom16_v1)), |
|
156 |
atom16_v1)), |
|
157 |
("rep_conversion_atom_func_vect_atom_3", |
|
158 |
Op2 (Eq, bool_T, Formula Neut, |
|
159 |
cast_to_rep (Atom (16, 0)) |
|
160 |
(cast_to_rep (Func (Atom (4, 0), Formula Neut)) |
|
161 |
(cast_to_rep (Vect (4, Atom (2, 0))) atom16_v1)), |
|
162 |
atom16_v1)), |
|
163 |
("rep_conversion_atom_func_vect_atom_5", |
|
164 |
Op2 (Eq, bool_T, Formula Neut, |
|
165 |
cast_to_rep (Atom (16, 0)) |
|
166 |
(cast_to_rep (Func (Atom (1, 0), Atom (16, 0))) |
|
167 |
(cast_to_rep (Vect (1, Atom (16, 0))) atom16_v1)), |
|
168 |
atom16_v1)), |
|
169 |
("rep_conversion_atom_vect_atom", |
|
170 |
Op2 (Eq, bool_T, Formula Neut, |
|
171 |
cast_to_rep (Atom (36, 0)) |
|
172 |
(cast_to_rep (Vect (2, Struct [Atom (2, 0), Atom (3, 0)])) |
|
173 |
atom36_v1), |
|
174 |
atom36_v1)), |
|
175 |
("rep_conversion_atom_func_atom", |
|
176 |
Op2 (Eq, bool_T, Formula Neut, |
|
177 |
cast_to_rep (Atom (36, 0)) |
|
178 |
(cast_to_rep (Func (Atom (2, 0), |
|
179 |
Struct [Atom (2, 0), Atom (3, 0)])) atom36_v1), |
|
180 |
atom36_v1)), |
|
181 |
("rep_conversion_struct_atom1_1", |
|
182 |
Op2 (Eq, bool_T, Formula Neut, |
|
183 |
cast_to_rep (Struct [Atom (1, 0), Atom (1, 0)]) atom1_v1, |
|
38190
b02e204b613a
get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents:
38186
diff
changeset
|
184 |
struct_atom1_atom1_v1))] |
33192 | 185 |
|
35284
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35280
diff
changeset
|
186 |
fun problem_for_nut ctxt (name, u) = |
33192 | 187 |
let |
188 |
val debug = false |
|
189 |
val peephole_optim = true |
|
190 |
val nat_card = 4 |
|
191 |
val int_card = 9 |
|
192 |
val j0 = 0 |
|
193 |
val constrs = kodkod_constrs peephole_optim nat_card int_card j0 |
|
194 |
val (free_rels, pool, table) = |
|
195 |
rename_free_vars (fst (add_free_and_const_names u ([], []))) initial_pool |
|
196 |
NameTable.empty |
|
197 |
val u = Op1 (Not, type_of u, rep_of u, u) |
|
198 |
|> rename_vars_in_nut pool table |
|
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35185
diff
changeset
|
199 |
val formula = kodkod_formula_from_nut Typtab.empty constrs u |
33192 | 200 |
val bounds = map (bound_for_plain_rel ctxt debug) free_rels |
201 |
val univ_card = univ_card nat_card int_card j0 bounds formula |
|
202 |
val declarative_axioms = map (declarative_axiom_for_plain_rel constrs) |
|
203 |
free_rels |
|
204 |
val formula = fold_rev s_and declarative_axioms formula |
|
205 |
in |
|
206 |
{comment = name, settings = settings, univ_card = univ_card, |
|
207 |
tuple_assigns = [], bounds = bounds, int_bounds = [], expr_assigns = [], |
|
208 |
formula = formula} |
|
209 |
end |
|
210 |
||
35284
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35280
diff
changeset
|
211 |
fun run_all_tests () = |
38186
c28018f5a1d6
example tweaking -- also prevents Nitpick_Tests from using more than 1 thread
blanchet
parents:
37396
diff
changeset
|
212 |
let |
69593 | 213 |
val {debug, overlord, timeout, ...} = Nitpick_Commands.default_params \<^theory> [] |
72190
8009c4b5db5e
proper treatment of absolute deadline vs. relative timeout;
wenzelm
parents:
69593
diff
changeset
|
214 |
val deadline = Time.now () + timeout |
38186
c28018f5a1d6
example tweaking -- also prevents Nitpick_Tests from using more than 1 thread
blanchet
parents:
37396
diff
changeset
|
215 |
val max_threads = 1 |
c28018f5a1d6
example tweaking -- also prevents Nitpick_Tests from using more than 1 thread
blanchet
parents:
37396
diff
changeset
|
216 |
val max_solutions = 1 |
c28018f5a1d6
example tweaking -- also prevents Nitpick_Tests from using more than 1 thread
blanchet
parents:
37396
diff
changeset
|
217 |
in |
72190
8009c4b5db5e
proper treatment of absolute deadline vs. relative timeout;
wenzelm
parents:
69593
diff
changeset
|
218 |
case Kodkod.solve_any_problem debug overlord deadline max_threads max_solutions |
69593 | 219 |
(map (problem_for_nut \<^context>) tests) of |
38190
b02e204b613a
get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents:
38186
diff
changeset
|
220 |
Kodkod.Normal ([], _, _) => () |
63693
5b02f7757a4c
removed trailing final stops in Nitpick messages
blanchet
parents:
55539
diff
changeset
|
221 |
| _ => error "Tests failed" |
38190
b02e204b613a
get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents:
38186
diff
changeset
|
222 |
end |
33192 | 223 |
|
224 |
end; |