Hello, CodeForces!
Information
I wrote a test generator in C++. It is very simple, it contains 2 functions: "generate a random number between $$$a$$$ and $$$b$$$, so that this random number is a multiple of $$$k$$$" (function: genint(a, b, k, add)
, where add
is whether to "add" this number to the test) and "generate of a random string". There's something to be written here.
- Generates a string of random length between $$$a$$$ and $$$b$$$, so that it is a multiple of $$$k$$$.
- Consisting of the given characters. You can set characters in two ways: write the interval
("a-f", "x-z")
or a individual character("m", "o")
. (function:genstr(a, b, k, pattern, add)
, wherepattern
is an array of given intervals or individual characters).
Usage
Here is a problem: You are given a string length of $$$n (n \le 10^5)$$$. You need to find the percentage of content of each character that is in the string (your answer will be considered correct if its absolute or relative error won't exceed $$$10^{-5}$$$). Example input and output:
You need to process $$$t$$$ testcases
For us, the competitors, this task is very simple, but for the authors it's necessary to write such tests, in which there will be both border and normal cases. Writing it by hand is a bad option. Especially since $$$n \le 10^5$$$.
With my generator you can make good tests in a few lines:
const int mintestcases = 5;
const int maxtestcases = 8;
const int minlength = 10;
const int maxlength = 20;
for (int i = 0; i < 5; i++) { // generates 5 tests
string test = "";
int t = genint(mintestcases, maxtestcases, 1, true);
test += '\n';
for (int j = 0; j < t; j++) {
int n = genint(minlength, maxlength, 5, true);
test += '\n';
genstr(n, n, 1, {"a-z"}, true);
test += '\n';
}
}
To make large tests you should increase values: mintestcases
, maxtestcases
, minlength
, maxlength
. For pretests you can take 1-2 tests of each "size".
You can generate strings consisting of uppercase letters: genstr(10, 20, 5, {"A-D"}, true)
, result: DCABACCCABBBBDBD
.
You can also generate a string consisting of lowercase and uppercase letters: genstr(10, 20, 5, {"A-D", "a-d"}, true)
, result: DcaBaccCABBBBDBD
.
Conclusion
This generator is also good for stress testing. Generating tests in a task is usually not very difficult. Also it can be used for hacks. You can generate a "maximal" test very easily.