Mercurial > hg > octave-lyh
annotate scripts/testfun/assert.m @ 17479:fc4df284efc8
assert.m: Replace repmat call with const*ones(...) for ~23% speed-up
* scripts/testfun/assert.m: Replace construction of vector mtol from repmat to
tol*ones(...).
author | Rik <rik@octave.org> |
---|---|
date | Mon, 23 Sep 2013 14:00:58 -0700 |
parents | b8ecdb6ce2f8 |
children |
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 |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
59 if (nargin == 0 || nargin > 3) |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
60 print_usage (); |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
61 endif |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
62 |
17261
e3870f594d8b
assert.m: Fix recursive calls.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17260
diff
changeset
|
63 persistent call_depth = -1; |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
64 persistent errmsg; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
65 |
17261
e3870f594d8b
assert.m: Fix recursive calls.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17260
diff
changeset
|
66 call_depth++; |
e3870f594d8b
assert.m: Fix recursive calls.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17260
diff
changeset
|
67 |
e3870f594d8b
assert.m: Fix recursive calls.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17260
diff
changeset
|
68 if (call_depth == 0) |
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
|
69 errmsg = ""; |
17314
09543e9c8f40
Use explicit form of end (endif, endfor, etc.) in core m-files.
Rik <rik@octave.org>
parents:
17263
diff
changeset
|
70 endif |
6494 | 71 |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
72 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
|
73 if ((! isnumeric (cond) && ! islogical (cond)) || ! all (cond(:))) |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
74 call_depth--; |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
75 if (nargin == 1) |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
76 ## Perhaps, say which elements failed? |
17478
b8ecdb6ce2f8
assert.m: Speed up function by ~16% by not pre-calculating warning message.
Rik <rik@octave.org>
parents:
17322
diff
changeset
|
77 argin = ["(" strjoin(cellstr (argn), ",") ")"]; |
b8ecdb6ce2f8
assert.m: Speed up function by ~16% by not pre-calculating warning message.
Rik <rik@octave.org>
parents:
17322
diff
changeset
|
78 error ("assert %s failed", argin); |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
79 else |
10549 | 80 error (varargin{:}); |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
81 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
82 endif |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
83 else |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
84 expected = varargin{1}; |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
85 if (nargin < 3) |
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
86 tol = 0; |
5589 | 87 else |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
88 tol = varargin{2}; |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
89 endif |
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
90 |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
91 ## Add to list as the errors accumulate. If empty at end then no errors. |
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
|
92 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
|
93 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
|
94 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
|
95 err.reason = {}; |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
96 |
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
97 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
|
98 if (! ischar (cond)) |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
99 err.index{end+1} = "."; |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
100 err.expected{end+1} = 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
|
101 if (isnumeric (cond)) |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
102 err.observed{end+1} = num2str (cond); |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
103 err.reason{end+1} = "Expected string, but observed number"; |
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
|
104 else |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
105 err.observed{end+1} = "O"; |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
106 err.reason{end+1} = ["Expected string, but observed " class(cond)]; |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
107 endif |
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
|
108 elseif (! strcmp (cond, expected)) |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
109 err.index{end+1} = "[]"; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
110 err.observed{end+1} = cond; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
111 err.expected{end+1} = expected; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
112 err.reason{end+1} = "Strings don't match"; |
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
|
113 endif |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
114 |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
115 elseif (iscell (expected)) |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
116 if (! iscell (cond)) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
117 err.index{end+1} = "."; |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
118 err.observed{end+1} = "O"; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
119 err.expected{end+1} = "E"; |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
120 err.reason{end+1} = ["Expected cell, but observed " class(cond)]; |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
121 elseif (ndims (cond) != ndims (expected) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
122 || any (size (cond) != size (expected))) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
123 err.index{end+1} = "."; |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
124 err.observed{end+1} = ["O(" sprintf("%dx", size(cond))(1:end-1) ")"]; |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
125 err.expected{end+1} = ["E(" sprintf("%dx", size(expected))(1:end-1) ")"]; |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
126 err.reason{end+1} = "Dimensions don't match"; |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
127 else |
10549 | 128 try |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
129 ## Recursively compare cell arrays |
10549 | 130 for i = 1:length (expected(:)) |
131 assert (cond{i}, expected{i}, tol); | |
132 endfor | |
133 catch | |
17261
e3870f594d8b
assert.m: Fix recursive calls.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17260
diff
changeset
|
134 err.index{end+1} = "{}"; |
e3870f594d8b
assert.m: Fix recursive calls.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17260
diff
changeset
|
135 err.observed{end+1} = "O"; |
e3870f594d8b
assert.m: Fix recursive calls.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17260
diff
changeset
|
136 err.expected{end+1} = "E"; |
e3870f594d8b
assert.m: Fix recursive calls.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17260
diff
changeset
|
137 err.reason{end+1} = "Cell configuration error"; |
10549 | 138 end_try_catch |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
139 endif |
5589 | 140 |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
141 elseif (isstruct (expected)) |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
142 if (! isstruct (cond)) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
143 err.index{end+1} = "."; |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
144 err.observed{end+1} = "O"; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
145 err.expected{end+1} = "E"; |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
146 err.reason{end+1} = ["Expected struct, but observed " class(cond)]; |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
147 elseif (ndims (cond) != ndims (expected) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
148 || any (size (cond) != size (expected)) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
149 || rows (fieldnames (cond)) != rows (fieldnames (expected))) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
150 |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
151 err.index{end+1} = "."; |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
152 err.observed{end+1} = ["O(" sprintf("%dx", size(cond))(1:end-1) ")"]; |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
153 err.expected{end+1} = ["E(" sprintf("%dx", size(expected))(1:end-1) ")"]; |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
154 err.reason{end+1} = "Structure sizes don't match"; |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
155 else |
10549 | 156 try |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
157 empty = isempty (cond); |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
158 normal = (numel (cond) == 1); |
10549 | 159 for [v, k] = cond |
160 if (! isfield (expected, k)) | |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
161 err.index{end+1} = "."; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
162 err.observed{end+1} = "O"; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
163 err.expected{end+1} = "E"; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
164 err.reason{end+1} = ["'" k "'" " is not an expected field"]; |
10549 | 165 endif |
166 if (empty) | |
12882
724bb6b7e3d5
assert.m: Correctly compare empty structures.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
167 v = {}; |
724bb6b7e3d5
assert.m: Correctly compare empty structures.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
168 elseif (normal) |
10549 | 169 v = {v}; |
170 else | |
171 v = v(:)'; | |
172 endif | |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
173 ## Recursively call assert for struct array values |
10549 | 174 assert (v, {expected.(k)}, tol); |
175 endfor | |
176 catch | |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
177 err.index{end+1} = "."; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
178 err.observed{end+1} = "O"; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
179 err.expected{end+1} = "E"; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
180 err.reason{end+1} = "Structure configuration error"; |
10549 | 181 end_try_catch |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
182 endif |
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
183 |
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
184 elseif (ndims (cond) != ndims (expected) |
10549 | 185 || any (size (cond) != size (expected))) |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
186 err.index{end+1} = "."; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
187 err.observed{end+1} = ["O(" sprintf("%dx", size(cond))(1:end-1) ")"]; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
188 err.expected{end+1} = ["E(" sprintf("%dx", size(expected))(1:end-1) ")"]; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
189 err.reason{end+1} = "Dimensions don't match"; |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
190 |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
191 else # Numeric comparison |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
192 if (nargin < 3) |
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
193 ## 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
|
194 if (! strcmp (class (cond), class (expected))) |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
195 err.index{end+1} = "()"; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
196 err.observed{end+1} = "O"; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
197 err.expected{end+1} = "E"; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
198 err.reason{end+1} = ["Class " class(cond) " != " class(expected)]; |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
199 elseif (isnumeric (cond)) |
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
200 if (issparse (cond) != issparse (expected)) |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
201 err.index{end+1} = "()"; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
202 err.observed{end+1} = "O"; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
203 err.expected{end+1} = "E"; |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
204 if (issparse (cond)) |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
205 err.reason{end+1} = "sparse != non-sparse"; |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
206 else |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
207 err.reason{end+1} = "non-sparse != sparse"; |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
208 endif |
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
209 elseif (iscomplex (cond) != iscomplex (expected)) |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
210 err.index{end+1} = "()"; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
211 err.observed{end+1} = "O"; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
212 err.expected{end+1} = "E"; |
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 if (iscomplex (cond)) |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
214 err.reason{end+1} = "complex != real"; |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
215 else |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
216 err.reason{end+1} = "real != complex"; |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
217 endif |
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
218 endif |
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
219 endif |
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
220 endif |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
221 |
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 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
|
223 |
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 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
|
225 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
|
226 |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
227 ## Check exceptional values. |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
228 errvec = ( isna (real (A)) != isna (real (B)) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
229 | isna (imag (A)) != isna (imag (B))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
230 erridx = find (errvec); |
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
|
231 if (! isempty (erridx)) |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
232 err.index(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
233 ind2tuple (size (A), erridx); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
234 err.observed(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
235 strtrim (cellstr (num2str (A(erridx) (:)))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
236 err.expected(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
237 strtrim (cellstr (num2str (B(erridx) (:)))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
238 err.reason(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
239 repmat ({"'NA' mismatch"}, length (erridx), 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
|
240 endif |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
241 errseen = errvec; |
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
|
242 |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
243 errvec = ( isnan (real (A)) != isnan (real (B)) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
244 | isnan (imag (A)) != isnan (imag (B))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
245 erridx = find (errvec & !errseen); |
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
|
246 if (! isempty (erridx)) |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
247 err.index(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
248 ind2tuple (size (A), erridx); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
249 err.observed(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
250 strtrim (cellstr (num2str (A(erridx) (:)))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
251 err.expected(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
252 strtrim (cellstr (num2str (B(erridx) (:)))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
253 err.reason(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
254 repmat ({"'NaN' mismatch"}, length (erridx), 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
|
255 endif |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
256 errseen |= errvec; |
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
|
257 |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
258 errvec = ((isinf (real (A)) | isinf (real (B))) ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
259 & (real (A) != real (B))) ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
260 | ((isinf (imag (A)) | isinf (imag (B))) ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
261 & (imag (A) != imag (B))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
262 erridx = find (errvec & !errseen); |
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
|
263 if (! isempty (erridx)) |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
264 err.index(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
265 ind2tuple (size (A), erridx); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
266 err.observed(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
267 strtrim (cellstr (num2str (A(erridx) (:)))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
268 err.expected(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
269 strtrim (cellstr (num2str (B(erridx) (:)))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
270 err.reason(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
271 repmat ({"'Inf' mismatch"}, length (erridx), 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
|
272 endif |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
273 errseen |= errvec; |
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
|
274 |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
275 ## Check normal values. |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
276 ## Replace exceptional values already checked above by zero. |
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
|
277 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
|
278 B_null_real = real (B); |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
279 exclude = errseen | ! isfinite (A_null_real) & ! isfinite (B_null_real); |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
280 A_null_real(exclude) = 0; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
281 B_null_real(exclude) = 0; |
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
|
282 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
|
283 B_null_imag = imag (B); |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
284 exclude = errseen | ! isfinite (A_null_imag) & ! isfinite (B_null_imag); |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
285 A_null_imag(exclude) = 0; |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
286 B_null_imag(exclude) = 0; |
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
|
287 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
|
288 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
|
289 if (isscalar (tol)) |
17479
fc4df284efc8
assert.m: Replace repmat call with const*ones(...) for ~23% speed-up
Rik <rik@octave.org>
parents:
17478
diff
changeset
|
290 mtol = tol * ones (size (A)); |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
291 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
|
292 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
|
293 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
|
294 |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
295 k = (mtol == 0); |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
296 erridx = find ((A_null != B_null) & 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
|
297 if (! isempty (erridx)) |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
298 err.index(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
299 ind2tuple (size (A), erridx); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
300 err.observed(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
301 strtrim (cellstr (num2str (A(erridx) (:)))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
302 err.expected(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
303 strtrim (cellstr (num2str (B(erridx) (:)))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
304 err.reason(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
305 ostrsplit (deblank (sprintf ("Abs err %.5g exceeds tol %.5g\n",... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
306 [abs(A_null(erridx) - B_null(erridx))(:) mtol(erridx)(:)]')), "\n"); |
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
|
307 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
|
308 |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
309 k = (mtol > 0); |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
310 erridx = find ((abs (A_null - B_null) > mtol) & 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
|
311 if (! isempty (erridx)) |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
312 err.index(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
313 ind2tuple (size (A), erridx); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
314 err.observed(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
315 strtrim (cellstr (num2str (A(erridx) (:)))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
316 err.expected(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
317 strtrim (cellstr (num2str (B(erridx) (:)))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
318 err.reason(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
319 ostrsplit (deblank (sprintf ("Abs err %.5g exceeds tol %.5g\n",... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
320 [abs(A_null(erridx) - B_null(erridx))(:) mtol(erridx)(:)]')), "\n"); |
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
|
321 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
|
322 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
323 k = (mtol < 0); |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
324 if (any (k(:))) |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
325 ## Test for absolute error where relative error can't be calculated. |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
326 erridx = find ((B_null == 0) & abs (A_null) > abs (mtol) & k); |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
327 if (! isempty (erridx)) |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
328 err.index(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
329 ind2tuple (size (A), erridx); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
330 err.observed(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
331 strtrim (cellstr (num2str (A(erridx) (:)))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
332 err.expected(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
333 strtrim (cellstr (num2str (B(erridx) (:)))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
334 err.reason(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
335 ostrsplit (deblank (sprintf ("Abs err %.5g exceeds tol %.5g\n", |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
336 [abs(A_null(erridx) - B_null(erridx)) -mtol(erridx)]')), "\n"); |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
337 endif |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
338 ## Test for relative error |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
339 Bdiv = Inf (size (B_null)); |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
340 Bdiv(k & (B_null != 0)) = B_null(k & (B_null != 0)); |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
341 relerr = abs ((A_null - B_null) ./ abs (Bdiv)); |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
342 erridx = find ((relerr > abs (mtol)) & k); |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
343 if (! isempty (erridx)) |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
344 err.index(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
345 ind2tuple (size (A), erridx); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
346 err.observed(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
347 strtrim (cellstr (num2str (A(erridx) (:)))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
348 err.expected(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
349 strtrim (cellstr (num2str (B(erridx) (:)))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
350 err.reason(end+1:end+length (erridx)) = ... |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
351 ostrsplit (deblank (sprintf ("Rel err %.5g exceeds tol %.5g\n", |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
352 [relerr(erridx)(:) -mtol(erridx)(:)]')), "\n"); |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
353 endif |
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
354 endif |
5589 | 355 endif |
9447
bb2ae2210e37
relax assert for exact matches
Jaroslav Hajek <highegg@gmail.com>
parents:
9313
diff
changeset
|
356 |
5589 | 357 endif |
358 | |
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
|
359 ## 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
|
360 if (! isempty (err.index)) |
17478
b8ecdb6ce2f8
assert.m: Speed up function by ~16% by not pre-calculating warning message.
Rik <rik@octave.org>
parents:
17322
diff
changeset
|
361 argin = ["(" strjoin(cellstr (argn), ",") ")"]; |
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
|
362 if (! isempty (errmsg)) |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
363 errmsg = [errmsg "\n"]; |
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
|
364 endif |
17478
b8ecdb6ce2f8
assert.m: Speed up function by ~16% by not pre-calculating warning message.
Rik <rik@octave.org>
parents:
17322
diff
changeset
|
365 errmsg = [errmsg, pprint(argin, err)]; |
17314
09543e9c8f40
Use explicit form of end (endif, endfor, etc.) in core m-files.
Rik <rik@octave.org>
parents:
17263
diff
changeset
|
366 endif |
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
|
367 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
368 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
|
369 |
17261
e3870f594d8b
assert.m: Fix recursive calls.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17260
diff
changeset
|
370 call_depth--; |
e3870f594d8b
assert.m: Fix recursive calls.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17260
diff
changeset
|
371 |
e3870f594d8b
assert.m: Fix recursive calls.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17260
diff
changeset
|
372 if (call_depth == -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
|
373 ## Last time through. If there were any errors on any pass, raise a flag. |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
374 if (! isempty (errmsg)) |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
375 error (errmsg); |
7770
c6a1a217ac3c
Compatibility fix for assert
David Bateman <dbateman@free.fr>
parents:
7703
diff
changeset
|
376 endif |
5589 | 377 endif |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
378 |
5589 | 379 endfunction |
380 | |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
381 |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
382 ## empty input |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
383 %!assert ([]) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
384 %!assert (zeros (3,0), zeros (3,0)) |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
385 %!error <O\(3x0\)\s+E\(0x2\)> assert (zeros (3,0), zeros (0,2)) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
386 %!error <Dimensions don't match> assert (zeros (3,0), []) |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
387 %!error <Dimensions don't match> assert (zeros (2,0,2), zeros (2,0)) |
5589 | 388 |
389 ## conditions | |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
390 %!assert (isempty ([])) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
391 %!assert (1) |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
392 %!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
|
393 %!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
|
394 %!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
|
395 %!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
|
396 %!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
|
397 %!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
|
398 %!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
|
399 |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
400 ## scalars |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
401 %!error <Dimensions don't match> assert (3, [3,3]) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
402 %!error <Dimensions don't match> assert (3, [3,3; 3,3]) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
403 %!error <Dimensions don't match> assert ([3,3; 3,3], 3) |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
404 %!assert (3, 3) |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
405 %!error <Abs err 1 exceeds tol> assert (3, 4) |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
406 %!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
|
407 %!assert (3, 3+eps, eps) |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
408 %!error <Abs err 4.4409e-16 exceeds tol> assert (3+2*eps, 3, eps) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
409 %!error <Abs err 4.4409e-16 exceeds tol> assert (3, 3+2*eps, eps) |
5589 | 410 |
411 ## vectors | |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
412 %!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
|
413 %!assert ([1;2;3],[1;2;3]); |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
414 %!error <Abs err 1 exceeds tol 0> assert ([2,2,3,3],[1,2,3,4]); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
415 %!error <Abs err 1 exceeds tol 0.5> assert ([2,2,3,3],[1,2,3,4],0.5); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
416 %!error <Rel err 1 exceeds tol 0.1> assert ([2,2,3,5],[1,2,3,4],-0.1); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
417 %!error <Abs err 1 exceeds tol 0> assert ([6;6;7;7],[5;6;7;8]); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
418 %!error <Abs err 1 exceeds tol 0.5> assert ([6;6;7;7],[5;6;7;8],0.5); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
419 %!error <Rel err .* exceeds tol 0.1> assert ([6;6;7;7],[5;6;7;8],-0.1); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
420 %!error <Dimensions don't match> assert ([1,2,3],[1;2;3]); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
421 %!error <Dimensions don't match> assert ([1,2],[1,2,3]); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
422 %!error <Dimensions don't match> assert ([1;2;3],[1;2]); |
5589 | 423 |
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
|
424 ## matrices |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
425 %!assert ([1,2;3,4],[1,2;3,4]); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
426 %!error <\(1,2\)\s+4\s+2> assert ([1,4;3,4],[1,2;3,4]) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
427 %!error <Dimensions don't match> assert ([1,3;2,4;3,5],[1,2;3,4]) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
428 %!test # 2-D matrix |
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
|
429 %! A = [1 2 3]'*[1,2]; |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
430 %! assert (A, A); |
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 %! fail ("assert (A.*(A!=2),A)"); |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
432 %!test # N-D matrix |
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
|
433 %! 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
|
434 %! Y = X; |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
435 %! Y(1,2,3) = 1.5; |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
436 %! fail ("assert (X,Y)", "\(1,2,3\).*Abs err 1.5 exceeds tol 0"); |
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
|
437 |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
438 ## 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
|
439 %!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
|
440 %!assert (100, 100+100*eps, -2*eps) |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
441 %!error <Rel err .* exceeds tol> assert (100+300*eps, 100, -2*eps) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
442 %!error <Rel err .* exceeds tol> assert (100, 100+300*eps, -2*eps) |
5589 | 443 |
7027 | 444 ## test relative vs. absolute tolerances |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
445 %!test assert (0.1+eps, 0.1, 2*eps); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
446 %!error <Rel err 2.2204e-15 exceeds tol> assert (0.1+eps, 0.1, -2*eps); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
447 %!test assert (100+100*eps, 100, -2*eps); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
448 %!error <Abs err 2.8422e-14 exceeds tol> assert (100+100*eps, 100, 2*eps); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
449 |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
450 ## Corner case of relative tolerance with 0 divider |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
451 %!error <Abs err 2 exceeds tol 0.1> assert (2, 0, -0.1) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
452 |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
453 ## Extra checking of inputs when tolerance unspecified. |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
454 %!error <Class single != double> assert (single (1), 1) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
455 %!error <Class uint8 != uint16> assert (uint8 (1), uint16 (1)) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
456 %!error <sparse != non-sparse> assert (sparse([1]), [1]) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
457 %!error <non-sparse != sparse> assert ([1], sparse([1])) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
458 %!error <complex != real> assert (1+i, 1) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
459 %!error <real != complex> assert (1, 1+i) |
7027 | 460 |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
461 ## exceptional values |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
462 %!assert ([NaN, NA, Inf, -Inf, 1+eps, eps], [NaN, NA, Inf, -Inf, 1, 0], eps) |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
463 |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
464 %!error <'NaN' mismatch> assert (NaN, 1) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
465 %!error <'NaN' mismatch> assert ([NaN 1], [1 NaN]) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
466 %!test |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
467 %! try |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
468 %! assert ([NaN 1], [1 NaN]); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
469 %! catch |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
470 %! errmsg = lasterr (); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
471 %! if (sum (errmsg () == "\n") != 4) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
472 %! error ("Too many errors reported for NaN assert"); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
473 %! elseif (strfind (errmsg, "NA")) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
474 %! error ("NA reported for NaN assert"); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
475 %! elseif (strfind (errmsg, "Abs err NaN exceeds tol 0")) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
476 %! error ("Abs err reported for NaN assert"); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
477 %! endif |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
478 %! end_try_catch |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
479 |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
480 %!error <'NA' mismatch> 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
|
481 %!error assert ([NA 1]', [1 NA]') |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
482 %!test |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
483 %! try |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
484 %! assert ([NA 1]', [1 NA]'); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
485 %! catch |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
486 %! errmsg = lasterr (); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
487 %! if (sum (errmsg () == "\n") != 4) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
488 %! error ("Too many errors reported for NA assert"); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
489 %! elseif (strfind (errmsg, "NaN")) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
490 %! error ("NaN reported for NA assert"); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
491 %! elseif (strfind (errmsg, "Abs err NA exceeds tol 0")) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
492 %! error ("Abs err reported for NA assert"); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
493 %! endif |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
494 %! end_try_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
|
495 %!error assert ([(complex (NA, 1)) (complex (2, NA))], [(complex (NA, 2)) 2]) |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
496 |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
497 %!error <'Inf' mismatch> assert (-Inf, Inf) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
498 %!error <'Inf' mismatch> assert ([-Inf Inf], [Inf -Inf]) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
499 %!test |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
500 %! try |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
501 %! assert (complex (Inf, 0.2), complex (-Inf, 0.2 + 2*eps), eps); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
502 %! catch |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
503 %! errmsg = lasterr (); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
504 %! if (sum (errmsg () == "\n") != 3) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
505 %! error ("Too many errors reported for Inf assert"); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
506 %! elseif (strfind (errmsg, "Abs err")) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
507 %! error ("Abs err reported for Inf assert"); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
508 %! endif |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
509 %! end_try_catch |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
510 %!error <Abs err> 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
|
511 |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
512 ## strings |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
513 %!assert ("dog", "dog") |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
514 %!error <Strings don't match> assert ("dog", "cat") |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
515 %!error <Expected string, but observed number> assert (3, "dog") |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
516 %!error <Class char != double> assert ("dog", [3 3 3]) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
517 %!error <Expected string, but observed cell> assert ({"dog"}, "dog") |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
518 %!error <Expected string, but observed struct> assert (struct ("dog", 3), "dog") |
5589 | 519 |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
520 ## cell arrays |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
521 %!error <Expected cell, but observed double> assert (1, {1}) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
522 %!error <Dimensions don't match> assert (cell (1,2,3), cell (3,2,1)) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
523 %!test |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
524 %! x = {{{1}}, 2}; # cell with multiple levels |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
525 %! y = x; |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
526 %! assert (x,y); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
527 %! y{1}{1}{1} = 3; |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
528 %! fail ("assert (x,y)", "Abs err 2 exceeds tol 0"); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
529 |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
530 %!test |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
531 %! 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
|
532 %! y = x; |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
533 %! assert (x, y); |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
534 %! 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
|
535 %! fail ("assert (x, y)"); |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
536 %! 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
|
537 %! fail ("assert (x, y)"); |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
538 %! 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
|
539 %! fail ("assert (x, y)"); |
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
540 %! 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
|
541 %! 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
|
542 %! 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
|
543 %! fail ("assert (x, y)"); |
12882
724bb6b7e3d5
assert.m: Correctly compare empty structures.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
544 |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
545 ## structures |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
546 %!error <Expected struct, but observed double> assert (1, struct ("a", 1)) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
547 %!error <Structure sizes don't match> |
17322
7f27a3cbdb41
Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents:
17314
diff
changeset
|
548 %! x(1,2,3).a = 1; |
7f27a3cbdb41
Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents:
17314
diff
changeset
|
549 %! y(1,2).a = 1; |
7f27a3cbdb41
Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents:
17314
diff
changeset
|
550 %! assert (x,y); |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
551 %!error <Structure sizes don't match> |
17322
7f27a3cbdb41
Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents:
17314
diff
changeset
|
552 %! x(1,2,3).a = 1; |
7f27a3cbdb41
Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents:
17314
diff
changeset
|
553 %! y(3,2,2).a = 1; |
7f27a3cbdb41
Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents:
17314
diff
changeset
|
554 %! assert (x,y); |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
555 %!error <Structure sizes don't match> |
17322
7f27a3cbdb41
Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents:
17314
diff
changeset
|
556 %! x.a = 1; |
7f27a3cbdb41
Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents:
17314
diff
changeset
|
557 %! x.b = 1; |
7f27a3cbdb41
Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents:
17314
diff
changeset
|
558 %! y.a = 1; |
7f27a3cbdb41
Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents:
17314
diff
changeset
|
559 %! assert (x,y); |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
560 %!error <'b' is not an expected field> |
17322
7f27a3cbdb41
Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents:
17314
diff
changeset
|
561 %! x.b = 1; |
7f27a3cbdb41
Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents:
17314
diff
changeset
|
562 %! y.a = 1; |
7f27a3cbdb41
Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents:
17314
diff
changeset
|
563 %! assert (x,y); |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
564 |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
565 %!test |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
566 %! x.a = 1; x.b=[2, 2]; |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
567 %! y.a = 1; y.b=[2, 2]; |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
568 %! assert (x, y); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
569 %! y.b=3; |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
570 %! fail ("assert (x, y)"); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
571 %! fail ("assert (3, x)"); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
572 %! fail ("assert (x, 3)"); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
573 %! ## Empty structures |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
574 %! x = resize (x, 0, 1); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
575 %! y = resize (y, 0, 1); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
576 %! assert (x, y); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
577 |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
578 ## vector of tolerances |
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
|
579 %!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
|
580 %! 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
|
581 %! 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
|
582 %! 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
|
583 %! 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
|
584 %! 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
|
585 |
17263
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
586 ## Multiple tolerances |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
587 %!test |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
588 %! x = [1 2; 3 4]; |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
589 %! y = [0 -1; 1 2]; |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
590 %! tol = [-0.1 0; -0.2 0.3]; |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
591 %! try |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
592 %! assert (x, y, tol); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
593 %! catch |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
594 %! errmsg = lasterr (); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
595 %! if (sum (errmsg () == "\n") != 6) |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
596 %! error ("Incorrect number of errors reported"); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
597 %! endif |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
598 %! assert (!isempty (regexp (errmsg, '\(1,2\).*Abs err 3 exceeds tol 0\>'))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
599 %! assert (!isempty (regexp (errmsg, '\(2,2\).*Abs err 2 exceeds tol 0.3'))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
600 %! assert (!isempty (regexp (errmsg, '\(1,1\).*Abs err 1 exceeds tol 0.1'))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
601 %! assert (!isempty (regexp (errmsg, '\(2,1\).*Rel err 2 exceeds tol 0.2'))); |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
602 %! end_try_catch |
a28c0d73e253
assert.m: Added many more %!tests for function. Fixed multiple bugs discovered.
Rik <rik@octave.org>
parents:
17261
diff
changeset
|
603 |
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
|
604 ## test input validation |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
605 %!error assert () |
14070
c2c18e2e7c9c
assert.m: Update documentation string, add %!tests for cell arrays.
Rik <octave@nomad.inbox5.com>
parents:
14038
diff
changeset
|
606 %!error assert (1,2,3,4) |
12882
724bb6b7e3d5
assert.m: Correctly compare empty structures.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
607 |
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
|
608 |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
609 ## Convert all error indices into tuple format |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
610 function cout = ind2tuple (matsize, erridx) |
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
|
611 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
612 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
|
613 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
|
614 [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
|
615 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
|
616 if (numel (matsize) == 2) |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
617 subs = subs(:, matsize != 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
|
618 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
|
619 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
|
620 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
|
621 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
|
622 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
|
623 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
624 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
|
625 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
626 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
627 ## Pretty print the various errors in a condensed tabular format. |
17478
b8ecdb6ce2f8
assert.m: Speed up function by ~16% by not pre-calculating warning message.
Rik <rik@octave.org>
parents:
17322
diff
changeset
|
628 function str = pprint (argin, err) |
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
|
629 |
17478
b8ecdb6ce2f8
assert.m: Speed up function by ~16% by not pre-calculating warning message.
Rik <rik@octave.org>
parents:
17322
diff
changeset
|
630 str = ["ASSERT errors for: assert " argin "\n"]; |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
631 str = [str, "\n Location | Observed | Expected | Reason\n"]; |
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
|
632 for i = 1:length (err.index) |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
633 leni = length (err.index{i}); |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
634 leno = length (err.observed{i}); |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
635 lene = length (err.expected{i}); |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
636 str = [str, sprintf("%*s%*s %*s%*s %*s%*s %s\n", |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
637 6+fix(leni/2), err.index{i} , 6-fix(leni/2), "", |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
638 6+fix(leno/2), err.observed{i}, 6-fix(leno/2), "", |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
639 6+fix(lene/2), err.expected{i}, 6-fix(lene/2), "", |
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
640 err.reason{i})]; |
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
|
641 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
|
642 |
afd235a206a2
Allow vector/matrix tolerance and improve error messages for assert.m script
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
17178
diff
changeset
|
643 endfunction |
17259
684ccccbc15d
assert.m: Add vector checking for relative errors.
Rik <rik@octave.org>
parents:
17258
diff
changeset
|
644 |