-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1369 from loicmarx/test-KLDis
Test function for KLDis
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |