assert.m

来自「Matlab程序」· M 代码 · 共 15 行

M
15
字号
function assert( callerStr, mssgStr )

if not(ischar(callerStr))
    error('assertion expression must be a string, since assert uses evalin')
end

assertionIsTrue = evalin( 'caller', callerStr );

if ( not(assertionIsTrue) ),
    
    if ( nargin == 1 ), mssgStr = ''; end
    
    disp(mssgStr)
    error( ['Assertion failed: ',callerStr] )
end

⌨️ 快捷键说明

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