@@ -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.' );
114123end
115124
116125
117126function 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
246267end
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+
248293function strSubs = TSUT_subs2str(varargin )
249294 cSubsStr = cellfun(@num2str , varargin{: }, ' UniformOutput' , false );
250295 strSubs = [' (' ...
0 commit comments