Can Functions Have a Built-In Self-Test?

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 commentaire

Adam Danz
Adam Danz le 15 Juil 2019
Modifié(e) : Adam Danz le 15 Juil 2019
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

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur MATLAB Compiler dans Centre d'aide et File Exchange

Produits

Version

R2019a

Question posée :

le 15 Juil 2019

Modifié(e) :

le 15 Juil 2019

Community Treasure Hunt

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

Start Hunting!

Translated by