-
Notifications
You must be signed in to change notification settings - Fork 1
Getting started
First, let's create a directory for your project. Navigate to wherever you want your contests folder to be, and create the folder:
$ mkdir contests
$ cd contests
This will be the root directory for your contests. Now, we'll initialize the project:
$ coman init
INIT coman repository
$ ls
Coman.toml src test
That's it—you're done setting up your workspace. The src
directory is where your code will go, and test
is for your tests.
Let's create a simple C++ program inside src
. You can name it whatever you want; in this example, we'll name it add.cpp
. Paste the following code into it:
#include <stdio.h>
int main() {
int x, y;
scanf("%d%d", &x, &y);
printf("%d\n", x + y);
return 0;
}
Now let's run it! coman can determine which file you've most recently edited, and it will run that one automagically:
$ coman
COMPILE add.cpp
RUN add.cpp
5 3
8
It works! The program asks the user to type in two numbers (I typed in 5 and 3), and it prints their sum.
To debug your solution, simply run coman debug
or coman d
:
$ coman d
COMPILE add.cpp
DEBUG add.cpp
GNU gdb (GDB) 8.3.1
... snip ...
Reading symbols from /home/jtai/contests/build/debug/add.cpp...
(gdb)
You can now debug your program interactively with gdb
.
We can add test cases inside the test
folder. Inside test
, create a folder with the same name as your source file, without the file extension. In this case, the folder should be named add
:
$ cd test
$ mkdir add
$ cd add
Inside here, you can create your test cases. For each test case, create an input file named xxx.in
and a corresponding expected output file named xxx.out
(where xxx
can be any name you choose). The input file is sent to the program's stdin, and the output file is expected to match (byte-for-byte) the program's stdout.
You can create as many test cases as you like. For example:
$ echo '5 8' > positive.in
$ echo '13' > positive.out
$ echo '3 -5' > negative.in
$ echo '-2' > negative.out
In this case, the positive
test case tests that the input 5 8
results in the program printing 13
. Likewise, the negative
test case makes sure that the input 3 -5
outputs -2
.
Let's try testing the program with coman test
or coman t
:
$ coman t
COMPILE add.cpp
TEST negative: pass 2.98 ms
TEST positive: pass 2.76 ms
All of our tests passed!
You can create solutions in any subfolder of src
. Test cases should be in the corresponding subfolder in test
. For example, if you have a solution src/foo/bar/baz.cpp
, then test cases should go in test/foo/bar/baz/
.
Here's what your directory tree should look like:
contests/
├── Coman.toml
├── build/
│ └── ...
├── src/
│ └── add.cpp
└── test/
└── add/
├── negative.in
├── negative.out
├── positive.in
└── positive.out
For troubleshooting tips, see Troubleshooting.