ccagml / leetcode-extension

Solved LeetCode problem in VS Code added some new features
https://marketplace.visualstudio.com/items?itemName=ccagml.vscode-leetcode-problem-rating
MIT License
253 stars 27 forks source link

测试case 本地显示和提交的不同 #268

Closed sgrtye closed 8 months ago

sgrtye commented 8 months ago

🐛 Bug Report(错误报告)

在[125. Valid Palindrome]中,最后一个test case的input是“ ”,也就是一个空格 但是使用case/allcase提交的时候 会将input提交成“” 也就是empty string。

To Reproduce(重现)

打开[125. Valid Palindrome],使用allcase提交。

Expected behavior(预期行为)

正确提交‘“ ”/n’

Extension Output(扩展输出)

{"messages":["Runtime Error"],"system_message":{"fid":125,"id":125,"qid":125,"sub_type":"test","accepted":false},"Error":["expected 's' to have 1 <= size <= 200000 but got 0","expected 's' to have 1 <= size <= 200000 but got 0"],"Your Input":["\"\"\n"],"Expected Answer":[""],"Stdout":[""]}

20231107170455

Your Environment

sgrtye commented 8 months ago

尝试了另外两题 也是会将testcase里的空格字符串替换成空字符串。

image 如图 所有的纯空格字符串都会被替换成空字符串 然后只提交其中一个。

ccagml commented 8 months ago

印象中有个什么题目的测试用例给的数据前面有空格, 所以在用例碰到字符前的空格全去掉了, 这样看来如果全是空的,反而不能去掉

sgrtye commented 8 months ago

@ccagml 但好像发现情况不只这一点。 在其他题的时候 使用debug按钮 自行输入testcase是可以正常工作的 但是125这道题如果是自己输入的testcase 那么好像command line arguments有错位的情况 直接报错了 哪怕我用的‘"race a car"\n’这个case 直接报错了。

20231109042331 如图,testString是‘“race',funcName是’a',paramTypes是’car"\n‘。

另外你说测试用例前面有多余空格的 有没有可能拉取的时候去空格 这样就算有问题 还可以手动在testcase里加入空格override自动拉取的testcase。

sgrtye commented 8 months ago

@ccagml 现在使用case提交到leetcode是正确的 但是debugger的parsing还是有问题。

在别的题中 testcase有没有leading space都可以正确判断。 但是125中必须在string之前还有一个空格 现在使用debug按钮提交默认testcase的话因为没有这个leading space,会直接报错。 但是使用上面debug按钮的提交 自行输入testcase并保证之前有空格的话就可以正确处理。

image

图中第一行是自行输入teatcase,因为加入了leading space,可以正常debug 第二行的是使用默认testcase的debug,会自动去掉开头的空格 导致报错。

ccagml commented 8 months ago

125.valid-palindrome.py \\"A\ man,\ a\ plan,\ a\ canal:\ Panama\\"\n isPalindrome string returnType 125 44221 我在Ubuntu22.04试了一下是这样子的,可以debug. 你说的这个是跟windows上的控制台有关吗?

sgrtye commented 8 months ago

@ccagml 在这个更新之前是没问题的 但是更新完之后就不行了 应该就是这次的更新造成的。 而且我试了一下 在MacOS上新版本是没有报错的。 我明天晚一点先查查问题出在哪里吧 找不到我再问你

sgrtye commented 8 months ago

@ccagml 我找到问题是在Windows系统下 testcase中的空格没有正确转义 Windows: '\"A man, a plan, a canal: Panama\"\n' 'isPalindrome' 'string' 'returnType' '125' '63314' MacOS:\\"A\ man,\ a\ plan,\ a\ canal:\ Panama\\"\n isPalindrome string returnType 125 59262

image

像这样 每个空格都会把testcase断开成独立的command line argument。现在这个情况不仅在125中出现 是在所有的testcase是string并包括空格的情况下出现 但在比如list中 添加额外的空格不会造成影响。

我只找到了testcase中间传递的代码 没有找到最后根据系统添加转义符的地方

ccagml commented 8 months ago

python的debug发起/leetcode-extension/src/debug/DoPy3.ts 在这里的vscode.debug.startDebugging 你这样看起来,像是vscode的debug不能在windows上正确处理字符串参数 '""' 变成' ""'的样子

ccagml commented 8 months ago

看着Windows上是要在字符串前面也加空格的样子

sgrtye commented 8 months ago

看起来是这样的 多谢修复了