cheran-senthil / PyRival

⚡ Competitive Programming Library
https://pyrival.readthedocs.io/
Apache License 2.0
1.17k stars 312 forks source link

Output Fails to Match even though it's Correct and Accepted when using CPH Judge and Competitive Companion Extension for VS Code #71

Closed shardul-rajhans closed 2 years ago

shardul-rajhans commented 2 years ago

Python Version: 3.8.3

Description

  1. Using the Master Sample Template, the CPH Judge extension for VS Code doesn't match the output, even though it's correct and accepted in CodeForces.
  2. I am sharing the Exact Code and the Problem Statement.
bjorn-martinsson commented 2 years ago
  1. What exactly is the difference in output?
  2. If you do not use pyrivals template, do you still get the same problem?
shardul-rajhans commented 2 years ago
  1. I have checked for trimmed spaces or everything but couldn't find any difference. To confirm this, I have checked the output values in a diff checker, it also matches everything perfectly fine.

  2. If I don't use pyrivals template, then the test cases are in Passed State.

Now, as we are modifying the sys.stdout, is the pyrivals template really compatible with the Competitive Companion Extension? I am adding the snapshots of the observations for better understanding. Even I can submit the code as it is and it gets accepted. But for me, it's bothering that the test cases are not passed with using the above extension. It will be better if you provide any suggestion or quick fix. Even, I will be more obliged if you recommend any other compatible extension with the template.

WithTemplateOutputDiff WithoutTemplate WithTemplate

bjorn-martinsson commented 2 years ago
  1. I have checked for trimmed spaces or everything but couldn't find any difference. To confirm this, I have checked the output values in a diff checker, it also matches everything perfectly fine.

This makes me suspect the issue is windows newlines vs linux newlines. Which operating system are you running? And can you check if that is the difference? Here is the Python 3 script that I normally use to detect windows newlines vs linux newlines in a file

import sys
print(sys.stdin.buffer.read())

Now, as we are modifying the sys.stdout, is the pyrivals template really compatible with the Competitive Companion Extension?

The template is just using os.write, which is what sys.stdout is using internally anyways. So that part of the template should not be able to cause any kind of incompabilities. That said, I don't know how the Competitive Companion Extension works. If anything this feels more like a bug on their side than ours.

shardul-rajhans commented 2 years ago
  1. I am using Windows 10 OS.
  2. I think the template is perfectly fine, but it's not matching the output in any case for any problem that's the problem. May be I need to find another way to match the output or use the normal print statements without overriding it. I checked that commenting the print and sys.stdout code worked for me as of now. Thanks for the help.
shardul-rajhans commented 2 years ago

However, if you can recommend a tool for Codeforces Contests solutions output matching in any of the editor, it will be helpful for me. Thanks.

cheran-senthil commented 2 years ago

It is not in our best interest to look or support other extensions since a good extension today will not be a good extension tomorrow.

I think the problem is just with Windows carriage line returns, and likely an issue with the extension handling this incorrectly.

bjorn-martinsson commented 2 years ago

I just wanted to add two final remarks.

  1. The template you have been using is a template made to run Python 3 code in Python 2. If you just want to code and run Python 3 code you should not use this template.

  2. If you still want to use to use this template, then the fix is to change

file.write(kwargs.pop("end", "\n"))

to

file.write(kwargs.pop("end", "\r\n"))