Automatic tester

Author(s): David Trallero Mena.

This module have been created to automate 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

Documentation on exports

PREDICATE

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)

  • Description: run_tester is a predicate for automatizate testers. It get 2 file names as entry (LogFile and ResultFile) for saving the trace and the short result scheme respectevely. Being and End are called at the beginning and at the end of the test. Test is called which each element of TestList and after, Check is called with the corresponding element in CheckList for checking the results of Test predicate. GoodExample is ground(int) at the exit and tells the number of examples that passed the test correctly. Slider can take the values slider(no) or slider(Title) and slider will be shown everytime a new test is called
  • The following properties should hold at call time:
    (basic_props:string/1)LogFile is a string (a list of character codes).
    (basic_props:string/1)ResultFile is a string (a list of character codes).
    (basic_props:callable/1)Begin is a term which represents a goal, i.e., an atom or a structure.
    (basic_props:callable/1)Test is a term which represents a goal, i.e., an atom or a structure.
    (basic_props:list/1)TestList is a list.
    (basic_props:callable/1)Check is a term which represents a goal, i.e., an atom or a structure.
    (basic_props:list/1)CheckList is a list.
    (basic_props:callable/1)End is a term which represents a goal, i.e., an atom or a structure.
    (term_typing:var/1)GoodExamples is a free variable.
    (basic_props:term/1)Slider is any term.

Other information

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 , '%' ] ).