comparison scripts/testfun/assert.m @ 17478:b8ecdb6ce2f8

assert.m: Speed up function by ~16% by not pre-calculating warning message. * scripts/testfun/assert.m: Don't pre-calculate "in" warning message since it is only used a small fraction of the time when there is an actual error.
author Rik <rik@octave.org>
date Mon, 23 Sep 2013 13:43:23 -0700
parents 7f27a3cbdb41
children fc4df284efc8
comparison
equal deleted inserted replaced
17477:a5c6591d01e6 17478:b8ecdb6ce2f8
67 67
68 if (call_depth == 0) 68 if (call_depth == 0)
69 errmsg = ""; 69 errmsg = "";
70 endif 70 endif
71 71
72 in = deblank (argn(1,:));
73 for i = 2:rows (argn)
74 in = [in "," deblank(argn(i,:))];
75 endfor
76 in = ["(" in ")"];
77
78 if (nargin == 1 || (nargin > 1 && islogical (cond) && ischar (varargin{1}))) 72 if (nargin == 1 || (nargin > 1 && islogical (cond) && ischar (varargin{1})))
79 if ((! isnumeric (cond) && ! islogical (cond)) || ! all (cond(:))) 73 if ((! isnumeric (cond) && ! islogical (cond)) || ! all (cond(:)))
80 call_depth--; 74 call_depth--;
81 if (nargin == 1) 75 if (nargin == 1)
82 ## Perhaps, say which elements failed? 76 ## Perhaps, say which elements failed?
83 error ("assert %s failed", in); 77 argin = ["(" strjoin(cellstr (argn), ",") ")"];
78 error ("assert %s failed", argin);
84 else 79 else
85 error (varargin{:}); 80 error (varargin{:});
86 endif 81 endif
87 endif 82 endif
88 else 83 else
361 356
362 endif 357 endif
363 358
364 ## Print any errors 359 ## Print any errors
365 if (! isempty (err.index)) 360 if (! isempty (err.index))
361 argin = ["(" strjoin(cellstr (argn), ",") ")"];
366 if (! isempty (errmsg)) 362 if (! isempty (errmsg))
367 errmsg = [errmsg "\n"]; 363 errmsg = [errmsg "\n"];
368 endif 364 endif
369 errmsg = [errmsg, pprint(in, err)]; 365 errmsg = [errmsg, pprint(argin, err)];
370 endif 366 endif
371 367
372 endif 368 endif
373 369
374 call_depth--; 370 call_depth--;
627 623
628 endfunction 624 endfunction
629 625
630 626
631 ## Pretty print the various errors in a condensed tabular format. 627 ## Pretty print the various errors in a condensed tabular format.
632 function str = pprint (in, err) 628 function str = pprint (argin, err)
633 629
634 str = ["ASSERT errors for: assert " in "\n"]; 630 str = ["ASSERT errors for: assert " argin "\n"];
635 str = [str, "\n Location | Observed | Expected | Reason\n"]; 631 str = [str, "\n Location | Observed | Expected | Reason\n"];
636 for i = 1:length (err.index) 632 for i = 1:length (err.index)
637 leni = length (err.index{i}); 633 leni = length (err.index{i});
638 leno = length (err.observed{i}); 634 leno = length (err.observed{i});
639 lene = length (err.expected{i}); 635 lene = length (err.expected{i});