Effacer les filtres
Effacer les filtres

assessFunctionPresence use in Matlab Grader for checking one out of n functions are present

2 vues (au cours des 30 derniers jours)
I am setting up a test in Matlab Grader to check that students use a for or a while loop in an exercise. They can only use one out of the two. The problem is that there is no way to set up an assessFunctionPresence test for this purpose. Is there any way around it?

Réponse acceptée

Cris LaPierre
Cris LaPierre le 29 Oct 2018
The MATLAB Code assessment type allows you to use any code you want to create an assessment. There are ways to achieve the result you want with assessFunctionPresence combined with assessFunctionAbsence, since it is the combination that is important. For example
try
assessFunctionPresence('while')
assessFunctionAbsence('for')
catch
assessFunctionPresence('for')
try
assessFunctionAbsence('while')
catch
assert(false,'You must use either a for loop or a while loop, but not both')
end
end
Any time a test evaluates false, you are bumped to the next level of the try/catch. If the solution contains both for and while loops, the assert statement will mark the answer false and give the student meaningful feedback on how to correct the code.

Plus de réponses (0)

Communautés

Plus de réponses dans  Distance Learning Community

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by