필터 지우기
필터 지우기

Can Functions Have a Built-In Self-Test?

조회 수: 1 (최근 30일)
Richard
Richard 2019년 7월 15일
편집: Adam Danz 2019년 7월 15일
Hi All
I'm trying to deterimine if there is a self-testing call or something for Matlab functions, similar to Octave's Self-Test Mode? It would be very helpful to be able to embed the tests into the function itself.
  댓글 수: 1
Adam Danz
Adam Danz 2019년 7월 15일
편집: Adam Danz 2019년 7월 15일
You can do something like this
function y = addStuff(x)
% adds everything in input 'x' (numeric)
% if 'x' is a string that equals 'test', it runs a self-test.
if ischar(x) && isequal('test',lower(x))
addStuff(1:99); % your test inputs
return
end
y = sum(x(:));
end

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by