comparison m-toolbox/classes/tests/@Assert/doubleEqualsWithAccuracy.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 % DOUBLEEQUALSWITHACCURACY Assert that two doubles are equal within some tolerance.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: Assert that two doubles are equal within some tolerance.
5 % doubleEqualsWithAccuracy(A, B, tol) throws an
6 % AssertionFailed exception if A and B are not equal within a
7 % tolerance.
8 % A and B must have the same class and the same length.
9 %
10 % COMMAND: Assert.doubleEquals(val1, val2, tol)
11 % Assert.doubleEquals(val1, val2, tol, message)
12 %
13 % VERSION: $Id: doubleEqualsWithAccuracy.m,v 1.1 2011/06/20 16:32:56 ingo Exp $
14 %
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16 function doubleEqualsWithAccuracy(val1, val2, tol, varargin)
17
18 % Check class of the input arguments
19 if ~isnumeric(val1) || ~isnumeric(val2)
20 Assert.fail('The input arguments must be two double.');
21 end
22
23 % Check the length of the inputs
24 if numel(val1) ~= numel(val2)
25 Assert.fail('The input arguments don''t have the same length.');
26 end
27
28 if abs(val1 - val2) > tol
29 Assert.fail(varargin{:});
30 end
31
32 end