Files and random numbers.

Re: Files and random numbers.

por Richard Lobb -
Número de respuestas: 4

Well done on your input file switcheroo - very cunning.

I don't think I really understand what you're after with this random question. How does the student code get hold of the numbers A and B? If it's a pure 'write a program' question, they'd have to read them from a file or standard input.

I attach a question that seems to fulfil the above spec, but I'm at all sure if it's what you're after. Did you want each student to see different random numbers in their tests? That's possible, but it does complicate things and doesn't make the question any more robust against cheating - if one student copies another's code, it will still work in their variant.

I built the question without filling in the 'Expected' fields of the tests, ran the sample answer with Validate On Save on, and just clicked the buttons to copy the expected answers in.

I doubt it's what you want, but it's the starting point for a discussion.


En respuesta a Richard Lobb

Re: Files and random numbers.

por Alex Shpeht -
With your example, we realized that the meaning of tasks for the checking system is lost. It is easier to check the code "manually".

There is another question, although not on these topics.
If a large number of numbers are output, some of the numbers are skipped. Writes "...snip..." and continues the output sequence.

How to fix it?
En respuesta a Alex Shpeht

Re: Files and random numbers.

por Richard Lobb -
There has to be some form of limit on the output that's displayed in a cell of the result table. Too much output would flood the browser and and waste space in the database (since all output is recorded there for every run). Simply truncating the output can lose you important output at the end of the run, such as an exception being thrown. So I chose to snip the middle out of the output and mark it as '<...snip...>'. I also limit line lengths and the number of lines.

If you really want to do your own thing you can write a combinator template grader, which can generate whatever output it likes, although there is fundamentally a limit on the amount of output a run can generate, enforced by Jobe.

I suggest trying to find a way to pose a question in such a way that a correct solution doesn't generate screeds of output. What is the learning outcome of the question you're asking the student? Does it really need megabytes of output to verify that the learning outcome has been achieved?
En respuesta a Richard Lobb

Re: Files and random numbers.

por Albert Levi -
So what triggers to snip the output? I could not find information about this. If I know it, I can avoid having snip in the expected output.
En respuesta a Albert Levi

Re: Files and random numbers.

por Mike McDowell -
You could capture the output into a list then assess it with your test (this works per test in the test code), limiting the printed output:

# Capture stdout
import sys, io
old_stdout = sys.stdout
new_stdout = io.StringIO()
sys.stdout = new_stdout

# Now run the student methods/code while output is off

# Restore stdout when you're ready to allow output again
sys.stdout = old_stdout
output = new_stdout.getvalue()

# Split captured output into lines for analysis
lines = output.splitlines()

# Output the results or feedback from your examination of lines/output for your test