Mercurial > hg > octave-lyh
annotate scripts/testfun/assert.m @ 17258:afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
* assert.m
(assert): Document non-scalar tolerance option. Remove FIXME about format of
output. Remove 'coda' and 'iserror' spanning whole routine. Use structure
'err.index/expected/observed/reason' to keep track of multiple results and
recursions. Add persistent variables 'errmsg', 'assert_call_depth' and
'assert_error_occurred' to allow recursions and print only when all complete.
Place output formating in pprint() function. Construct vector tolerance from
scalar tolerance. Add test illustrating recursions and multiple tables. Add
test illustrating variable tolerance. Add test illustrating multidimensional
matrices. Remove looping for constructing error information. Add thorough
tests for exceptional values by checking both real and imaginary. Place zeros
where exceptional values exist in real and imaginary parts of the two matrices.
Add tests illustrating exceptional values in real and/or imaginary part and
numerical mismatch in the other part.
(construct_indeces): Format linear indexing as tuple indexing, vectors (#),
scalars ().
(pprint): Sub function to format and print input command, index of failure,
expected and observed values at failure, and the reason for failure.
author | Daniel J Sebald <daniel.sebald@ieee.org> |
---|---|
date | Mon, 12 Aug 2013 15:44:40 -0500 |
parents | d6499c14021c |
children | 684ccccbc15d |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14093
diff
changeset
|
1 ## Copyright (C) 2000-2012 Paul Kienzle |
5589 | 2 ## |
7016 | 3 ## This file is part of Octave. |
5589 | 4 ## |
7016 | 5 ## Octave is free software; you can redistribute it and/or modify it |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
5589 | 14 ## |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5589 | 18 |
19 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
20 ## @deftypefn {Function File} {} assert (@var{cond}) |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
21 ## @deftypefnx {Function File} {} assert (@var{cond}, @var{errmsg}, @dots{}) |
9313 | 22 ## @deftypefnx {Function File} {} assert (@var{cond}, @var{msg_id}, @var{errmsg}, @dots{}) |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
23 ## @deftypefnx {Function File} {} assert (@var{observed}, @var{expected}) |
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
24 ## @deftypefnx {Function File} {} assert (@var{observed}, @var{expected}, @var{tol}) |
5589 | 25 ## |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
26 ## Produce an error if the specified condition is not met. @code{assert} can |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
27 ## be called in three different ways. |
5589 | 28 ## |
29 ## @table @code | |
17178
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
30 ## @item assert (@var{cond}) |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
31 ## @itemx assert (@var{cond}, @var{errmsg}, @dots{}) |
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
32 ## @itemx assert (@var{cond}, @var{msg_id}, @var{errmsg}, @dots{}) |
5589 | 33 ## Called with a single argument @var{cond}, @code{assert} produces an |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
34 ## error if @var{cond} is zero. When called with more than one argument the |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
35 ## additional arguments are passed to the @code{error} function. |
5589 | 36 ## |
37 ## @item assert (@var{observed}, @var{expected}) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
38 ## Produce an error if observed is not the same as expected. Note that |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
39 ## @var{observed} and @var{expected} can be scalars, vectors, matrices, |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
40 ## strings, cell arrays, or structures. |
5589 | 41 ## |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
42 ## @item assert (@var{observed}, @var{expected}, @var{tol}) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
43 ## Produce an error if observed is not the same as expected but equality |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
44 ## comparison for numeric data uses a tolerance @var{tol}. |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
45 ## If @var{tol} is positive then it is an absolute tolerance which will produce |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
46 ## an error if @code{abs (@var{observed} - @var{expected}) > abs (@var{tol})}. |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
47 ## If @var{tol} is negative then it is a relative tolerance which will produce |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
48 ## an error if @code{abs (@var{observed} - @var{expected}) > |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
49 ## abs (@var{tol} * @var{expected})}. If @var{expected} is zero @var{tol} will |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
50 ## always be interpreted as an absolute tolerance. If @var{tol} is not scalar |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
51 ## its dimensions must agree with those of @var{observed} and @var{expected} |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
52 ## and tests are performed on an element-wise basis. |
5589 | 53 ## @end table |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
54 ## @seealso{test, fail, error} |
5589 | 55 ## @end deftypefn |
56 | |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
57 function assert (cond, varargin) |
6494 | 58 |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
59 if (exist ("assert_call_depth", "var")) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
60 assert_call_depth++; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
61 else |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
62 persistent assert_call_depth = 0; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
63 persistent assert_error_occurred; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
64 assert_error_occurred = 0; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
65 persistent errmsg; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
66 errmsg = ""; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
67 end |
6494 | 68 |
69 in = deblank (argn(1,:)); | |
70 for i = 2:rows (argn) | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
71 in = [in "," deblank(argn(i,:))]; |
7151 | 72 endfor |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
73 in = ["(" in ")"]; |
5589 | 74 |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
75 if (nargin == 1 || (nargin > 1 && islogical (cond) && ischar (varargin{1}))) |
9841
6f1ea8241c99
make isnumeric yield false on logicals
Jaroslav Hajek <highegg@gmail.com>
parents:
9448
diff
changeset
|
76 if ((! isnumeric (cond) && ! islogical (cond)) || ! all (cond(:))) |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
77 if (nargin == 1) |
10549 | 78 ## Say which elements failed? |
79 error ("assert %s failed", in); | |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
80 else |
10549 | 81 error (varargin{:}); |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
82 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
83 endif |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
84 else |
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
85 if (nargin < 2 || nargin > 3) |
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
86 print_usage (); |
5589 | 87 endif |
88 | |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
89 expected = varargin{1}; |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
90 if (nargin < 3) |
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
91 tol = 0; |
5589 | 92 else |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
93 tol = varargin{2}; |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
94 endif |
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
95 |
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
96 if (exist ("argn") == 0) |
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
97 argn = " "; |
5589 | 98 endif |
99 | |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
100 ## Add to lists as the errors accumulate. If empty at end then no erros. |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
101 err.index = {}; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
102 err.observed = {}; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
103 err.expected = {}; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
104 err.reason = {}; |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
105 |
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
106 if (ischar (expected)) |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
107 if (! ischar (cond)) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
108 err.index{end + 1} = "[]"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
109 err.expected{end + 1} = expected; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
110 if (isnumeric (cond)) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
111 err.observed{end + 1} = num2str (cond); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
112 err.reason{end + 1} = "Expected string, but observed number"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
113 elseif (iscell (cond)) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
114 err.observed{end + 1} = "{}"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
115 err.reason{end + 1} = "Expected string, but observed cell"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
116 else |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
117 err.observed{end + 1} = "[]"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
118 err.reason{end + 1} = "Expected string, but observed struct"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
119 end |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
120 elseif (! strcmp (cond, expected)) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
121 err.index{end + 1} = "[]"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
122 err.observed{end + 1} = cond; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
123 err.expected{end + 1} = expected; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
124 err.reason{end + 1} = "Strings don't match"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
125 endif |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
126 elseif (iscell (expected)) |
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
127 if (! iscell (cond) || any (size (cond) != size (expected))) |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
128 err.index{end + 1} = "{}"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
129 err.observed{end + 1} = "O"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
130 err.expected{end + 1} = "E"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
131 err.reason{end + 1} = "Cell sizes don't match"; |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
132 else |
10549 | 133 try |
134 for i = 1:length (expected(:)) | |
135 assert (cond{i}, expected{i}, tol); | |
136 endfor | |
137 catch | |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
138 err.index{end + 1} = "{}"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
139 err.observed{end + 1} = "O"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
140 err.expected{end + 1} = "E"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
141 err.reason{end + 1} = "Cell configuration error"; |
10549 | 142 end_try_catch |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
143 endif |
5589 | 144 |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
145 elseif (isstruct (expected)) |
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
146 if (! isstruct (cond) || any (size (cond) != size (expected)) |
10549 | 147 || rows (fieldnames (cond)) != rows (fieldnames (expected))) |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
148 err.index{end + 1} = "{}"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
149 err.observed{end + 1} = "O"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
150 err.expected{end + 1} = "E"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
151 err.reason{end + 1} = "Structure sizes don't match"; |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
152 else |
10549 | 153 try |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
154 #empty = numel (cond) == 0; |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
155 empty = isempty (cond); |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
156 normal = (numel (cond) == 1); |
10549 | 157 for [v, k] = cond |
158 if (! isfield (expected, k)) | |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
159 err.index{end + 1} = "."; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
160 err.observed{end + 1} = "O"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
161 err.expected{end + 1} = "E"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
162 err.reason{end + 1} = ["'" k "'" " is not an expected field"]; |
10549 | 163 endif |
164 if (empty) | |
12882
724bb6b7e3d5
assert.m: Correctly compare empty structures.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
165 v = {}; |
724bb6b7e3d5
assert.m: Correctly compare empty structures.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
166 elseif (normal) |
10549 | 167 v = {v}; |
168 else | |
169 v = v(:)'; | |
170 endif | |
171 assert (v, {expected.(k)}, tol); | |
172 endfor | |
173 catch | |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
174 err.index{end + 1} = "."; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
175 err.observed{end + 1} = "O"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
176 err.expected{end + 1} = "E"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
177 err.reason{end + 1} = "Structure configuration error"; |
10549 | 178 end_try_catch |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
179 endif |
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
180 |
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
181 elseif (ndims (cond) != ndims (expected) |
10549 | 182 || any (size (cond) != size (expected))) |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
183 err.index{end + 1} = "."; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
184 err.observed{end + 1} = ["O(" (sprintf ("%dx", size (cond)) (1:end-1)) ")"]; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
185 err.expected{end + 1} = ["E(" (sprintf ("%dx", size (expected)) (1:end-1)) ")"]; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
186 err.reason{end + 1} = "Dimensions don't match"; |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
187 |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
188 else |
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
189 if (nargin < 3) |
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
190 ## Without explicit tolerance, be more strict. |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
191 if (! strcmp (class (cond), class (expected))) |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
192 err.index{end + 1} = "()"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
193 err.observed{end + 1} = "O"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
194 err.expected{end + 1} = "E"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
195 err.reason{end + 1} = cstrcat("Class ", class (cond), " != ", class(expected)); |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
196 elseif (isnumeric (cond)) |
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
197 if (issparse (cond) != issparse (expected)) |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
198 err.index{end + 1} = "()"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
199 err.observed{end + 1} = "O"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
200 err.expected{end + 1} = "E"; |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
201 if (issparse (cond)) |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
202 err.reason{end + 1} = "sparse != non-sparse"; |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
203 else |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
204 err.reason{end + 1} = "non-sparse != sparse"; |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
205 endif |
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
206 elseif (iscomplex (cond) != iscomplex (expected)) |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
207 err.index{end + 1} = "()"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
208 err.observed{end + 1} = "O"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
209 err.expected{end + 1} = "E"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
210 if (iscomplex (cond)) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
211 err.reason{end + 1} = "complex != real"; |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
212 else |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
213 err.reason{end + 1} = "real != complex"; |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
214 endif |
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
215 endif |
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
216 endif |
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
217 endif |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
218 |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
219 if (isempty (err.index)) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
220 |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
221 ## Numeric. |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
222 A = cond; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
223 B = expected; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
224 |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
225 ## Check exceptional values. |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
226 erridx = find (isna (real (A)) != isna (real (B)) | isna (imag (A)) != isna (imag (B))); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
227 if (! isempty (erridx)) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
228 err.index (end + 1:end + length (erridx)) = construct_indeces (size (A), erridx); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
229 err.observed (end + 1:end + length (erridx)) = ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
230 strtrim (cellstr (num2str (A (erridx) (:)))); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
231 err.expected (end + 1:end + length (erridx)) = ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
232 strtrim (cellstr (num2str (B (erridx) (:)))); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
233 err.reason (end + 1:end + length (erridx)) = cellstr (repmat ("'NA' mismatch", length (erridx), 1)); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
234 endif |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
235 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
236 erridx = find (isnan (real (A)) != isnan (real (B)) | isnan (imag (A)) != isnan (imag (B))); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
237 if (! isempty (erridx)) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
238 err.index (end + 1:end + length (erridx)) = construct_indeces (size (A), erridx); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
239 err.observed (end + 1:end + length (erridx)) = ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
240 strtrim (cellstr (num2str (A (erridx) (:)))); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
241 err.expected (end + 1:end + length (erridx)) = ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
242 strtrim (cellstr (num2str (B (erridx) (:)))); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
243 err.reason (end + 1:end + length (erridx)) = cellstr (repmat ("'NaN' mismatch", length (erridx), 1)); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
244 endif |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
245 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
246 erridx = find (((isinf (real (A)) | isinf (real (B))) & real (A) != real (B)) | ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
247 ((isinf (imag (A)) | isinf (imag (B))) & imag (A) != imag (B))); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
248 if (! isempty (erridx)) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
249 err.index (end + 1:end + length (erridx)) = construct_indeces (size (A), erridx); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
250 err.observed (end + 1:end + length (erridx)) = ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
251 strtrim (cellstr (num2str (A (erridx) (:)))); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
252 err.expected (end + 1:end + length (erridx)) = ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
253 strtrim (cellstr (num2str (B (erridx) (:)))); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
254 err.reason (end + 1:end + length (erridx)) = cellstr (repmat ("'Inf' mismatch", length (erridx), 1)); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
255 endif |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
256 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
257 ## Check normal values. Replace all exceptional values by zero. |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
258 A_null_real = real (A); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
259 B_null_real = real (B); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
260 exclude = ! isfinite (A_null_real) & ! isfinite (B_null_real); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
261 A_null_real (exclude) = 0; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
262 B_null_real (exclude) = 0; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
263 A_null_imag = imag (A); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
264 B_null_imag = imag (B); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
265 exclude = ! isfinite (A_null_real) & ! isfinite (B_null_real); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
266 A_null_imag (exclude) = 0; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
267 B_null_imag (exclude) = 0; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
268 A_null = complex (A_null_real, A_null_imag); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
269 B_null = complex (B_null_real, B_null_imag); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
270 if (isscalar (tol)) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
271 mtol = ones (size (A)) * tol; |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
272 else |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
273 mtol = tol; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
274 endif |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
275 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
276 k = (mtol == 0 & isfinite (A_null) & isfinite (B_null)); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
277 erridx = find (A_null != B_null & k); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
278 if (! isempty (erridx)) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
279 err.index (end + 1:end + length (erridx)) = ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
280 construct_indeces (size (A), erridx); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
281 err.observed (end + 1:end + length (erridx)) = ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
282 strtrim (cellstr (num2str (A (erridx) (:)))); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
283 err.expected (end + 1:end + length (erridx)) = ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
284 strtrim (cellstr (num2str (B (erridx) (:)))); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
285 err.reason (end + 1:end + length (erridx)) = ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
286 strsplit (deblank (sprintf ("Abs err %g exceeds tol %g\n", ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
287 [(abs (A_null (erridx) - B_null (erridx))) (mtol (erridx))]')), "\n"); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
288 endif |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
289 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
290 k = (mtol > 0 & isfinite (A_null) & isfinite (B_null)); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
291 erridx = find (abs (A_null - B_null) > mtol & k); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
292 if (! isempty (erridx)) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
293 err.index (end + 1:end + length (erridx)) = ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
294 construct_indeces (size (A), erridx); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
295 err.observed (end + 1:end + length (erridx)) = ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
296 strtrim (cellstr (num2str (A (erridx) (:)))); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
297 err.expected (end + 1:end + length (erridx)) = ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
298 strtrim (cellstr (num2str (B (erridx) (:)))); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
299 err.reason (end + 1:end + length (erridx)) = ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
300 strsplit (deblank (sprintf ("Abs err %g exceeds tol %g\n", ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
301 [(abs (A_null (erridx) - B_null (erridx))) (mtol (erridx))]')), "\n"); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
302 endif |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
303 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
304 k = (mtol < 0); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
305 if (any (k)) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
306 AA = A_null (k); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
307 BB = B_null (k); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
308 abserr = max (abs (AA(BB == 0))); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
309 AA = AA(BB != 0); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
310 BB = BB(BB != 0); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
311 relerr = max (abs (AA - BB) ./ abs (BB)); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
312 maxerr = max ([abserr; relerr]); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
313 if (maxerr > abs (tol)) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
314 err.index{end + 1} = "()"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
315 err.observed{end + 1} = "O"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
316 err.expected{end + 1} = "E"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
317 err.reason{end + 1} = sprintf ("Max rel err %g exceeds tol %g", maxerr, abs (tol)); |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
318 endif |
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
319 endif |
5589 | 320 endif |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
321 |
5589 | 322 endif |
323 | |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
324 ## Print any errors |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
325 if (! isempty (err.index)) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
326 assert_error_occurred = 1; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
327 if (! isempty (errmsg)) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
328 errmsg = cstrcat (errmsg, "\n"); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
329 endif |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
330 errmsg = cstrcat (errmsg, pprint (in, err)); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
331 end |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
332 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
333 endif |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
334 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
335 if (assert_call_depth == 0) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
336 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
337 ## Remove from the variable space to indicate end of recursion |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
338 clear -v assert_call_depth; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
339 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
340 ## Last time through. If there were any errors on any pass, raise a flag. |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
341 if (assert_error_occurred) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
342 error ("%s", errmsg); |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
343 endif |
5589 | 344 |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
345 else |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
346 assert_call_depth--; |
5589 | 347 endif |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
348 |
5589 | 349 endfunction |
350 | |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
351 |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
352 ## empty input |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
353 %!assert ([]) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
354 %!assert (zeros (3,0), zeros (3,0)) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
355 %!error assert (zeros (3,0), zeros (0,2)) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
356 %!error assert (zeros (3,0), []) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
357 %!error <Dimensions don't match> assert (zeros (2,0,2), zeros (2,0)) |
5589 | 358 |
359 ## conditions | |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
360 %!assert (isempty ([])) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
361 %!assert (1) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
362 %!error assert (0) |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
363 %!assert (ones (3,1)) |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
364 %!assert (ones (1,3)) |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
365 %!assert (ones (3,4)) |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
366 %!error assert ([1,0,1]) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
367 %!error assert ([1;1;0]) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
368 %!error assert ([1,0;1,1]) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
369 |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
370 ## scalars |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
371 %!error assert (3, [3,3; 3,3]) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
372 %!error assert ([3,3; 3,3], 3) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
373 %!assert (3, 3) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
374 %!assert (3+eps, 3, eps) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
375 %!assert (3, 3+eps, eps) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
376 %!error assert (3+2*eps, 3, eps) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
377 %!error assert (3, 3+2*eps, eps) |
5589 | 378 |
379 ## vectors | |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
380 %!assert ([1,2,3],[1,2,3]); |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
381 %!assert ([1;2;3],[1;2;3]); |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
382 %!error assert ([2,2,3,3],[1,2,3,4]); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
383 %!error assert ([6;6;7;7],[5;6;7;8]); |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
384 %!error assert ([1,2,3],[1;2;3]); |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
385 %!error assert ([1,2],[1,2,3]); |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
386 %!error assert ([1;2;3],[1;2]); |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
387 %!assert ([1,2;3,4],[1,2;3,4]); |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
388 %!error assert ([1,4;3,4],[1,2;3,4]) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
389 %!error assert ([1,3;2,4;3,5],[1,2;3,4]) |
5589 | 390 |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
391 ## matrices |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
392 %!test |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
393 %! A = [1 2 3]'*[1,2]; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
394 %! assert (A,A); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
395 %! fail ("assert (A.*(A!=2),A)"); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
396 %! X = zeros (2,2,3); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
397 %! Y = X; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
398 %! Y (1,2,3) = 1; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
399 %! fail ("assert (X,Y)"); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
400 |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
401 ## must give a small tolerance for floating point errors on relative |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
402 %!assert (100+100*eps, 100, -2*eps) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
403 %!assert (100, 100+100*eps, -2*eps) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
404 %!error assert (100+300*eps, 100, -2*eps) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
405 %!error assert (100, 100+300*eps, -2*eps) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
406 %!error assert (3, [3,3]) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
407 %!error assert (3, 4) |
5589 | 408 |
7027 | 409 ## test relative vs. absolute tolerances |
410 %!test assert (0.1+eps, 0.1, 2*eps); # accept absolute | |
411 %!error assert (0.1+eps, 0.1, -2*eps); # fail relative | |
412 %!test assert (100+100*eps, 100, -2*eps); # accept relative | |
413 %!error assert (100+100*eps, 100, 2*eps); # fail absolute | |
414 | |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
415 ## exceptional values |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
416 %!assert ([NaN, NA, Inf, -Inf, 1+eps, eps], [NaN, NA, Inf, -Inf, 1, 0], eps) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
417 %!error assert (NaN, 1) |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
418 %!error assert ([NaN 1], [1 NaN]) |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
419 %!error assert (NA, 1) |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
420 %!error assert ([NA 1]', [1 NA]') |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
421 %!error assert ([(complex (NA, 1)) (complex (2, NA))], [(complex (NA, 2)) 2]) |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
422 %!error assert (-Inf, Inf) |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
423 %!error assert ([-Inf Inf], [Inf -Inf]) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
424 %!error assert (complex (Inf, 0.2), complex (-Inf, 0.2 + 2*eps), eps) |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
425 |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
426 ## strings |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
427 %!assert ("dog", "dog") |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
428 %!error assert ("dog", "cat") |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
429 %!error assert ("dog", 3) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
430 %!error assert (3, "dog") |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
431 %!error assert (cellstr ("dog"), "dog") |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
432 %!error assert (cell2struct ({"dog"; 3}, {"pet", "age"}, 1), "dog"); |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
433 |
5589 | 434 ## structures |
435 %!shared x,y | |
436 %! x.a = 1; x.b=[2, 2]; | |
437 %! y.a = 1; y.b=[2, 2]; | |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
438 %!assert (x, y) |
5589 | 439 %!test y.b=3; |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
440 %!error assert (x, y) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
441 %!error assert (3, x) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
442 %!error assert (x, 3) |
12882
724bb6b7e3d5
assert.m: Correctly compare empty structures.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
443 %!test |
724bb6b7e3d5
assert.m: Correctly compare empty structures.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
444 %! # Empty structures |
724bb6b7e3d5
assert.m: Correctly compare empty structures.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
445 %! x = resize (x, 0, 1); |
724bb6b7e3d5
assert.m: Correctly compare empty structures.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
446 %! y = resize (y, 0, 1); |
724bb6b7e3d5
assert.m: Correctly compare empty structures.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
447 %! assert (x, y); |
5589 | 448 |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
449 ## cell arrays |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
450 %!test |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
451 %! x = {[3], [1,2,3]; 100+100*eps, "dog"}; |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
452 %! y = x; |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
453 %! assert (x, y); |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
454 %! y = x; y(1,1) = [2]; |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
455 %! fail ("assert (x, y)"); |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
456 %! y = x; y(1,2) = [0, 2, 3]; |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
457 %! fail ("assert (x, y)"); |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
458 %! y = x; y(2,1) = 101; |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
459 %! fail ("assert (x, y)"); |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
460 %! y = x; y(2,2) = "cat"; |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
461 %! fail ("assert (x, y)"); |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
462 %! y = x; y(1,1) = [2]; y(1,2) = [0, 2, 3]; y(2,1) = 101; y(2,2) = "cat"; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
463 %! fail ("assert (x, y)"); |
12882
724bb6b7e3d5
assert.m: Correctly compare empty structures.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
464 |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
465 ## variable tolerance |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
466 %!test |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
467 %! x = [-40:0]; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
468 %! y1 = (10.^x).*(10.^x); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
469 %! y2 = 10.^(2*x); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
470 %! assert (y1, y2, eps (y1)); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
471 %! fail ("assert (y1, y2 + eps*1e-70, eps (y1))"); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
472 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
473 ## test input validation |
12882
724bb6b7e3d5
assert.m: Correctly compare empty structures.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
474 %!error assert |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
475 %!error assert (1,2,3,4) |
12882
724bb6b7e3d5
assert.m: Correctly compare empty structures.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
476 |
17258
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
477 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
478 ## Convert all indeces into tuple format |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
479 function cout = construct_indeces (matsize, erridx) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
480 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
481 cout = cell (numel (erridx), 1); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
482 tmp = cell (1, numel (matsize)); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
483 [tmp{:}] = ind2sub (matsize, erridx (:)); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
484 subs = [tmp{:}]; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
485 if (numel (matsize) == 2) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
486 subs = subs (:, matsize != 1); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
487 endif |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
488 for i = 1:numel (erridx) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
489 loc = sprintf ("%d,", subs(i,:)); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
490 cout{i} = ["(" loc(1:end-1) ")"]; |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
491 endfor |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
492 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
493 endfunction |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
494 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
495 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
496 ## Pretty print the various errors in a condensed tabular format. |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
497 function str = pprint (in, err) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
498 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
499 str = sprintf (cstrcat ("ASSERT errors for: assert ", in, "\n")); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
500 str = cstrcat (str, sprintf ("\n Location | Observed | Expected | Reason\n")); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
501 prespace = zeros (3); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
502 postspace = zeros (3); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
503 for i = 1:length (err.index) |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
504 len = length (err.index{i}); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
505 prespace (1) = floor ((10 - len) / 2); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
506 postspace (1) = 10 - len - prespace (1); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
507 len = length (err.observed{i}); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
508 prespace (2) = floor ((10 - len) / 2); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
509 postspace (2) = 10 - len - prespace (2); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
510 len = length (err.expected{i}); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
511 prespace (3) = floor ((10 - len) / 2); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
512 postspace (3) = 10 - len - prespace (3); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
513 str = cstrcat (str, sprintf ("%s %s %s %s %s %s %s %s %s %s\n", ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
514 repmat (' ', 1, prespace (1)), ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
515 err.index{i}, ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
516 repmat (' ', 1, postspace (1)), ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
517 repmat (' ', 1, prespace (2)), ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
518 err.observed{i}, ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
519 repmat (' ', 1, postspace (2)), ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
520 repmat (' ', 1, prespace (3)), ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
521 err.expected{i}, ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
522 repmat (' ', 1, postspace (3)), ... |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
523 err.reason{i})); |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
524 endfor |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
525 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
526 endfunction |