フィルターのクリア

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 Center および File ExchangeGet 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