Go to the first, previous, next, last section, table of contents.


Automatic tester

Author(s): David Trallero Mena.

Version: 1.10#7 (2006/4/26, 19:22:13 CEST)

Version of last change: 1.0 (2003/10/16, 11:52:43 CEST)

This module have been created to automatizate the test that a predicate should pass hopefully. With that intention we have to provide a set of test and its correct answers. The predicate run_tester/10 will execute every test and compare it with its answer, generating two traces, one with detailed information, and another with the summary of executions of the tests.

Usage and interface (tester)

Documentation on exports (tester)

PREDICATE: run_tester/10:

Meta-predicate with arguments: run_tester(?,?,pred(0),pred(1),?,pred(1),?,pred(0),?,?).

Usage: run_tester(LogFile, ResultFile, Begin, Test, TestList, Check, CheckList, End, GoodExamples, Slider)

Other information (tester)

Two simple examples of the use of the run_tester are provided.

Understanding run_test predicate

:- module( tester_test2 , _ , _ ).

:- use_module( '../tester' ).
%:- use_module( library(tester) ).
:- use_module( library(lists) ).
:- use_module( library(write) ).

init_func :-
        write( 'Starting the test\n' ).

tester_func( (X,X,_) ) :-
        write( 'The argument is correct ' ),
        write( X ) , nl.

checker_func( (_,X,X) ) :-
        write( 'check is fine\n\n' ).
        

end_func :-
        write( 'Test ended\n' ).

main :-
        L = [ (1,1,1),   % CORRECT
              (2,2,1),   % Test CORRECT , CHECK FALSE
              (1,2,2)    % Test FALSE
            ],
              
         run_tester(
                      'test.log',
                      'result.log',
                      init_func ,
                      tester_func ,
                      L,
                      checker_func,
                      L,
                      end_func,
                      Res,
                      slider( 'Tester2: ' )
                  ),

         length( L , LL ),
         Op is (Res / LL) * 100,
         message( note , [ 'Analysis result: ' , Op , '%' ] ).

More complex example

In this example we just want to test if the output of Ciaopp is readable by CIAO.

Tester function succeds if it is able to write the output file.

Checker function succeds if it is able to load the written file.

:- module( tester_test1 , _ , [] ).

%:- use_module( library(tester) , [run_tester/10] ).
:- use_module( '../tester' , [run_tester/10] ).

:- use_module( library(ciaopp) ).
:- use_module( library(compiler) ).

:- use_module(library(filenames)).

:- use_module( library( write ) ).

:- use_module( library( lists ) ).

init_func.
        

test_files( '/home/dtm/Ciaopp/Benchmarks/ciaopp/modes/' ).

tester_func( FileArg ) :-
        test_files( Path ),
        atom_concat( Path , FileArg , File0 ),

        message( note ,
         [ '+++++++++++++++++++++++++++++++++++++++++++++++\n' ] ),
        (unload( File0 )->true;true),
        module( File0 ),

        atom_concat( TFile , '.pl', File0 ),
        atom_concat( TFile , '_test.pl' , TestFile ),

        output( TestFile ).

get_module( Path , Module ) :-
        no_path_file_name( Path , File ),
        (atom_concat( Module , '.pl' , File )
        -> true ; Module = File ).

checker_func( FileArg ) :-
        get_module( FileArg , Module ),
        (unload( Module )->true;true),

        atom_concat(RawFile, '.pl'     , FileArg ),         
        atom_concat(RawFile, '_test.pl' , OptFile ),

        test_files( Path ),
        atom_concat( Path , OptFile, OptFilePath ),

        message( note , [ 'Cargando ' , OptFilePath ] ),
        use_module( OptFilePath ).

end_func.

main :-
        L = [
                'aiakl.pl',
                'query.pl',
                'mmatrix.pl',
                'ann.pl',
                'bid.pl',
                'rdtok.pl',
                'myread.pl',
                'boyer.pl',
                'read.pl',
                'occur.pl',
                'serialize.pl',
                'browse.pl',
                'peephole.pl',
                'tak.pl',
                'deriv.pl',
                'progeom.pl',
                'warplan.pl',
                'fib.pl',
                'qplan.pl',
                'witt.pl',
                'grammar.pl',
                'zebra.pl',
                'qsortapp.pl',
                'hanoiapp.pl'
              ],

        run_tester(
                      'test.log',
                      'result.log',
                      init_func ,
                      tester_func ,
                      L,
                      checker_func,
                      L,
                      end_func,
                      Res,
                      slider( 'Tester1: ' )
                  ),
         length( L , LL ),
         Op is (Res / LL) * 100,
         message( note , [ 'Analysis result: ' , Op , '%' ] ).


Go to the first, previous, next, last section, table of contents.