From 27a64fc187e0b2548e128b217ef601827e1f7381 Mon Sep 17 00:00:00 2001 From: Loic Marx Date: Mon, 29 Oct 2018 10:24:30 +0100 Subject: [PATCH 1/5] testing KLDis function --- refData_KLDis_1.mat | Bin 0 -> 197 bytes .../analysis/testThermo/testTemplate.m | 72 ++++++++++++++++++ testKLDis.m | 34 +++++++++ 3 files changed, 106 insertions(+) create mode 100644 refData_KLDis_1.mat create mode 100644 test/verifiedTests/analysis/testThermo/testTemplate.m create mode 100644 testKLDis.m diff --git a/refData_KLDis_1.mat b/refData_KLDis_1.mat new file mode 100644 index 0000000000000000000000000000000000000000..77e22119d7d135a3b324bfb1fa5a3fe7b54c08f4 GIT binary patch literal 197 zcmeZu4DoSvQZUssQ1EpO(M`+DN!3vZ$Vn_o%P-2c0*X0%nwjV*I2WZRmZYXA%Z1kCPJ;J}@MiDLiYq zq;P=isWGFWvdCuUjobUZ(+c+}GOJI}WjJ!FtUSd>a{G<^eN(snIQTW8nqgiwmkj`f CyEW4Q literal 0 HcmV?d00001 diff --git a/test/verifiedTests/analysis/testThermo/testTemplate.m b/test/verifiedTests/analysis/testThermo/testTemplate.m new file mode 100644 index 0000000000..26f2f4bb81 --- /dev/null +++ b/test/verifiedTests/analysis/testThermo/testTemplate.m @@ -0,0 +1,72 @@ +% The COBRAToolbox: .m +% +% Purpose: +% - : +% + +global CBTDIR + +% define the features required to run the test +requiredToolboxes = { 'bioinformatics_toolbox', 'optimization_toolbox' }; + +requiredSolvers = { 'dqqMinos', 'matlab' }; + +% require the specified toolboxes and solvers, along with a UNIX OS +solversPkgs = prepareTest('reqSolvers', requiredSolvers, 'requiredToolboxes', requiredToolboxes, 'needUnix', true); + +% save the current path +currentDir = pwd; + +% initialize the test +cd(fileparts(which(mfilename))); + +% set the tolerance +tol = 1e-8; + +% load the model +%Either: +model = getDistributedModel('ecoli_core_model.mat'); %For all models in the test/models folder and subfolders +%or +model = readCbModel('testModel.mat','modelName','NameOfTheModelStruct'); %For all models which are part of this particular test. + +%Load reference data +load('testData_functionToBeTested.mat'); + +%{ +% This is only necessary for tests that test a function that runs in parallel. +% create a parallel pool +% This is in try/catch as otherwise the test will error if no parallel +% toolbox is installed. +try + parTest = true; + poolobj = gcp('nocreate'); % if no pool, do not create new one. + if isempty(poolobj) + parpool(2); % launch 2 workers + end +catch ME + parTest = false; + fprintf('No Parallel Toolbox found. TRying test without Parallel toolbox.\n') +end +if parTest +% if parallel toolbox has to be present (if not, this can be left out). +%} + +for k = 1:length(solverPkgs.LP) + fprintf(' -- Running using the solver interface: %s ... ', solverPkgs.LP{k}); + + solverLPOK = changeCobraSolver(solverPkgs.LP{k}, 'LP', 0); + + if solverLPOK + % + end + wrongInputs = {'FirstArgument',modelForSecondArgument}; + verifyCobraFunctionError('testFile', 'inputs', wrongInputs); + % output a success message + fprintf('Done.\n'); +end + +% change the directory +cd(currentDir) diff --git a/testKLDis.m b/testKLDis.m new file mode 100644 index 0000000000..acc4449c75 --- /dev/null +++ b/testKLDis.m @@ -0,0 +1,34 @@ +% 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))); + + +% Generate 2 matrix of the same size + P= [12 62; 93 3] + Q= [1 23; 43 1] + + % Reference data + KLDis_1 = KLDis(P,Q) + %save('refData_KLDis_1.mat', 'KLDis_1'); + % Test if a function throws an error or warning message +assert(verifyCobraFunctionError('KLDis','inputs', {P, Q'},'testMessage', 'Input2 has the wrong dimension')); + +% run the function +KLD=KLDis(P,Q); + +% compare the scaled matrix against the reference data +assert(isequal(KLD, KLDis_1)) + +% change the directory +cd(currentDir) From e8548d468337e231640c6ba5f831400914a64ac1 Mon Sep 17 00:00:00 2001 From: Loic Marx Date: Tue, 30 Oct 2018 12:32:33 +0100 Subject: [PATCH 2/5] deleting template --- .../analysis/testThermo/testTemplate.m | 72 ------------------- 1 file changed, 72 deletions(-) delete mode 100644 test/verifiedTests/analysis/testThermo/testTemplate.m diff --git a/test/verifiedTests/analysis/testThermo/testTemplate.m b/test/verifiedTests/analysis/testThermo/testTemplate.m deleted file mode 100644 index 26f2f4bb81..0000000000 --- a/test/verifiedTests/analysis/testThermo/testTemplate.m +++ /dev/null @@ -1,72 +0,0 @@ -% The COBRAToolbox: .m -% -% Purpose: -% - : -% - -global CBTDIR - -% define the features required to run the test -requiredToolboxes = { 'bioinformatics_toolbox', 'optimization_toolbox' }; - -requiredSolvers = { 'dqqMinos', 'matlab' }; - -% require the specified toolboxes and solvers, along with a UNIX OS -solversPkgs = prepareTest('reqSolvers', requiredSolvers, 'requiredToolboxes', requiredToolboxes, 'needUnix', true); - -% save the current path -currentDir = pwd; - -% initialize the test -cd(fileparts(which(mfilename))); - -% set the tolerance -tol = 1e-8; - -% load the model -%Either: -model = getDistributedModel('ecoli_core_model.mat'); %For all models in the test/models folder and subfolders -%or -model = readCbModel('testModel.mat','modelName','NameOfTheModelStruct'); %For all models which are part of this particular test. - -%Load reference data -load('testData_functionToBeTested.mat'); - -%{ -% This is only necessary for tests that test a function that runs in parallel. -% create a parallel pool -% This is in try/catch as otherwise the test will error if no parallel -% toolbox is installed. -try - parTest = true; - poolobj = gcp('nocreate'); % if no pool, do not create new one. - if isempty(poolobj) - parpool(2); % launch 2 workers - end -catch ME - parTest = false; - fprintf('No Parallel Toolbox found. TRying test without Parallel toolbox.\n') -end -if parTest -% if parallel toolbox has to be present (if not, this can be left out). -%} - -for k = 1:length(solverPkgs.LP) - fprintf(' -- Running using the solver interface: %s ... ', solverPkgs.LP{k}); - - solverLPOK = changeCobraSolver(solverPkgs.LP{k}, 'LP', 0); - - if solverLPOK - % - end - wrongInputs = {'FirstArgument',modelForSecondArgument}; - verifyCobraFunctionError('testFile', 'inputs', wrongInputs); - % output a success message - fprintf('Done.\n'); -end - -% change the directory -cd(currentDir) From 8d840ebb776a096fa8a7b6efac268abfdbf2dfc7 Mon Sep 17 00:00:00 2001 From: Loic Marx Date: Wed, 31 Oct 2018 14:46:52 +0100 Subject: [PATCH 3/5] testing KLDis function --- testKLDis.m | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/testKLDis.m b/testKLDis.m index acc4449c75..b253626347 100644 --- a/testKLDis.m +++ b/testKLDis.m @@ -13,22 +13,25 @@ % initialize the test cd(fileparts(which(mfilename))); +% set the tolerance +tol = 1e-6; % Generate 2 matrix of the same size - P= [12 62; 93 3] - Q= [1 23; 43 1] - - % Reference data - KLDis_1 = KLDis(P,Q) - %save('refData_KLDis_1.mat', 'KLDis_1'); - % Test if a function throws an error or warning message -assert(verifyCobraFunctionError('KLDis','inputs', {P, Q'},'testMessage', 'Input2 has the wrong dimension')); +P = [1 2; 2 1]; +Q = [3 2; 2 3]; % run the function -KLD=KLDis(P,Q); +KLD = KLDis(P,Q); % compare the scaled matrix against the reference data -assert(isequal(KLD, KLDis_1)) +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) From f36376b6bdb0f4f64aac471df998b6d25e44366b Mon Sep 17 00:00:00 2001 From: Loic Marx Date: Wed, 31 Oct 2018 14:57:26 +0100 Subject: [PATCH 4/5] moving test --- .../verifiedTests/analysis/testKLdistance/testKLDis.m | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename testKLDis.m => test/verifiedTests/analysis/testKLdistance/testKLDis.m (100%) diff --git a/testKLDis.m b/test/verifiedTests/analysis/testKLdistance/testKLDis.m similarity index 100% rename from testKLDis.m rename to test/verifiedTests/analysis/testKLdistance/testKLDis.m From 4b27d95817b98441d287e60285be367c3a91aff8 Mon Sep 17 00:00:00 2001 From: Loic Marx Date: Wed, 31 Oct 2018 14:59:05 +0100 Subject: [PATCH 5/5] delete ref data --- refData_KLDis_1.mat | Bin 197 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 refData_KLDis_1.mat diff --git a/refData_KLDis_1.mat b/refData_KLDis_1.mat deleted file mode 100644 index 77e22119d7d135a3b324bfb1fa5a3fe7b54c08f4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 197 zcmeZu4DoSvQZUssQ1EpO(M`+DN!3vZ$Vn_o%P-2c0*X0%nwjV*I2WZRmZYXA%Z1kCPJ;J}@MiDLiYq zq;P=isWGFWvdCuUjobUZ(+c+}GOJI}WjJ!FtUSd>a{G<^eN(snIQTW8nqgiwmkj`f CyEW4Q