MATLAB Grader -- assessing functions

11 visualizzazioni (ultimi 30 giorni)
Nicole
Nicole il 31 Mag 2023
Modificato: Cris LaPierre il 31 Mag 2023
Reference Solution:
function results = drinking_age(x)
if x < 0
results = 'Invalid age'
end
if x >= 21
results = 'You are of drinking age'
else
results = 'You are not of drinking age'
end
end
Assessment:
% Run learner solution.
x = 1;
results = drinking_age(x);
% Run reference solution.
yReference = reference.drinking_age(x);
% Compare.
assessVariableEqual('results', yReference);
The assessment claims all is good : x=25 drinking_age(x)
When I change the >= to ==, the assessment says all is good
function results = drinking_age(x)
if x < 0
results = 'Invalid age'
end
if x == 21
results = 'You are of drinking age'
else
results = 'You are not of drinking age'
end
end

Risposta accettata

Cris LaPierre
Cris LaPierre il 31 Mag 2023
Perhaps you could explain what it is you think should be happening?
The value of x used to assess the learner solution is defined in your assessment test:
% Run learner solution.
x = 1; %<---------- Defined here
results = drinking_age(x);
% Run reference solution.
yReference = reference.drinking_age(x);
I assume the code 'x=25' has been added to the 'Code to call your function' field. Since functions must be called in order to run, this field just gives learners a way to test their function before submitting. It has nothing to do with assessing the function.
So, in your case, your assessment test is always checking the functions using x=1. Since 1 is much less than 21, it doesn't matter if you use >=21 or ==21. The else case is still the one that executes.
  4 Commenti
Nicole
Nicole il 31 Mag 2023
Cris -
Is there a way to assess more than 1 x?
I'd like to test -10 and 30, for example
Cris LaPierre
Cris LaPierre il 31 Mag 2023
Modificato: Cris LaPierre il 31 Mag 2023
There are 2 possible ways. First is to have the function written in such a way as to accept a vector as input, and return a corresponding output. The second is to test each input separately.
For the function you have shared, I think the easiest is to either create a separate assessment test for each case, or have a single assessment test all three:
% Test 1
x = 1;
results = drinking_age(x);
yReference = reference.drinking_age(x);
% Compare.
assessVariableEqual('results', yReference);
% Test 2
x = 10;
results = drinking_age(x);
yReference = reference.drinking_age(x);
% Compare.
assessVariableEqual('results', yReference);
% Test 3
x = 30;
results = drinking_age(x);
yReference = reference.drinking_age(x);
% Compare.
assessVariableEqual('results', yReference);
Ultimately, you are designing a learning experience for your students. What will work best for them? If you split this into 3 separate assessment tests, then you can give partial credit if they get some scenarios working but not others. You can also give more specific feedback related to each individual scenario.
If you put everything into a single test, it may look less intimidating to your learners, but can be harder to help them identify their mistake if they are incorrect.

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by