[Index for tmp_for_tar/dumper]
[Return to Master Index]
test_dumper
(tmp_for_tar/dumper/test_dumper.m)
Function Synopsis
r = mytest( val, ermesg )
Help text
errors = test_dumper
Test whether dumper functions behave, and returns the number of errors.
Sets the global variables test_dumper_errors (number of errors)
and test_dumper_cnt (number of tests)
If a workspace variable 'quiet' is set to -1 the output is verbose.
If it is set to 1, output is minimal (error and test counts).
Otherwise, each error is reported with a short message and the error and ...
test counts are displayed at the end of the script (if it is reached).
Last modified: August 2001
Cross-Reference Information
This function calls
- cmpany tmp_for_tar/dumper/cmpany.m
Listing of function file tmp_for_tar/dumper/test_dumper.m
## errors = test_dumper
##
## Test whether dumper functions behave, and returns the number of errors.
##
## Sets the global variables test_dumper_errors (number of errors)
## and test_dumper_cnt (number of tests)
##
## If a workspace variable 'quiet' is set to -1 the output is verbose.
## If it is set to 1, output is minimal (error and test counts).
## Otherwise, each error is reported with a short message and the error and ...
## test counts are displayed at the end of the script (if it is reached).
##
## Author: Etienne Grossmann <etienne@isr.ist.utl.pt>
## Last modified: August 2001
1 ;
global test_dumper_errors ;
global test_dumper_cnt ;
global test_dumper_quiet ;
test_dumper_quiet = -1 ;
test_dumper_errors = test_dumper_cnt = 0 ;
if exist('quiet') == 1 ,
test_dumper_quiet = quiet ;
end
function r = mytest( val, ermesg )
global test_dumper_cnt ;
global test_dumper_errors ;
global test_dumper_quiet ;
if ! exist('test_dumper_quiet'), test_dumper_quiet = 0 ; end
if val ,
if test_dumper_quiet == -2,
printf('OK %i : %s\n',test_dumper_cnt,ermesg) ;
elseif test_dumper_quiet == -1,
printf('OK %i\n',test_dumper_cnt) ;
end
r = 1 ;
else
if test_dumper_quiet != 1,
printf('NOT OK %-4i : %s\n',test_dumper_cnt,ermesg) ;
end
test_dumper_errors++ ;
r = 0 ;
end
test_dumper_cnt++ ;
endfunction
######################################################################
############ START TESTS #############################################
######################################################################
# mat2str ############################
x = 1:5 ;
sx = mat2str(x) ;
xx = eval([ sx , ';']) ;
if mytest( all(xx==x) , 'mat2str is buggy 1' ) ,
mytest( cmpany(xx,x) , 'cmpany is buggy 1' ) ;
sxx = any2str(x) ;
mytest( strcmp(sxx,sx) , 'any2str is buggy 1' ) ;
end
x = [] ;
sx = mat2str(x) ;
xx = eval([ sx , ';']) ;
if mytest( all(xx==x) , 'mat2str is buggy 2' ) ,
mytest( cmpany(xx,x) , 'cmpany is buggy 2' ) ;
sxx = any2str(x) ;
mytest( strcmp(sxx,sx) , 'any2str is buggy 2' ) ;
end
x = [1:8]' ;
sx = mat2str(x) ;
xx = eval([ sx , ';']) ;
if mytest( all(xx==x) , 'mat2str is buggy 3' ) ,
mytest( cmpany(xx,x) , 'cmpany is buggy 3' ) ;
sxx = any2str(x) ;
mytest( strcmp(sxx,sx) , 'any2str is buggy 3' ) ;
end
x = [1,3,5,7]'*[1,11,13,17,19,23] ;
sx = mat2str(x) ;
xx = eval([ sx , ';']) ;
if mytest( all(xx==x) , 'mat2str is buggy 4' ) ,
mytest( cmpany(xx,x) , 'cmpany is buggy 4' ) ;
sxx = any2str(x) ;
mytest( strcmp(sxx,sx) , 'any2str is buggy 4' ) ;
end
x = exp( [1,3,5,7]'*[1,11,13,17,19,23] ) ;
sx = mat2str(x) ;
xx = eval([ sx , ';']) ;
mytest( all(abs((xx-x)./x)<1e-15) , 'mat2str is buggy 5' ) ;
sxx = any2str(x) ;
mytest( strcmp(sxx,sx) , 'any2str is buggy 5' ) ;
x = ones(3,0) ;
sx = mat2str(x) ;
xx = eval([ sx , ';']) ;
mytest( all(size(xx)==[3,0]) , 'mat2str is buggy 6' ) ;
sxx = any2str(x) ;
mytest( strcmp(sxx,sx) , 'any2str is buggy 6' ) ;
# struct2str :
# Can't do tests unless 'cmpstruct'
# exists.
if exist('cmpstruct') == 2 ,
x = struct('foo',1,'bar',1:5,'hello',[1:3]') ;
sx = struct2str(x) ;
xx = eval([ sx , ';']) ;
if mytest(cmpstruct( xx,x ) , 'struct2str is buggy 1' ) ,
mytest( cmpany( xx,x ) , 'cmpany is buggy 5' ) ;
sxx = any2str(x) ;
mytest( strcmp(sxx,sx) , 'any2str is buggy 6' ) ;
end
x = struct('foo',1,'bar',ones(5,7),'hello',[1:3]') ;
sx = struct2str(x) ;
xx = eval([ sx , ';']) ;
if mytest( cmpstruct( xx,x ) , 'struct2str is buggy 2' ) ,
mytest( cmpany( xx,x ) , 'cmpany is buggy 6' ) ;
sxx = any2str(x) ;
mytest( strcmp(sxx,sx) , 'any2str is buggy 7' ) ;
end
end
# list2str :
# Check for 'list' and 'nth' functions
if exist('list') == 5 && exist('nth') == 5 ,
x = list('Hello',[1,3,5,7]'*[1,11,13,17,19,23]) ;
sx = list2str(x) ;
xx = eval([ sx , ';']) ;
mytest( cmpany(x,xx), 'cmpany is buggy 7' ) ;
sxx = any2str(x) ;
mytest( strcmp(sxx,sx) , 'any2str is buggy 8' ) ;
if mytest( length(x) == length(xx) , 'list2str is buggy : 1') ,
for i = 1:length(x),
ok = ! any(size(nth(x,i))!=size(nth(xx,i))) && ...
! any(any(nth(x,i) != nth(xx,i)));
if mytest( ok , sprintf( 'list2str is buggy 2 %d',i)),
mytest( cmpany(nth(x,i),nth(xx,i)),...
sprintf( 'cmpany is buggy 8 %d',i)) ;
end
end
end
end
# Strings
x = ['Hello World\nNewline\nTons \'o escapes\a\b\f\n\r\t\v"\n',...
'\a \b \f \n \r \t \v " \n' ] ;
sx = any2str(x) ;
xx = eval([ sx , ';']) ;
if mytest( strcmp( xx,x ) , 'any2str is buggy (strings) 1' ) ,
mytest( cmpany( xx,x ) , 'cmpany is buggy 9' ) ;
end
# any2m
x1 = xx1 = 1:5 ;
x2 = xx2 = [] ;
x3 = xx3 = [1:8]' ;
x4 = xx4 = [1,3,5,7]'*[1,11,13,17,19,23] ;
x5 = xx5 = exp( [1,3,5,7]'*[1,11,13,17,19,23] ) ;
if exist('cmpstruct') == 2 ,
x6 = xx6 = struct('foo',1,'bar',1:5,'hello',[1:3]') ;
x7 = xx7 = struct('foo',1,'bar',ones(5,7),'hello',[1:3]') ;
else
x6 = xx6 = 1 ;
x7 = xx7 = 1 ;
end
xx9 = longname = 'Hello World' ;
xx10 = withnewline = 'A\nB\n' ;
# list2str :
# Check for 'list' and 'nth' functions
if exist('list') == 5 && exist('nth') == 5 ,
x8 = xx8 = list('Hello',[1,3,5,7]'*[1,11,13,17,19,23]) ;
else
x8 = xx8 = 1 ;
end
filen = 'dumper_dummy_file.m' ;
if exist(filen) == 2 ,
[status, msg] = unlink(filen) ;
if status ,
printf("Can't delete %s : %s.",filen,msg) ;
keyboard
end
end
any2m(filen,x1,x2,x3,x4,x5,x6,x7,x8,longname,withnewline) ;
clear x1 x2 x3 x4 x5 x6 x7 x8 longname withnewline ;
eval(strrep(filen,'.m','')) ;
mytest( cmpany(xx1,x1) , 'any2m is buggy 1' ) ;
mytest( cmpany(xx2,x2) , 'any2m is buggy 2' ) ;
mytest( cmpany(xx3,x3) , 'any2m is buggy 3' ) ;
mytest( cmpany(xx4,x4) , 'any2m is buggy 4' ) ;
mytest( all(abs((xx5-x5)./xx5)<1e-15) , 'any2m is buggy 5' ) ;
mytest( cmpany(xx6,x6) , 'any2m is buggy 6' ) ;
mytest( cmpany(xx7,x7) , 'any2m is buggy 7' ) ;
mytest( cmpany(xx8,x8) , 'any2m is buggy 8' ) ;
mytest( cmpany(xx9,longname) , 'any2m is buggy 9' ) ;
mytest( cmpany(xx10,withnewline) , 'any2m is buggy 10' ) ;
######################################################################
############ END TESTS ###############################################
######################################################################
printf('Number of errors : %d out of %d tests\n',...
test_dumper_errors,test_dumper_cnt) ;
clear test_dumper_quiet ;
[status, msg] = unlink(filen) ;
if status ,
printf("Can't delete %s at end of test suite:\n%s\n",filen,msg) ;
keyboard
end
Produced by oct2html on Tue Aug 7 17:33:07 2001
Cross-Directory links are: ON