Assess Grader script-based assignment with multiple examples
Mostrar comentarios más antiguos
Hi,
I have an assignment on Grader, where students should write a bit of code that extracts the elements with odd incides of a certain vector vec.
The answer I'm looking for is something like:
odd_vec = vec(1:2:end) % This is the only line of code that I used as reference solution
I would like to test the solutions of the students with multiple examples:
vec = [0,1];
vec = [1,2,3,4,5];
Previously (in Cody), I was able to write a reference solution as shown above and then insert the example vectors in the separate tests as:
vec = [11 12 13 14 15 16 17 18];
run('solution');
assessVariableEqual('odd_vec',[11 13 15 17]);
However, this no longer works as I get the error that vec is not defined. Apparently, the reference solution is now the first bit of code that is being executed.
Is there any way I can create similar tests as in Cody, without having to create separate vectors (vec1, vec2, odd_vec1, odd_vec2) for every test?
Thanks in advance.
Best,
Stijn
4 comentarios
Aditya Jain
el 22 de En. de 2019
Editada: Aditya Jain
el 22 de En. de 2019
MATLAB Grader has changed the execution model where the reference solution is the first piece of code that runs. This is to make sure that students don't mess around with the reference solution.
Looking that the example you provided, it would be an ideal usecase for using functions rather than scripts.
Is there a reason you are opting for scripts instead of functions?
Stijn Nuiten
el 28 de En. de 2019
Brandon Armstrong
el 29 de En. de 2019
Editada: Brandon Armstrong
el 29 de En. de 2019
The approach you just suggest is a good one if you're not using functions yet. One thing I think you may be wanting is to keep a test case randomized or hidden so that the student does not simply hardcode the answer and his/her code must work on a vector of unknown length. The random number seed used for the reference and learner solution is the same, so you can add the following to your learner template
N = randi([10 100]); % Random length for a vector
vec = randi([0 10], 1, N) % random vector of length N
and lock the lines. vec will be the same in the learner and instructor solutions for use with assessVariableEqual. As you suggest, add 1 or 2 more examples if you want to give some easy tests as well.
What I like about the new execution model is that is it more transparent to the student. The script they write can be directly copied into MATLAB and will work the same way. That is all variables are created and exist for students to test their code on. This makes debugging easier for students.
Stijn Nuiten
el 30 de En. de 2019
Respuestas (0)
Comunidades de usuarios
Más respuestas en Distance Learning Community
Categorías
Más información sobre Holidays / Seasons en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!