Skip to content

Commit

Permalink
Merge pull request #1369 from loicmarx/test-KLDis
Browse files Browse the repository at this point in the history
Test function for KLDis
  • Loading branch information
laurentheirendt authored Nov 1, 2018
2 parents 987faee + 4b27d95 commit 7b4bdee
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/verifiedTests/analysis/testKLdistance/testKLDis.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
% The COBRAToolbox: testKLDis.m
%
% Purpose:
% - test the functionality of KLDis
%
% Authors:
% - Loic Marx
%

% save the current path
currentDir = pwd;

% initialize the test
cd(fileparts(which(mfilename)));

% set the tolerance
tol = 1e-6;

% Generate 2 matrix of the same size
P = [1 2; 2 1];
Q = [3 2; 2 3];

% run the function
KLD = KLDis(P,Q);

% compare the scaled matrix against the reference data
assert(norm(KLD - 0.12723233459191 * [1; 1]) < tol)

Q2 = [inf inf];
P2 = [inf inf];

% Test if KLDis throws an error
assert(verifyCobraFunctionError('KLDis','inputs', {P, Q(:,1)}, 'testMessage', 'the number of columns in P and Q should be the same'));
assert(verifyCobraFunctionError('KLDis','inputs', {P2, Q2}, 'testMessage', 'the inputs contain non-finite values!'));

% change the directory
cd(currentDir)

0 comments on commit 7b4bdee

Please sign in to comment.