prologin / concours-site

Source code of the Prologin contest website
https://gitlab.com/prologin/concours/site
GNU General Public License v3.0
10 stars 6 forks source link

Please, ignore extrawhitespaces only at right when judging #318

Closed FranckCHAMBON closed 2 years ago

FranckCHAMBON commented 3 years ago

In function test_passes, strip is used at lines 64 and 72:

    stdout = force_text(test['stdout'], strings_only=False, errors='replace').strip()
#...
            stdout == reference.stdout.strip())

Instead of strip method, the rstrip is enough for the desired job, and it will let intact output like:

  #
 # #
# # #
 # #
  #

or rather more important an awaited output like

   1   1 1
     1 0 0 1
 +   1 0 1 1
------------
   1 0 1 0 0

Regards,

FranckCHAMBON commented 3 years ago

I read again the code of the function test_passes, and I think not only the last line should be right stripped, but all lines.

With this in mind, the last line of this function shouldn't be :

stdout == reference.stdout.strip())

but rather

import itertools
#...
all(line_reference.rstrip() == line_submitted.rstrip()
     for line_reference, line_submitted in
          itertools.zip_longuest(reference.stdout.split('\n'), stdout.split('\n'), fillvalue = '')

There is interest in rstrip all lines instead of only the last one. For example, this code will fail to pass test, but it should.

# code
for i in range(3):
    print(i * i, end= " ")
print("done!")

stdout

0 1 4
done!

Why ? There's an extra whitespace at the end of the first line. This extra whitespace should, imho, be stripped just like any ones at the end of a line. This will make easier code for beginners, and won't affect the meaning of a problem.

seirl commented 3 years ago

This issue was opened in the wrong repository, transferring to site/.

juli0z commented 2 years ago

Migrated to https://gitlab.com/prologin/concours/site/-/issues/318