Testlib 的使用方法 翻译
下载地址 https://github.com/MikeMirzayanov/testlib/archive/0.9.12.zip
Testlib 库
Intro 简介
This project contains C++ implementation of the testlib. It already used on many programming contests in Russia (Russian National Olympiad in Informatics, different stages of ACM-ICPC). Join!
本项目包含了C++实现的testlib。testlib已经用于许多俄罗斯的程序竞赛中(比如Russian National Olympiad in Informatics,ACM的不同阶段),快来使用testlib吧!
The library C++ code is tested for compatibility with Borland C++ (5.6), Microsoft Visual C++ (2003+), g++ (MinGW 4.0.2). Also we don't hear any issues about incorrect work with other compilers.
testlib库已经过与 Borland C++ (5.6), Microsoft Visual C++ (2003+), g++ (MinGW 4.0.2). 的兼容性测试。而且我们没有听闻过testlib库任何与编译器的冲突问题。
This code used many times on Open Team Programming Collegiate Cup contests (http://opencup.ru/) running on Linux platform and compiled by g++ compiler.
Samples 使用范例
Checker SPJ判断
This is sample checker which expects in the output and in the answer the same integer. It ignores all white-spaces. See more examples in the package.
下面这个栗子需要输出一个和和答案文件中一样的
#include "testlib.h"
int main(int argc, char * argv[])
{
setName("compares two signed integers");
registerTestlibCmd(argc, argv);
int ja = ans.readInt();
int pa = ouf.readInt();
if (ja != pa)
quitf(_wa, "expected %d, found %d", ja, pa);
quitf(_ok, "answer is %d", ja);
}
Validator 判断HACK数据合法与否
This code reads input from the standard input and checks that it contains the only integer between 1 and 100, inclusive. Also validates that file ends with EOLN and EOF. On Windows it expects #13#10 as EOLN and it expects #10 as EOLN on other platforms. It doesn't ignore white-spaces, so it works very strict. It will return non-zero code in case of illegal input and writes message into the standard output. See more examples in the package.
这份代码从标准输入(stdin)中读入,检测输入的整数是否在
#include "testlib.h"
int main(int argc, char* argv[])
{
registerValidation(argc, argv);
inf.readInt(1, 100);
inf.readEoln();
inf.readEof();
}
Generator 发生器
This generator outputs into the standard output random token, containing Latin letters or digits. The length of the token will be between 1 and 1000, inclusive. It will use uniformly distributed random. To generate different values, call it with different command line parameters. It is typical behaviour of testlib generator to setup randseed by command line. See more examples in the package.
Generator通过标准输出(stdout)输出随机字符串或数字,字符串长度要小于
#include "testlib.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
registerGen(argc, argv, 1);
cout << rnd.next(1, 10) << endl; /* Random number in the range [1,10]. */
cout << rnd.next("[a-zA-Z0-9]{1,1000}") << endl; /* Random word of length [1,1000]. */
}