From dc3a5992f5bddc8b01ccd3f33cee1e009937e47f Mon Sep 17 00:00:00 2001 From: Zoe Hamel Date: Tue, 3 Nov 2015 10:38:12 -0800 Subject: [PATCH 1/4] test_unusual_input test whether function generates matrices when inputs are `incorrect`. --- test_unusual_input | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test_unusual_input diff --git a/test_unusual_input b/test_unusual_input new file mode 100644 index 0000000..dd45838 --- /dev/null +++ b/test_unusual_input @@ -0,0 +1,27 @@ +function test_unusual_input(N,dx) + +% This function is used to test whether the function diff_matrices1d will +% create an output for D1xb, D1xc, D1xf, or D1xx when the inputs for +% N and dx don't fit the task. + +% It will return 1(TRUE) if diff_matrices1d: +% - generates at least one of the 4 matrices even though at least one of the inputs is 'incorrect'; +% - generates the 4 matrices when the inputs are 'correct'. +% will return 0(FALSE) if it doesn't create any of the 4 matrices when the +% inputs are 'correct'. + +% It turns out that when dx = nan, outputs is returned with enties NAN. +% Otherwise it seems to work as expected. + +try % used to run the entire script even though the function return an error +[Ix,D1xx,D1xc,D1xb,D1xf] = diff_matrices1d(N,dx,'n'); % the last argument can be chosen between BC, 'n', or 'd' +end + +if (~(isinteger(N))) | (~(isnumeric(dx))) | (dx == Inf) | (isnan(dx)) % 'incorrect' inputs + (exist('D1xb') == 0)&(exist('D1xc') == 0)&(exist('D1xf') == 0)&(exist('D1xx') == 0) +else + (exist('D1xb') == 1)&(exist('D1xc') == 1)&(exist('D1xf') == 1)&(exist('D1xx') == 1) +end +end + + From e5d22059a7cc7fd5070a9082280cc327b79b6a1d Mon Sep 17 00:00:00 2001 From: Zoe Hamel Date: Tue, 3 Nov 2015 13:34:28 -0800 Subject: [PATCH 2/4] Update test_unusual_input added `nargin ==` --- test_unusual_input | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test_unusual_input b/test_unusual_input index dd45838..9d8e79d 100644 --- a/test_unusual_input +++ b/test_unusual_input @@ -13,6 +13,13 @@ function test_unusual_input(N,dx) % It turns out that when dx = nan, outputs is returned with enties NAN. % Otherwise it seems to work as expected. +if nargin == 0 + N = false; + dx = false; +elseif nargin == 1 + dx = false; +end + try % used to run the entire script even though the function return an error [Ix,D1xx,D1xc,D1xb,D1xf] = diff_matrices1d(N,dx,'n'); % the last argument can be chosen between BC, 'n', or 'd' end From a040b7828b0e540c1aca86107fb660c5698c2d59 Mon Sep 17 00:00:00 2001 From: Zoe Hamel Date: Thu, 5 Nov 2015 13:39:59 -0800 Subject: [PATCH 3/4] replaced isinteger() --- test_unusual_input | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test_unusual_input b/test_unusual_input index 9d8e79d..c69e2ce 100644 --- a/test_unusual_input +++ b/test_unusual_input @@ -24,11 +24,9 @@ try % used to run the entire script even thoug [Ix,D1xx,D1xc,D1xb,D1xf] = diff_matrices1d(N,dx,'n'); % the last argument can be chosen between BC, 'n', or 'd' end -if (~(isinteger(N))) | (~(isnumeric(dx))) | (dx == Inf) | (isnan(dx)) % 'incorrect' inputs +if (~(rem(N,1)==0)) | (~(isnumeric(dx))) | (dx == Inf) | (isnan(dx)) % 'incorrect' inputs (exist('D1xb') == 0)&(exist('D1xc') == 0)&(exist('D1xf') == 0)&(exist('D1xx') == 0) else (exist('D1xb') == 1)&(exist('D1xc') == 1)&(exist('D1xf') == 1)&(exist('D1xx') == 1) end end - - From e9c11117aa18c2cfe0d46d5cf746b528bbda3b14 Mon Sep 17 00:00:00 2001 From: Zoe Hamel Date: Fri, 6 Nov 2015 08:46:09 -0800 Subject: [PATCH 4/4] Update test_unusual_input --- test_unusual_input | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/test_unusual_input b/test_unusual_input index c69e2ce..16beb70 100644 --- a/test_unusual_input +++ b/test_unusual_input @@ -1,32 +1,46 @@ -function test_unusual_input(N,dx) +function test_unusual_input(verbose, plot) % This function is used to test whether the function diff_matrices1d will % create an output for D1xb, D1xc, D1xf, or D1xx when the inputs for % N and dx don't fit the task. -% It will return 1(TRUE) if diff_matrices1d: -% - generates at least one of the 4 matrices even though at least one of the inputs is 'incorrect'; +% It will return 'true' if diff_matrices1d: +% - doesn't generate any of the 4 matrices when at least one of the inputs is 'incorrect'; % - generates the 4 matrices when the inputs are 'correct'. -% will return 0(FALSE) if it doesn't create any of the 4 matrices when the -% inputs are 'correct'. +% It will return 'false' if diff_matrices1d: +% - generates at least one of the 4 matrices even though at least one of the inputs is 'incorrect'; +% - doesn't generate the 4 matrices when the inputs are 'correct'. + +% Here we take the specific example of: +% N = 3; (correct) +% dx = nan; (incorrect) % It turns out that when dx = nan, outputs is returned with enties NAN. -% Otherwise it seems to work as expected. if nargin == 0 - N = false; - dx = false; + verbose = false; + plot = false; elseif nargin == 1 - dx = false; + plot = false; end -try % used to run the entire script even though the function return an error -[Ix,D1xx,D1xc,D1xb,D1xf] = diff_matrices1d(N,dx,'n'); % the last argument can be chosen between BC, 'n', or 'd' +N = 3; % Those inputs could be adapted for other (N,dx) +dx = nan; + +try +[Ix,D1xx,D1xc,D1xb,D1xf] = diff_matrices1d(N,dx,'n'); % the last argument can be chosen between BC, 'n', or 'd' end -if (~(rem(N,1)==0)) | (~(isnumeric(dx))) | (dx == Inf) | (isnan(dx)) % 'incorrect' inputs - (exist('D1xb') == 0)&(exist('D1xc') == 0)&(exist('D1xf') == 0)&(exist('D1xx') == 0) +if (~(rem(N,1)==0)) | (~(isnumeric(dx))) | (dx == Inf) | (isnan(dx)) + r = (exist('D1xb') == 0)&(exist('D1xc') == 0)&(exist('D1xf') == 0)&(exist('D1xx') == 0); else - (exist('D1xb') == 1)&(exist('D1xc') == 1)&(exist('D1xf') == 1)&(exist('D1xx') == 1) -end + r = (exist('D1xb') == 1)&(exist('D1xc') == 1)&(exist('D1xf') == 1)&(exist('D1xx') == 1); end + +% return true/false if the test passed/failed +if r == 0 + disp ('false') +elseif r == 1 + disp ('true') +end +end