The following is assumed. I will also write the version at hand when creating the article.
You can run a test in the sample case with Ctrl + Shift + B
,
Create an environment where you can manually execute a test with Ctrl + Shift + T
.
I did the following. As one file for each question, throw it all under src.
work
│ cptest.bat
│ input.txt
│
├─.vscode
│ launch.json
│ settings.json
│ tasks.json
│
├─src
│ abc114_a.py
│
└─test
cptest.bat
cptest.bat
@echo off
set problemname=%1
set testdir=test\%problemname%
set baseurl=%problemname:~0,-2%
set baseurlreplaced=%baseurl:_=-%
rem # log in
oj login -u username -p password "https://atcoder.jp/"
oj login --check "https://atcoder.jp/"
rem # make test directory
if not exist %testdir% (
oj dl -d test/%problemname%/ https://atcoder.jp/contests/%baseurlreplaced%/tasks/%problemname%
)
oj test -c "python src/%problemname%.py" -d test/%problemname%/
It is a batch file that runs by giving one argument like cptest.bat abc114_a
.
In addition, conversion processing is forcibly inserted so that it works even with cptest.bat ddcc2020_qual_a
.
Change ʻusername and
password in the line of ʻoj login -u
appropriately before using.
On the last line, assuming that the python
command is in the path, it will slam and spit out the result to standard output.
input.txt
input.txt
(Write what you want to pass as standard input)
It is a text file used like python xxxxx.py <input.txt
.
Write the input you want to test on your own.
launch.json
launch.json
{
//You can use IntelliSense to learn the available attributes.
//Hover and display the description of existing attributes.
//Check the following for more information: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"args": [
"<",
"input.txt"
]
}
]
}
This is a configuration file for running the debugger with F5
.
The following is how to make:
You can open debug by opening the .py file and then suddenly pressing F5
.
You can prepare the launch.json
template by pressing" Add Configuration "on the screen below.
If you write around ʻargs` on the prepared template, it is completed.
tasks.json
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "test_atcorder_sample",
"group": {
"kind": "build",
"isDefault": true
},
"type": "shell",
"command": "${workspaceFolder}/cptest.bat",
"args": [
"${fileBasenameNoExtension}"
],
"problemMatcher": []
},
{
"label": "test_manual_input",
"group": {
"kind": "test",
"isDefault": true
},
"type": "shell",
"command": "python",
"args": [
"${file}",
"<",
"input.txt"
]
}
]
}
This is a configuration file for writing Ctrl + Shift + B
(build task) and Ctrl + Shift + T
(test task).
The following is how to make:
If you suddenly press Ctrl + Shift + B
after opening the .py file, the following screen will appear and you can prepare a template for tasks.json
.
It is completed by editing the prepared template.
abc114_a.py
abc114_a.py
def main():
x = int(input())
ans = "NO"
if (x == 7 or x == 5 or x == 3):
ans = "YES"
print(ans)
if __name__ == '__main__':
main()
Be careful with the file name so that it is [contest name] _ [problem name] .py
.
In the above case, write the code to solve the A problem of ABC114.
Create a .py file with an appropriate file name under src according to the contest.
After making an answer, check the operation of the sample case with Ctrl + Shift + B
, and submit it as it is if you like.
If you notice a suspicious part, change ʻinput.txt as appropriate, check the operation with
F5or
Ctrl + Shift + T`, correct it and submit it.
Building a competitive professional environment with Visual Studio Code (Practice) --Qiita
Recommended Posts