src/HOL/TPTP/TPTP_Test.thy
author sultana
Wed, 19 Feb 2014 15:57:02 +0000
changeset 55595 2e2e9bc7c4c6
parent 47687 bfbd2d0bb348
child 56303 4cc3f4db3447
permissions -rw-r--r--
made list of test files a parameter to timed_test in TPTP_Test.thy, and updated dependent definitions;
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
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    38
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    39
section "Supporting test functions"
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    40
ML {*
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    41
  fun report ctxt str =
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    42
    let
47518
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47512
diff changeset
    43
      val tptp_test_out = Config.get ctxt tptp_test_out
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    44
    in
47518
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47512
diff changeset
    45
      if tptp_test_out = "" then warning str
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    46
      else
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    47
        let
47518
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47512
diff changeset
    48
          val out_stream = TextIO.openAppend tptp_test_out
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    49
        in (TextIO.output (out_stream, str ^ "\n");
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    50
            TextIO.flushOut out_stream;
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    51
            TextIO.closeOut out_stream)
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    52
        end
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    53
    end
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    54
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    55
  fun test_fn ctxt f msg default_val file_name =
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    56
    let
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    57
      val _ = TPTP_Syntax.debug tracing (msg ^ " " ^ Path.print file_name)
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    58
    in
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    59
     (f file_name; ())
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    60
     (*otherwise report exceptions as warnings*)
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    61
     handle exn =>
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    62
       if Exn.is_interrupt exn then
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    63
         reraise exn
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    64
       else
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    65
         (report ctxt (msg ^ " test: file " ^ Path.print file_name ^
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    66
          " raised exception: " ^ ML_Compiler.exn_message exn);
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    67
          default_val)
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    68
    end
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    69
55595
2e2e9bc7c4c6 made list of test files a parameter to timed_test in TPTP_Test.thy, and updated dependent definitions;
sultana
parents: 47687
diff changeset
    70
  fun timed_test ctxt f test_files =
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    71
    let
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    72
      fun f' x = (f x; ())
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    73
      val time =
55595
2e2e9bc7c4c6 made list of test files a parameter to timed_test in TPTP_Test.thy, and updated dependent definitions;
sultana
parents: 47687
diff changeset
    74
        Timing.timing (List.app f') test_files
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    75
        |> fst
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    76
      val duration =
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    77
        #elapsed time
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    78
        |> Time.toSeconds
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    79
        |> Real.fromLargeInt
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    80
      val average =
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    81
        (StringCvt.FIX (SOME 3),
55595
2e2e9bc7c4c6 made list of test files a parameter to timed_test in TPTP_Test.thy, and updated dependent definitions;
sultana
parents: 47687
diff changeset
    82
         (duration / Real.fromInt (length test_files)))
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    83
        |-> Real.fmt
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    84
    in
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    85
      report ctxt ("Test timing: " ^ Timing.message time ^ "\n(about " ^ average ^
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    86
       "s per problem)")
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    87
    end
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    88
*}
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    89
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    90
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    91
ML {*
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    92
  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
    93
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    94
  fun parser_test ctxt = (*FIXME argument order*)
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    95
    test_fn ctxt
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    96
     (fn file_name =>
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    97
        Path.implode file_name
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    98
        |> (fn file =>
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    99
             ((*report ctxt file; this is if you want the filename in the log*)
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   100
              TPTP_Parser.parse_file file)))
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   101
     "parser"
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   102
     ()
47547
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   103
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   104
  fun parse_timed file =
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   105
    Timing.timing TPTP_Parser.parse_file (Path.implode file)
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   106
*}
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   107
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   108
end