src/HOL/TPTP/TPTP_Test.thy
author haftmann
Fri, 01 Nov 2013 18:51:14 +0100
changeset 54230 b1d955791529
parent 47687 bfbd2d0bb348
child 55595 2e2e9bc7c4c6
permissions -rw-r--r--
more simplification rules on unary and binary minus
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
     1
(*  Title:      HOL/TPTP/TPTP_Test.thy
47518
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47512
diff changeset
     2
    Author:     Nik Sultana, Cambridge University Computer Laboratory
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
     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
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
     6
*)
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
     7
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
     8
theory TPTP_Test
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
     9
imports TPTP_Parser
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    10
begin
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    11
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    12
ML {*
47518
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47512
diff changeset
    13
  val tptp_test_out = Attrib.setup_config_string @{binding "tptp_test_out"} (K "")
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47512
diff changeset
    14
  val tptp_test_all = Attrib.setup_config_bool @{binding "tptp_test_all"} (K false)
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47512
diff changeset
    15
  val tptp_test_timeout =
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47512
diff changeset
    16
    Attrib.setup_config_int @{binding "tptp_test_timeout"} (K 5)
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47512
diff changeset
    17
  fun test_all ctxt = Config.get ctxt tptp_test_all
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47512
diff changeset
    18
  fun get_timeout ctxt = Config.get ctxt tptp_test_timeout
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    19
  fun S x y z = x z (y z)
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    20
*}
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    21
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    22
section "Parser tests"
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    23
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    24
ML {*
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    25
  fun payload_of (TPTP_Syntax.Annotated_Formula (_, _, _, _, fmla, _)) = fmla
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    26
  val payloads_of = map payload_of
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    27
*}
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    28
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    29
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    30
section "Source problems"
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    31
ML {*
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    32
  (*problem source*)
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    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
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    35
    |> Path.expand;
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    36
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    37
  (*list of files to under test*)
47687
bfbd2d0bb348 moved function for testing problem-name parsing;
sultana
parents: 47558
diff changeset
    38
  fun test_files () = TPTP_Syntax.get_file_list tptp_probs_dir;
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    39
*}
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    40
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    41
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    42
section "Supporting test functions"
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    43
ML {*
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    44
  fun report ctxt str =
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    45
    let
47518
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47512
diff changeset
    46
      val tptp_test_out = Config.get ctxt tptp_test_out
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    47
    in
47518
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47512
diff changeset
    48
      if tptp_test_out = "" then warning str
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    49
      else
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    50
        let
47518
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47512
diff changeset
    51
          val out_stream = TextIO.openAppend tptp_test_out
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    52
        in (TextIO.output (out_stream, str ^ "\n");
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    53
            TextIO.flushOut out_stream;
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    54
            TextIO.closeOut out_stream)
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    55
        end
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    56
    end
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    57
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    58
  fun test_fn ctxt f msg default_val file_name =
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    59
    let
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    60
      val _ = TPTP_Syntax.debug tracing (msg ^ " " ^ Path.print file_name)
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    61
    in
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    62
     (f file_name; ())
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    63
     (*otherwise report exceptions as warnings*)
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    64
     handle exn =>
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    65
       if Exn.is_interrupt exn then
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    66
         reraise exn
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    67
       else
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    68
         (report ctxt (msg ^ " test: file " ^ Path.print file_name ^
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    69
          " raised exception: " ^ ML_Compiler.exn_message exn);
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    70
          default_val)
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    71
    end
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    72
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    73
  fun timed_test ctxt f =
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    74
    let
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    75
      fun f' x = (f x; ())
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    76
      val time =
47687
bfbd2d0bb348 moved function for testing problem-name parsing;
sultana
parents: 47558
diff changeset
    77
        Timing.timing (List.app f') (test_files ())
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    78
        |> fst
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    79
      val duration =
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    80
        #elapsed time
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    81
        |> Time.toSeconds
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    82
        |> Real.fromLargeInt
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    83
      val average =
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    84
        (StringCvt.FIX (SOME 3),
47687
bfbd2d0bb348 moved function for testing problem-name parsing;
sultana
parents: 47558
diff changeset
    85
         (duration / Real.fromInt (length (test_files ()))))
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    86
        |-> Real.fmt
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    87
    in
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    88
      report ctxt ("Test timing: " ^ Timing.message time ^ "\n(about " ^ average ^
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    89
       "s per problem)")
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    90
    end
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    91
*}
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    92
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    93
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    94
ML {*
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    95
  fun situate file_name = Path.append tptp_probs_dir (Path.explode file_name);
47547
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
    96
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    97
  fun parser_test ctxt = (*FIXME argument order*)
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    98
    test_fn ctxt
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    99
     (fn file_name =>
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   100
        Path.implode file_name
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   101
        |> (fn file =>
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   102
             ((*report ctxt file; this is if you want the filename in the log*)
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   103
              TPTP_Parser.parse_file file)))
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   104
     "parser"
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   105
     ()
47547
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   106
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   107
  fun parse_timed file =
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   108
    Timing.timing TPTP_Parser.parse_file (Path.implode file)
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   109
*}
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   110
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   111
end