% **********************************************************************
%       function l2lc_tests.m by www.boundary-element-method.com       *
% **********************************************************************
% l2lc_tests.m Version 1, Sept 2015

% Matlab/Freemat/Octave/Scilab open source codes
% Stephen Kirkup, School of Engineering
% University of Central Lancashire
% http://www.researchgate.net/profile/Stephen_Kirkup

% function l2lc_tests()
% A set of tests for l2lc.m

% Web source of this file
%  http://www.boundary-element-method.com/mfiles/l2lc_tests.m
% A guide to this routine is given at
%  http://www.boundary-element-method.com/mfiles/l2lc_tests_m.pdf
% This is a test file for
%  http://www.boundary-element-method.com/mfiles/l2lc.m

function l2lc_tests()
    
    needl=true;
    needm=true;
    needmt=true;
    needn=true;

    lvalid=true;
    tolGeom=0.000001;
    tolQuad=0.000001;
    
    vecp=zeros(2,1);
    
    [w,x,nq]=gl();

    lponel=false;
     
% Tests 1
% =======
    p(1)=0.0;
    p(2)=0.0;
    qa(1)=1.0;
    qa(2)=0.0;
    qb(1)=1.5;
    qb(2)=0.0;
    
% Test 1A
% -------
    
    vecp(1)=0.0;
    vecp(2)=1.0;
    
    [l,m,mt,n,lfail]=l2lc(p,vecp,qa,qb,lponel, nq, w, x, lvalid, tolGeom, tolQuad, needl,needm,needmt,needn);
                        if (abs(l+0.017220193)+abs(m)+abs(mt)+abs(n-0.053051648)<0.001 &~lfail)
        'Test 1A Passed'
    else
        'Test 1A Failed'
    end
    
% Test 1B
% -------
    
    vecp(1)=-1.0;
    vecp(2)=0.0;
    
    [l,m,mt,n,lfail]=l2lc(p,vecp,qa,qb,lponel, nq, w, x, lvalid, tolGeom, tolQuad, needl,needm,needmt,needn);
    if (abs(l+0.017220193)+abs(m)+abs(mt+0.064531776)+abs(n)<0.001 &~lfail)

        'Test 1B Passed'
    else
        'Test 1B Failed'
    end
                


% Test 1C
% -------
    
    vecp(1)=0.6;
    vecp(2)=0.8;
    
        [l,m,mt,n,lfail]=l2lc(p,vecp,qa,qb,lponel, nq, w, x, lvalid, tolGeom, tolQuad, needl,needm,needmt,needn);
    if (abs(l+0.017220193)+abs(m)+abs(mt-0.038719066)+abs(n-0.042441318)<0.001 &~lfail)        'Test 1B Passed'
        'Test 1C Passed'
    else
        'Test 1C Failed'
    end
                
% Test 2
% ======
    p(1)=0.0;
    p(2)=0.0;
    qa(1)=2.0;
    qa(2)=0.0;
    qb(1)=2.0;
    qb(2)=1.0;
    vecp(1)=1.0;
    vecp(2)=0.0;

 
    [l,m,mt,n,lfail]=l2lc(p,vecp,qa,qb,lponel, nq, w, x, lvalid, tolGeom, tolQuad, needl,needm,needmt,needn);
    if (abs(l+0.116503674)+abs(m-0.073791809)+abs(mt-0.073791809)+abs(n-0.031830989)<0.001 &~lfail)       'Test 1B Passed'
        'Test 2 Passed'
    else
        'Test 2 Failed'
    end
    
    
% Test 3
% ======
    p(1)=1.15;
    p(2)=2.2;
    qa(1)=1.0;
    qa(2)=2.0;
    qb(1)=1.3;
    qb(2)=2.4;
    vecp(1)=-0.8;
    vecp(2)=0.6;
    lponel=true;

 
    [l,m,mt,n,lfail]=l2lc(p,vecp,qa,qb,lponel, nq, w, x, lvalid, tolGeom, tolQuad, needl,needm,needmt,needn);
    if (abs(l-0.189895272)+abs(m)+abs(mt)+abs(n+1.273239545)<0.001 &~lfail)
        'Test 3 Passed'
    else
        'Test 3 Failed'
    end