function testsequence(flag)
% testsequence( [flag] )
% Demonstrates how to use the sequence-packge and tests if the sequence-package works correctly
% if flag is 1, then the functions in the package are tested.
%
% Written by: tommsch, 2018

%#ok<*NOPRT>
%#ok<*ASGLU>
%#ok<*NASGU>

if(nargin>=1 && flag); selftestsequence; return; end;

vprintf('Either start the function with argument <1> or read the source code of this file.\n'); 
return; 
2; %#ok<UNRCH>

end

function selftestsequence
    vprintf('The sequence-package will be tested. All output on the screen should be followed by an explanation.\n','cpr',[.1 .4 .1]);
    vprintf('If there is some error or un-commented output, the test fails.\n\n','cpr',[.1 .4 .1]);
    
    val=addsequence([1 2 ],[4;5],[1;1],[1;0]);
    if(~isequal(val,[4 1 2;5 0 0])); vprintf('addsequence() is broken.\n\n','cpr','err'); end;    
    
    [a,amin]=characteristic([1 0; 2 0; 1 -1]','amin',[-1; -1]);
    if(~isequal(a,[0 0;0 0;1 1;0 1]) || ~isequal(amin,[-1;-1])); vprintf('characteristic() is broken.\n\n','cpr','err'); end;
    
    mu=constructmu(2,2);
    if(~isequal(mu,[2 1 0;0 1 2])); vprintf('constructmu() is broken.\n\n','cpr','err'); end;
    
    val=diffsequence([1 2 3; 4 5 6],1,'equalsize');
    if(~isequal(val,{[1 2 3 0;3 3 3 0;-4 -5 -6 0]; [1 1 1 -3;4 1 1 -6;0 0 0 0]})); vprintf('diffsequence() is broken.\n\n','cpr','err'); end;    
    
    val=equalizeminidx({[10 ; 10],[1 1]';[1],[0 0]'});
    if(~isequal(val{1},[0 0;0 10;0 10]) || ~isequal(val{2},[1 0;0 0;0 0])); vprintf('equalizeminidx() is broken.\n\n','cpr','err'); end;    
    
    mask=symbol2mask(mask2symbol([1 2 3; 4 5 6]));
    if(~isequal(mask,[1 2 3; 4 5 6])); vprintf('mask2symbol()/symbol2mask() is broken.\n\n','cpr','err'); end;
    
    val=setidx([1 2; 2 3],[1 1]',[0 0]',[2 3]');
    if(~isequal(val,[0 0 0 0;0 1 2 0;0 2 3 0])); vprintf('setidx() is broken.\n\n','cpr','err'); end;    
    
    val=setplus([1 0; 1 1]',[10 10; 20 20; 30 30]');
    if(~isequal(val,[11 11 21 21 31 31;10 11 20 21 30 31])); vprintf('setplus() is broken.\n\n','cpr','err'); end;    
    
    suppval=supp([1 1; 0 1],2,[1;-1]);
    if(~isequal(suppval,[1 1 2;-1 0 0])); vprintf('supp() is broken.\n\n','cpr','err'); end;
    
    %symbol2mask %tested above
    
    %testsequence %this file
    
    c1=sequence([1 2 3 4],[1; 1]);
    c2=sequence([10 20 30 40],[-5; 0]);
    if(~isequal(c1.c,[1 2 3 4])); vprintf('sequence() is broken.\n\n','cpr','err'); end;    
    if(~isequal(c1.idx,[1;1])); vprintf('sequence() is broken.\n\n','cpr','err'); end;    
    c1+c2; %#ok<VUNUS>
    c1.*c2; %#ok<VUNUS>
    c1./c2; %#ok<VUNUS>
    sum(c1);
    norm(c1,3);
    supp(c1);
    symbol(c1);
    upsample(c1,[2 1; 0 2]);
    diffsequence(c1,[1 1]);
    conv(c1,c2,c1);
    vprintf('If there was any error since the last green test-message, @sequence is broken.\n\n','cpr',[.1 .4 .1]);
end


function dummy; end %#ok<DEFNU> %Generates an error, if the 'end' of a function is missing. 
