<HTML> <HEAD> <!-- Created by texi2html 1.56k + clip patches and <A href="http://www.clip.dia.fi.upm.es/Software">lpdoc</A> from ciao.texi on 28 January 2007 --> <LINK rel="stylesheet" href="ciao.css" type="text/css"> <TITLE>The Ciao Prolog System - Automatic tester</TITLE> </HEAD> <BODY> Go to the <A HREF="ciao_1.html">first</A>, <A HREF="ciao_228.html">previous</A>, <A HREF="ciao_230.html">next</A>, <A HREF="ciao_241.html">last</A> section, <A HREF="ciao_toc.html">table of contents</A>. <P><HR><P> <H1><A NAME="SEC889" HREF="ciao_toc.html#TOC889">Automatic tester</A></H1> <P> <A NAME="IDX9806"></A> <P> <STRONG>Author(s):</STRONG> David Trallero Mena. <P> <STRONG>Version:</STRONG> 1.10#7 (2006/4/26, 19:22:13 CEST) <P> <STRONG>Version of last change:</STRONG> 1.0 (2003/10/16, 11:52:43 CEST) <P> 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 <A NAME="IDX9807"></A> <CODE>run_tester/10</CODE> 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. <UL> <LI><A HREF="ciao_229.html#SEC890">Usage and interface (tester)</A> <LI><A HREF="ciao_229.html#SEC891">Documentation on exports (tester)</A> <LI><A HREF="ciao_229.html#SEC892">Other information (tester)</A> </UL> <H2><A NAME="SEC890" HREF="ciao_toc.html#TOC890">Usage and interface (<CODE>tester</CODE>)</A></H2> <div class="cartouche"> <UL> <LI><STRONG>Library usage:</STRONG> <CODE>:- use_module(library(tester)).</CODE> <LI><STRONG>Exports:</STRONG> <UL> <LI><EM>Predicates:</EM> <A NAME="IDX9808"></A> <CODE>run_tester/10</CODE>. </UL> <LI><STRONG>Other modules used:</STRONG> <UL> <LI><EM>System library modules:</EM> <A NAME="IDX9809"></A> <CODE>lists</CODE>, <A NAME="IDX9810"></A> <CODE>write</CODE>, <A NAME="IDX9811"></A> <CODE>io_alias_redirection</CODE>. </UL> </UL> </div class="cartouche"> <H2><A NAME="SEC891" HREF="ciao_toc.html#TOC891">Documentation on exports (<CODE>tester</CODE>)</A></H2> <P> <A NAME="IDX9812"></A> <A NAME="IDX9813"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>run_tester/10:</B> <DD><A NAME="IDX9814"></A> <P> <EM>Meta-predicate</EM> with arguments: <CODE>run_tester(?,?,pred(0),pred(1),?,pred(1),?,pred(0),?,?)</CODE>. <P> <STRONG>Usage:</STRONG> <CODE>run_tester(LogFile, ResultFile, Begin, Test, TestList, Check, CheckList, End, GoodExamples, Slider)</CODE> <UL> <LI><EM>Description:</EM> run_tester is a predicate for automatizate testers. It get 2 file names as entry (<CODE>LogFile</CODE> and <CODE>ResultFile</CODE>) for saving the trace and the short result scheme respectevely. <CODE>Being</CODE> and <CODE>End</CODE> are called at the beginning and at the end of the test. <CODE>Test</CODE> is called which each element of <CODE>TestList</CODE> and after, <CODE>Check</CODE> is called with the corresponding element in <CODE>CheckList</CODE> for checking the results of <CODE>Test</CODE> predicate. <CODE>GoodExample</CODE> is ground(int) at the exit and tells the number of examples that passed the test correctly. <CODE>Slider</CODE> can take the values slider(no) or slider(Title) and slider will be shown everytime a new test is called <LI><EM>The following properties should hold at call time:</EM> <CODE>LogFile</CODE> is a string (a list of character codes). (<CODE>basic_props:string/1</CODE>) <CODE>ResultFile</CODE> is a string (a list of character codes). (<CODE>basic_props:string/1</CODE>) <CODE>Begin</CODE> is a term which represents a goal, i.e., an atom or a structure. (<CODE>basic_props:callable/1</CODE>) <CODE>Test</CODE> is a term which represents a goal, i.e., an atom or a structure. (<CODE>basic_props:callable/1</CODE>) <CODE>TestList</CODE> is a list. (<CODE>basic_props:list/1</CODE>) <CODE>Check</CODE> is a term which represents a goal, i.e., an atom or a structure. (<CODE>basic_props:callable/1</CODE>) <CODE>CheckList</CODE> is a list. (<CODE>basic_props:list/1</CODE>) <CODE>End</CODE> is a term which represents a goal, i.e., an atom or a structure. (<CODE>basic_props:callable/1</CODE>) <CODE>GoodExamples</CODE> is a free variable. (<CODE>term_typing:var/1</CODE>) <CODE>Slider</CODE> is any term. (<CODE>basic_props:term/1</CODE>) </UL> </DL> <H2><A NAME="SEC892" HREF="ciao_toc.html#TOC892">Other information (<CODE>tester</CODE>)</A></H2> <P> <P> Two simple examples of the use of the run_tester are provided. <UL> <LI><A HREF="ciao_229.html#SEC893">Understanding run_test predicate</A> <LI><A HREF="ciao_229.html#SEC894">More complex example</A> </UL> <H3><A NAME="SEC893" HREF="ciao_toc.html#TOC893">Understanding run_test predicate</A></H3> <P> <PRE> :- 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 , '%' ] ). </PRE> <H3><A NAME="SEC894" HREF="ciao_toc.html#TOC894">More complex example</A></H3> <P> In this example we just want to test if the output of Ciaopp is readable by CIAO. <P> Tester function succeds if it is able to write the output file. <P> Checker function succeds if it is able to load the written file. <P> <PRE> :- 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 , '%' ] ). </PRE> <P><HR><P> Go to the <A HREF="ciao_1.html">first</A>, <A HREF="ciao_228.html">previous</A>, <A HREF="ciao_230.html">next</A>, <A HREF="ciao_241.html">last</A> section, <A HREF="ciao_toc.html">table of contents</A>. </BODY> </HTML>