The program produces correct results when run on the local computer, but produces incorrect results when run on CodeRunner.

The program produces correct results when run on the local computer, but produces incorrect results when run on CodeRunner.

de moon moodle -
Número de respuestas: 8

Why did this code pass the test on my local machine, but fail on three test cases when submitted to Moodle CodeRunner? The test data is in this ZIP file.Is this the reason?

#include<cstdio>

using namespace std;

int m[10010][4];

int main(){

    int n,a,b,s=-1;

    scanf("%d",&n);

    for(int i=1;i<=n;i++){

    scanf("%d%d%d%d",&m[i][0],&m[i][1],&m[i][2],&m[i][3]);

    }

    scanf("%d%d",&a,&b);

    for(int i=n;i>0;i--){    

    if(m[i][0]<=a&&m[i][0]+m[i][2]>=a&&m[i][1]<=b&&m[i][1]+m[i][3]>=b){

    s=i;

    break;

    }}

printf("%d",s);

return 0;

}

https://coderunner.org.nz/pluginfile.php/1564/mod_forum/post/3041/testcase.zip

En respuesta a moon moodle

Re: The program produces correct results when run on the local computer, but produces incorrect results when run on CodeRunner.

de Richard Lobb -
Please export your question as an xml file and post it. Also, explain what results you expect to get (perhaps a screen shot on your local computer) and what you actually got (a CodeRunner screenshot).
En respuesta a Richard Lobb

Re: The program produces correct results when run on the local computer, but produces incorrect results when run on CodeRunner.

de moon moodle -

I've found out the reason for the error. When importing into Moodle, two rows of data were merged into one, causing the number at the end of the previous row to be combined with the number at the beginning of the next row into one single number. I checked the XML file, and the numbers in it are correct. I don't know why they got merged together when imported into Moodle. Is it because there is too much data? Look at the data in test case 3: 4234 7552 5848 4291 7722 7888 9249 738 became 4234 7552 5848 42917722 7888 9249 738.



https://coderunner.org.nz/pluginfile.php/1564/mod_forum/post/3043/1081.xml

En respuesta a moon moodle

Re: The program produces correct results when run on the local computer, but produces incorrect results when run on CodeRunner.

de Richard Lobb -

Thanks for the detailed report.

I can reproduce the issue, but can't explain it. I've put a breakpoint in the CodeRunner xml import function and it appears that those two lines of input data have already been run together in the parsed XML object that is passed into my function. 

I've inspected the XML file in detail, put it through a validator and looked for any weirdness. Deleting all the Chinese text and replacing it with 8-bit UTF-8 characters just seems to move the bug further forward. The error occurs around character 190k - 210k even as I delete earlier testcases.

My only theory at this point is that there's a bug in the Moodle XML parser when handling large XML files, but that seems rather improbable. I have imported XML files way larger than this - up to a hundred megabytes or more - although they were questions with large support files rather than very long <text> elements, as are used for the <stdin> field.

So I'm sorry, I don't have an explanation for this, though it does seem to be a bug. I do have one additional question that may be relevant, however - how were the xml files generated? Presumably not from a Moodle export?

In an earlier posting you talked about the difficulty of using large datafiles in Moodle. But these datasets aren't particularly large. I have a large archive of programming contest problems that often have much larger datasets of 10s or even 100s of megabytes (though the latter need special settings). Do you wish to report in more detail on the difficulty you were having with datafiles of, say, a few hundred kilobytes?

En respuesta a Richard Lobb

Re: The program produces correct results when run on the local computer, but produces incorrect results when run on CodeRunner.

de moon moodle -

This is an XML file ((fps-admin-1081-1081))that I exported from a problem set of an Online Judge (OJ) system . I then converted it into the XML format used by CodeRunner, namely this 1081.xml, and subsequently imported this XML file into Moodle.

https://coderunner.org.nz/pluginfile.php/1564/mod_forum/post/3045/fps-admin-1081-1081.xml

En respuesta a moon moodle

Re: The program produces correct results when run on the local computer, but produces incorrect results when run on CodeRunner.

de moon moodle -

I have these two files now, "1081 Export Error.xml" and "1081 Correct Format.xml". Why is it that when I import the file "1081 Correct Format.xml" into Moodle, there is no such problem? This file was created by first importing the "1081 Export Error.xml" into Moodle, then fixing the errors within Moodle, and finally exporting it again from Moodle.
https://coderunner.org.nz/pluginfile.php/1564/mod_forum/post/3046/1081%20Correct%20Format.xml
https://coderunner.org.nz/pluginfile.php/1564/mod_forum/post/3046/1081%20Export%20Error.xml

En respuesta a moon moodle

Re: The program produces correct results when run on the local computer, but produces incorrect results when run on CodeRunner.

de Richard Lobb -
Interesting, but again I have no explanation. Both still seem like valid xml to me, and still suggests there's a bug in the XML importer. If you're really keen to explore further, you could try "fixing" some of the differences in the error version, one by one. Candidates that strike me are:
  1. Very long lines. Your error version has lines up to 701 characters in length.
  2. Different representations of empty text elements (<text /> versus <text></text>).
  3. Different ordering of elements e.g. <answer> coming before the testcases rather than after.

On a different topic, are your Online Judge exports from DOMJudge? I have a question type that runs DOMJudge zips directly - just attach the zip as a support file. The question spec is made available as a link rather than appearing directly within the question, so it's all a big hack, but it's very convenient if you have a lot of such questions. 

En respuesta a Richard Lobb

Re: The program produces correct results when run on the local computer, but produces incorrect results when run on CodeRunner.

de moon moodle -
It might be the file encoding that is incorrect. I copied the entire content of the correctly formatted XML file and pasted it over the content of the incorrectly formatted file, and then imported it, but it still didn’t work. However, when I saved the correctly formatted XML file with a different file name and imported it into Moodle, it worked perfectly. So I guess it must be an encoding issue. But what would be the correct encoding?
En respuesta a Richard Lobb

Re: The program produces correct results when run on the local computer, but produces incorrect results when run on CodeRunner.

de moon moodle -
I have already solved this problem. It turns out that the line breaks in the XML file should use the Unix line break format, which is \n, instead of the Windows line break format \r\n. Thank you very much for your patient explanation! The OJ system I am using is a Chinese one called HUSTOJ. Also, I have a suggestion,The Moodle page has to load a lot of PHP, which makes it open slowly. If there are many and large test cases, it will be even slower. For Codrunner problems, can we not display the specific test data after submission and checking? Instead, can we just show whether each test case is passed? If someone wants to see the specific data, they can click a link to open it.