vscode-leetcode icon indicating copy to clipboard operation
vscode-leetcode copied to clipboard

How can i debug my code

Open loisjee opened this issue 7 years ago • 6 comments

Hello! I want to know how can i debug my code after i finish my solution in vscode. can anybody help me

loisjee avatar Mar 29 '19 05:03 loisjee

Hi @SongJee,

Debug is not supported yet. If you want to debug your solution, you need to install related language extensions and write some code to wrap your solution.

jdneo avatar Mar 29 '19 06:03 jdneo

I dont think this is a concern of this extension though.....

littlebeandog avatar Mar 29 '19 09:03 littlebeandog

If you write your solution in cpp, you could take a look at the discussion in #241.

This feature is currently under early discussion, and is a concern of mine.

Vigilans avatar Mar 30 '19 04:03 Vigilans

Just wanted to add that my approach has been using the CodeRunner extension: https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner

I then add a call to the solution function, like so:

// Pre generated template
solution(...) {
    ...
}
// I add this line so running CodeRunner executes the function
solution()

Of course you can then add inputs to it:

a = 'foo'
b = 'bar'
solution(a, b)

Depending on the problem.

Luanf avatar Mar 31 '19 01:03 Luanf

You can write test cases by yourself. Here is mine.

if __name__ == "__main__":
    s = Solution()
    testcases = [
                 ("USA", True), 
                 ("leetcode", True),
                 ("Facebook", True),
                 ("HaWa", False),
                 ]
    for i, (inp, ans) in enumerate(testcases):
        print("Test case: ", i)
        print("answer:   ", s.detectCapitalUse(inp))
        print("expected: ", ans)
        print()

As @littlebeandog said, the test is not a concern for this extension. This should be closed.

BrambleXu avatar Mar 31 '19 11:03 BrambleXu

Thank you @All for providing the solutions.

I'm closing the issue for now, but the discussion is still open!

For anyone who has his own solution about debugging the code, please feel free to comment.

You can also add 👍 for your favorite solution, which could be a guide for those who need help.

jdneo avatar Mar 31 '19 11:03 jdneo