author | huffman |
Sat, 21 Apr 2012 10:59:52 +0200 | |
changeset 47647 | ec29cc09599d |
parent 47558 | 55b42f9af99d |
child 47687 | bfbd2d0bb348 |
permissions | -rw-r--r-- |
47512 | 1 |
(* Title: HOL/TPTP/TPTP_Test.thy |
47518 | 2 |
Author: Nik Sultana, Cambridge University Computer Laboratory |
47512 | 3 |
|
47558
55b42f9af99d
phase out "$TPTP_PROBLEMS_PATH"; prefer "$TPTP" for consistency with CASC setup
blanchet
parents:
47547
diff
changeset
|
4 |
Some test support for the TPTP interface. Some of the tests rely on the Isabelle |
55b42f9af99d
phase out "$TPTP_PROBLEMS_PATH"; prefer "$TPTP" for consistency with CASC setup
blanchet
parents:
47547
diff
changeset
|
5 |
environment variable $TPTP, which should point to the TPTP-vX.Y.Z directory. |
47512 | 6 |
*) |
7 |
||
8 |
theory TPTP_Test |
|
9 |
imports TPTP_Parser |
|
10 |
begin |
|
11 |
||
12 |
ML {* |
|
47518 | 13 |
val tptp_test_out = Attrib.setup_config_string @{binding "tptp_test_out"} (K "") |
14 |
val tptp_test_all = Attrib.setup_config_bool @{binding "tptp_test_all"} (K false) |
|
15 |
val tptp_test_timeout = |
|
16 |
Attrib.setup_config_int @{binding "tptp_test_timeout"} (K 5) |
|
17 |
fun test_all ctxt = Config.get ctxt tptp_test_all |
|
18 |
fun get_timeout ctxt = Config.get ctxt tptp_test_timeout |
|
47512 | 19 |
fun S x y z = x z (y z) |
20 |
*} |
|
21 |
||
22 |
section "Parser tests" |
|
23 |
||
24 |
ML {* |
|
25 |
fun payload_of (TPTP_Syntax.Annotated_Formula (_, _, _, _, fmla, _)) = fmla |
|
26 |
val payloads_of = map payload_of |
|
27 |
*} |
|
28 |
||
29 |
||
30 |
section "Source problems" |
|
31 |
ML {* |
|
32 |
(*problem source*) |
|
33 |
val tptp_probs_dir = |
|
47558
55b42f9af99d
phase out "$TPTP_PROBLEMS_PATH"; prefer "$TPTP" for consistency with CASC setup
blanchet
parents:
47547
diff
changeset
|
34 |
Path.explode "$TPTP/Problems" |
47512 | 35 |
|> Path.expand; |
36 |
||
37 |
(*list of files to under test*) |
|
38 |
val files = TPTP_Syntax.get_file_list tptp_probs_dir; |
|
39 |
||
40 |
(* (*test problem-name parsing and mangling*) |
|
41 |
val problem_names = |
|
42 |
map (Path.base #> |
|
43 |
Path.implode #> |
|
44 |
TPTP_Problem_Name.parse_problem_name #> |
|
45 |
TPTP_Problem_Name.mangle_problem_name) |
|
46 |
files*) |
|
47 |
*} |
|
48 |
||
49 |
||
50 |
section "Supporting test functions" |
|
51 |
ML {* |
|
52 |
fun report ctxt str = |
|
53 |
let |
|
47518 | 54 |
val tptp_test_out = Config.get ctxt tptp_test_out |
47512 | 55 |
in |
47518 | 56 |
if tptp_test_out = "" then warning str |
47512 | 57 |
else |
58 |
let |
|
47518 | 59 |
val out_stream = TextIO.openAppend tptp_test_out |
47512 | 60 |
in (TextIO.output (out_stream, str ^ "\n"); |
61 |
TextIO.flushOut out_stream; |
|
62 |
TextIO.closeOut out_stream) |
|
63 |
end |
|
64 |
end |
|
65 |
||
66 |
fun test_fn ctxt f msg default_val file_name = |
|
67 |
let |
|
68 |
val _ = TPTP_Syntax.debug tracing (msg ^ " " ^ Path.print file_name) |
|
69 |
in |
|
70 |
(f file_name; ()) |
|
71 |
(*otherwise report exceptions as warnings*) |
|
72 |
handle exn => |
|
73 |
if Exn.is_interrupt exn then |
|
74 |
reraise exn |
|
75 |
else |
|
76 |
(report ctxt (msg ^ " test: file " ^ Path.print file_name ^ |
|
77 |
" raised exception: " ^ ML_Compiler.exn_message exn); |
|
78 |
default_val) |
|
79 |
end |
|
80 |
||
81 |
fun timed_test ctxt f = |
|
82 |
let |
|
83 |
fun f' x = (f x; ()) |
|
84 |
val time = |
|
85 |
Timing.timing (List.app f') files |
|
86 |
|> fst |
|
87 |
val duration = |
|
88 |
#elapsed time |
|
89 |
|> Time.toSeconds |
|
90 |
|> Real.fromLargeInt |
|
91 |
val average = |
|
92 |
(StringCvt.FIX (SOME 3), |
|
93 |
(duration / Real.fromInt (length files))) |
|
94 |
|-> Real.fmt |
|
95 |
in |
|
96 |
report ctxt ("Test timing: " ^ Timing.message time ^ "\n(about " ^ average ^ |
|
97 |
"s per problem)") |
|
98 |
end |
|
99 |
*} |
|
100 |
||
101 |
||
102 |
ML {* |
|
103 |
fun situate file_name = Path.append tptp_probs_dir (Path.explode file_name); |
|
47547 | 104 |
|
47512 | 105 |
fun parser_test ctxt = (*FIXME argument order*) |
106 |
test_fn ctxt |
|
107 |
(fn file_name => |
|
108 |
Path.implode file_name |
|
109 |
|> (fn file => |
|
110 |
((*report ctxt file; this is if you want the filename in the log*) |
|
111 |
TPTP_Parser.parse_file file))) |
|
112 |
"parser" |
|
113 |
() |
|
47547 | 114 |
|
115 |
fun parse_timed file = |
|
116 |
Timing.timing TPTP_Parser.parse_file (Path.implode file) |
|
47512 | 117 |
*} |
118 |
||
119 |
end |