comparison m-toolbox/classes/tests/@Assert/objectEqualsWithException.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % OBJECTEQUALSWITHEXCEPTION Assert that two ltpda_obj objects are equal with an exception list.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: Assert that two ltpda_obj objects are equal with an
5 % exception list.
6 % objectEquals(A, B) throws an AssertionFailed exception if
7 % eq(A,B, exception_list) is not equal. A and B must have the
8 % same class and the same length.
9 %
10 % COMMAND: Assert.objectEqualsWithException(val1, val2, exceptions)
11 % Assert.objectEqualsWithException(val1, val2, exceptions, message)
12 %
13 % EXCEPTIONS: - a cell array with the exceptions.
14 % - a PLIST with the parameter 'Exceptions' for the key and a
15 % cell array with exceptions for the value.
16 %
17 % VERSION: $Id: objectEqualsWithException.m,v 1.1 2011/06/20 16:32:56 ingo Exp $
18 %
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20 function objectEqualsWithException(val1, val2, ex, varargin)
21
22 % Check number in input arguments
23 if nargin < 3
24 Assert.fail('This function needs at least three inputs.');
25 end
26
27 % Check class of the input arguments
28 if ~strcmp(class(val1), class(val2))
29 Assert.fail('The input arguments must be from the same class.');
30 end
31
32 % Check class of the input arguments
33 if ~isa(val1, 'ltpda_obj')
34 Assert.fail('The input arguments must be derived from the ltpda_obj class.');
35 end
36
37 % Check the exception list
38 if isa(ex, 'plist') && ex.isparam('Exceptions')
39 ex = ex.find('Exceptions');
40 elseif iscell(ex)
41 % Don't do anything
42 else
43 Assert.fail('The exception list must be a cell array or a PLIST.');
44 end
45
46 % Check the length of the inputs
47 if numel(val1) ~= numel(val2)
48 Assert.fail('The input arguments don''t have the same length.');
49 end
50
51 if ~eq(val1, val2, ex{:})
52 Assert.fail(varargin{:});
53 end
54
55 end