Skip to content

Commit c74805b

Browse files
committed
Squashed '@TIFFStack/' changes from e80689f..1eb6076
1eb6076 * Implemented (errors) when trying to concatenate `TIFFStacks` * Pulled in changes to `subsref` from @epaxon * Added a few unit tests git-subtree-dir: @tiffstack git-subtree-split: 1eb607635b0f07939ba3f021cdcd29a98d518bed
1 parent 6323781 commit c74805b

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

TIFFStack.m

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ function diagnostic(oStack)
419419

420420
%% --- Overloaded subsref
421421

422-
function [tfData] = subsref(oStack, S)
422+
function [varargout] = subsref(oStack, S)
423423
switch S(1).type
424424
case '()'
425425
% - Test for valid subscripts
@@ -545,7 +545,7 @@ function diagnostic(oStack)
545545

546546
% - Catch empty refs
547547
if (prod(vnRetDataSize) == 0)
548-
tfData = zeros(vnRetDataSize);
548+
[varargout{1:nargout}] = zeros(vnRetDataSize);
549549
return;
550550
end
551551

@@ -598,6 +598,8 @@ function diagnostic(oStack)
598598
tfData = reshape(tfData, vnRetDataSize);
599599
end
600600

601+
[varargout{1:nargout}] = tfData;
602+
601603
otherwise
602604
error('TIFFStack:InvalidReferencing', ...
603605
'*** TIFFStack: Only ''()'' referencing is supported by TIFFStacks.');
@@ -623,8 +625,8 @@ function diagnostic(oStack)
623625
end
624626

625627

626-
%% --- Overloaded numel, size, permute, ipermute, ctranspose, transpose
627-
function [n] = numel(oStack)
628+
%% --- Overloaded numel, size, permute, ipermute, ctranspose, transpose, cat, horzcat, vertcat
629+
function [n] = numel(oStack, varargin)
628630
n = prod(size(oStack)); %#ok<PSIZE>
629631
end
630632

@@ -705,6 +707,22 @@ function diagnostic(oStack)
705707
oStack = permute(oStack, [2 1]);
706708
end
707709

710+
% cat - METHOD Overloaded cat, horzcat, vertcat functions
711+
function [varargout] = cat(varargin) %#ok<STOUT>
712+
error('TIFFStack:Concatenation', ...
713+
'*** TIFFStack: Concatenation is not supported by TIFFStack.');
714+
end
715+
716+
function [varargout] = horzcat(varargin) %#ok<STOUT>
717+
error('TIFFStack:Concatenation', ...
718+
'*** TIFFStack: Concatenation is not supported by TIFFStack.');
719+
end
720+
721+
function [varargout] = vertcat(varargin) %#ok<STOUT>
722+
error('TIFFStack:Concatenation', ...
723+
'*** TIFFStack: Concatenation is not supported by TIFFStack.');
724+
end
725+
708726
%% --- Overloaded end
709727

710728
function nLength = end(oStack, nEndDim, nTotalRefDims)

private/TS_UnitTest.m

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,33 @@ function TS_UnitTest(strFilename)
109109
s = load(strMatFile);
110110
TSUT_TestReferencing(tsStack, s.tsStack, 'Serialised/Deserialised stack');
111111

112+
%% - Test error conditions
113+
TSUT_assertFail('TIFFStack:Concatenation', '[tsStack tsStack];');
114+
TSUT_assertFail('TIFFStack:Concatenation', '[tsStack; tsStack];');
115+
TSUT_assertFail('TIFFStack:Concatenation', 'cat(1, tsStack, tsStack);');
116+
TSUT_assertFail('TIFFStack:InvalidReferencing', 'tsStack{1}');
117+
TSUT_assertFail('TIFFStack:InvalidReferencing', 'tsStack.diagnostic();');
118+
TSUT_assertFail('TIFFStack:DimensionMustBePositiveInteger', 'size(tsStack, 0);');
119+
TSUT_assertFail('TIFFStack:InvalidArgument', 'tsStack.bInvert = 2;');
120+
112121
%% - Success if we reach here with no errors
113122
disp('--- TS_UnitTest: Unit tests for ''TIFFStack'' passed.');
114123
end
115124

116125

117126
function TSUT_TestReferencing(tsStack, tfStack, strTestName)
127+
% - Test stack sizes
128+
assert(isequal(size(tsStack), size(tfStack)), ...
129+
'TIFFStack:UnitTestFailed', 'The result of calling ''size'' was not equal between the two stacks.');
130+
assert(isequal(size(tsStack, 1), size(tfStack, 1)), ...
131+
'TIFFStack:UnitTestFailed', 'The result of calling ''size'' was not equal between the two stacks.');
132+
assert(isequal(size(tsStack, 2), size(tfStack, 2)), ...
133+
'TIFFStack:UnitTestFailed', 'The result of calling ''size'' was not equal between the two stacks.');
134+
assert(isequal(size(tsStack, 3), size(tfStack, 3)), ...
135+
'TIFFStack:UnitTestFailed', 'The result of calling ''size'' was not equal between the two stacks.');
136+
assert(isequal(size(tsStack, 4), size(tfStack, 4)), ...
137+
'TIFFStack:UnitTestFailed', 'The result of calling ''size'' was not equal between the two stacks.');
138+
118139
% - Test referencing entire stack
119140
TSUT_compareRef(':');
120141
TSUT_compareRef(':', ':');
@@ -245,6 +266,30 @@ function TSUT_testInvalidRef(strErrorID, varargin)
245266
end
246267
end
247268

269+
% - Function to test errors with invalid references
270+
function TSUT_assertFail(strErrorID, strCommand)
271+
try
272+
% - Evalulate command in called workspace
273+
evalin('caller', strCommand);
274+
275+
catch mErr
276+
% - Check whether the correct error was reported
277+
if ~isequal(mErr.identifier, strErrorID)
278+
mUTErr = MException('TIFFStack:UnitTestFailed', 'Incorrect error raised during error test with command [%s]. Desired error [%s], raised error [%s].', ...
279+
strCommand, strErrorID, mErr.identifier);
280+
mErr = mErr.addCause(mUTErr);
281+
rethrow(mErr);
282+
end
283+
return;
284+
end
285+
286+
% - We should never get here, so raise an error
287+
error('TIFFStack:UnitTestFailed:ErrorNotThrown', ...
288+
'An error should have occurred but did not, with subs %s, during test [%s]. Desired error [%s].', ...
289+
TSUT_subs2str(varargin), strTestName, strErrorID);
290+
end
291+
292+
248293
function strSubs = TSUT_subs2str(varargin)
249294
cSubsStr = cellfun(@num2str, varargin{:}, 'UniformOutput', false);
250295
strSubs = ['(' ...

0 commit comments

Comments
 (0)