If you have written some tasks, and have prepared test cases, you will probably experience the terrible feeling that some test cases may be invalid (meaning it does not agree with the constraints in problem statement): upper bound can be violated, your graph not satisfied connectivity requirements or is not at tree. It is a reasonable to feel that way. Even experienced problem setters make mistakes sometimes (for example, in the pretigious ACM ICPC World final 2007).
The validator in testlib is a good tool to help you prevent such mistakes. It is very easy to use.
Example
Following is the validator of validator, which I used in a problem I prepared: 100541A - Stock Market:
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
int main() {
registerValidation();
int test = inf.readInt(1, 10);
inf.readEoln();
while (test--) {
int n = inf.readInt(1, 100);
inf.readChar(' ');
int w = inf.readInt(1, 1000000);
inf.readEoln();
for(int i = 0; i < n; ++i) {
inf.readInt(1, 1000);
if (i < n-1) inf.readChar(' ');
else inf.readEoln();
}
}
inf.readEof();
return 0;
}
More examples can be found at the Github repo
List of available methods:
Following is the methods available:
Method | What it does |
---|---|
registerValidation | this method must be called at the beginning of your code in order to use validator. |
readInt(L, R) | read an integer and check if it is in range [L, R]. Throw error if next token in input does not satisfy. |
readEof | read end of file. Throw error if end of file is not reached. |
readEoln | read end of line. Throw error if next character is not end of line. |
readChar(C) | read a character. |
[more content to be added]