vrassert.m

来自「Video IO toolbox for matlab. 用directsho」· M 代码 · 共 67 行

M
67
字号
function vrassert(varargin)%vrassert(testCondition)%   Evaluates the test condition in the caller's context.  If the result is%   false, an error is thrown indicating that the test failed.%   TESTCONDITION should be a string (Matlab 2007a has a real ASSERT operator,%   but many people don't have that version, so that's why we have this%   function).%%EXAMPLES:%   vrassert('1==2')      ==> assertion error generated%   x=1; vrassert('x==1') ==> no error%   vrassert(1==2)        ==> bad parameter error generated%   vrassert('{a==3')     ==> error generated by Matlab (bad vrassert code)%%by Gerald Dalleyfor i=1:nargin  if (~ischar(varargin{i}))    error('Type HELP ASSERT for usage');  endendtestCondition = join(' ', varargin);if (~evalin('caller', testCondition))  error(['ASSERT FAILED: ' testCondition]);end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function s = join(d,varargin)% This JOIN function is an inlined version of Gerald Dalley's one posted at the% Matlab Central website.  It is placed here as a convenience to users that% have not downloaded it.if (isempty(varargin)),  s = '';else  if (iscell(varargin{1}))    s = join(d, varargin{1}{:});  else    s = varargin{1};  end  for ss = 2:length(varargin)    s = [s d join(d, varargin{ss})]; %#ok<AGROW>  endend%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function test %#ok<DEFNU>% Copy-and-paste the below code into the command window to test this% function.clear all;worked = 0; try vrassert('1==2'); catch worked = 1; endif (~worked), error('Test failed'); endworked = 1; try x=1; vrassert('x==1'); catch worked = 0; endif (~worked), error('Test failed'); endworked = 0; try vrassert(1==2); catch worked = 1; endif (~worked), error('Test failed'); endworked = 0; try vrassert('{a==3'); catch worked = 1; endif (~worked), error('Test failed'); end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?