% **********************************************************************
%  Subroutine OkGeometry2lc_tests.m by www.boundary-element-method.com *
% **********************************************************************
% OkGeometry2lc_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

% A set of tests for OkGeometry2lc.m
% Source of this code:
%  http://www.boundary-element-method.com/mfiles/OkGeometry2lc_tests.m
% Source of the user-guide:
%  http://www.boundary-element-method.com/mfiles/OkGeometry2lc_tests_m.pdf
% Source of OkGeometry2lc:
%  http://www.boundary-element-method.com/mfiles/OkGeometry2lc.m

function OkGeometry2lc_tests()
    
    p=[0 0];
    vecp=[0; 1];
    qa=[1 0];
    qb=[1.5 0];
    lponel=false;
    qlen=dist(qa,qb);
    
    'Test 1 on tolGeom: tolGeom=0, but tolGeom must be positive'
    tolGeom=0.0;
    lerror=OkGeometry2lc(p, vecp, qa, qb, lponel, tolGeom);
    lerror

    'Test 2 on tolGeom: tolGeom=0.1, but tolGeom must not be so large'
    tolGeom=0.1;
    lerror=OkGeometry2lc(p, vecp, qa, qb, lponel, tolGeom);
    lerror
    
% From now on tolGeom=0.000001
    tolGeom=0.000001;
    
    'Test 3: qa and qb must be distinct points'
    qb(1)=1.0;
    lerror=OkGeometry2lc(p, vecp, qa, qb, lponel, tolGeom);
    lerror
     
% Reset qb
    qb(1)=1.5;
        
    'Test 4: p must be a unit vector'
    vecp=[0; 0.9];
    lerror=OkGeometry2lc(p, vecp, qa, qb, lponel, tolGeom);
    lerror
    
    
    'Test 5: vecp must be equal to the normal to qa-qb when lponel=true'
    vecp=[1;0];
    lponel=true;
    lerror=OkGeometry2lc(p, vecp, qa, qb, lponel, tolGeom);
    lerror
 
% Reset vecp
    vecp=[0; 1];
    
    'Test 6: If lponel=false p must not be on qa-qb'
    p=[1.2 0.0];
    lponel=false;
    lerror=OkGeometry2lc(p, vecp, qa, qb, lponel, tolGeom);
    lerror
    
    
    'Test 7: p and qa must be distinct'
    p=[1.0 0.0];
    lponel=true;
    lerror=OkGeometry2lc(p, vecp, qa, qb, lponel, tolGeom);
    lerror
    
    'Test 8: p and qb must be distinct'
    qa=[0.5 0];
    qb=[1.0 0];
    lponel=true;
    lerror=OkGeometry2lc(p, vecp, qa, qb, lponel, tolGeom);
    lerror

% Reset qa,qb
    qa=[1 0];
    qb=[1.5 0];
    
    'Test 9:  p should not be close to qa-qb when lponel=false'
    p=[1.2 0.02];
    lponel=false;
    lerror=OkGeometry2lc(p, vecp, qa, qb, lponel, tolGeom);
    lerror
    
    'Test 10:  p should not be close to qa or qb when lponel=true'
    p=[1.04 0.00];
    lponel=true;
    lerror=OkGeometry2lc(p, vecp, qa, qb, lponel, tolGeom);
    lerror
      
    