The only codeforces helper library you'll ever need.
nodeforces is a library written in node that helps you compile and test your codeforces contest problems on the go.
$ nodeforces init 765A.cpp
$ nodeforces test 765A.cpp
And that's all you need to create and test your code.
- Parse problem sample input and output
- Source file generation with required template
- Compile and Execute code
- Debug lines parser
- Test your code against sample input and output
- Support for Java
javac
and C++g++
The package can be installed with node.js
npm
package manager. If you dont have nodejs
installed you can download it here
$ npm install -g nodeforces
Note: The -g
flag might require sudo
permisson.
The easiest way to get started is typing the below in your favorite shell
$ nodeforces --help
This outputs some useful information like
Usage: nodeforces [command]
Commands:
version
init|i [problem_name] This command initializes a codefile for you to start coding
test|t [problem_name] This command (compiles,) runs your code against sample test cases
Options:
-h, --help output usage information
-v, --version output the version number
$ nodeforces init 585C.java
File Created at /home/krishna/585C/585C.java. Get ready to start coding
The above command automatically creats a folder 585C
in your home
directory and adds the source file 585C.java
along with sample input and output files. You can change the directory to store and other options (see Advanced Usage)
See the extension .java
. That's what tells the module to compile your code using javac
. For specifying compiler options (see Advanced Usage)
Note: If you're using Java
make sure to write your main method inside Main class
that is not public (something like below)
585C.java
class Main {
public static void main(String[] args) {
// your code here.
}
}
$ nodeforces test 585C.java
The above command automatically compiles and tests your code against sample inputs and outputs. The output might look something like
$ nodeforces test 585C.java
Reporting Basic Test Results.
However there are still pretests and finaltests that we cant see :)
***Tests for 585C**
✓ Case: 1
1) Case: 2
1 passing (16ms)
1 failing
1) ***Tests for 585C** Case: 2:
Uncaught AssertionError: expected [] to deeply equal [ 'Impossible' ]
+ expected - actual
-[]
+[
+ "Impossible"
+]
The output format should be familiar to you if you've used Mocha before. It simply reports all the test results with expected output and your output.
Advanced users can create a .cfrc
file in their home
directory for specifying advanced options. The config should be a json
file that looks something like
{
"src": {
"dir": "/path/to/dir/to/store/problems",
"fileHeaderPath": "/path/to/file/header/to/include/in/your/source"
},
"compiler": {
"options": ["-std=c++11"]
}
}
When you need to log something to stdout for debugging purpose, all you need to do is test with the -d
flag. The -d
flag parses the lines starting with ~
and automatically shows them as the debug log. For instance,
888A.cpp
if (case == 1)
printf("~I am debug line\n");
Now running the below command produces something like,
$ nodeforces test 888A.cpp -d
DEBUG output for Case: 1
I am a debug line
***Tests for 585C**
✓ Case: 1
✓ Case: 2
2 passing (16ms)
- The project follows gitflow branching model.
- Branch off of
develop
into afeature/your_feature
branch. - Do a
npm run test
to make sure you're not breaking anything. - Send a
pull request
todevelop
branch with a meaningful description.