Test generator

Правка en5, от rustam-cpp, 2024-03-14 17:21:58

Hello, CodeForces!

Information

I have written 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), where pattern is an array of given intervals or individual characters).
Code

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:

Example

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';
  }
}
Tests

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.

Lucky rounds and high rating to all, bye!

Теги test generator

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
ru10 Русский rustam-cpp 2024-03-14 17:56:58 22 Мелкая правка: 'in() {\n // gen' -> 'in() {\n srand(time(NULL));\n // gen'
en10 Английский rustam-cpp 2024-03-14 17:56:42 22 Tiny change: 'in() {\n // gen' -> 'in() {\n srand(time(NULL));\n // gen'
en9 Английский rustam-cpp 2024-03-14 17:31:34 2 Tiny change: 'generator in C++. It ' -> 'generator on C++. It '
en8 Английский rustam-cpp 2024-03-14 17:30:47 9 Tiny change: 'on**\n\nI have written a test ge' -> 'on**\n\nI wrote a test ge'
ru9 Русский rustam-cpp 2024-03-14 17:27:52 0 (опубликовано)
en7 Английский rustam-cpp 2024-03-14 17:27:34 0 (published)
en6 Английский rustam-cpp 2024-03-14 17:27:04 7
ru8 Русский rustam-cpp 2024-03-14 17:26:57 7
en5 Английский rustam-cpp 2024-03-14 17:21:58 1012
ru7 Русский rustam-cpp 2024-03-14 17:21:31 1011
en4 Английский rustam-cpp 2024-03-14 17:03:03 1751
en3 Английский rustam-cpp 2024-03-14 16:31:48 13 Tiny change: ' summary="Пример">\n\n~~~~' -> ' summary="Example">\n\n~~~~'
en2 Английский rustam-cpp 2024-03-14 16:29:54 914
en1 Английский rustam-cpp 2024-03-14 16:29:28 3377 Initial revision for English translation (saved to drafts)
ru6 Русский rustam-cpp 2024-03-14 16:26:59 182
ru5 Русский rustam-cpp 2024-03-14 16:21:36 353
ru4 Русский rustam-cpp 2024-03-14 16:11:38 824
ru3 Русский rustam-cpp 2024-03-14 16:06:11 1898 Мелкая правка: 'ью до $10^-3$) каждого' -> 'ью до $10^{-3}$) каждого'
ru2 Русский rustam-cpp 2024-03-14 15:52:01 83 Мелкая правка: '======\n\nЯ написал свой генератор тестов.\n\n**Всем' -> '======\n\n\n\n**Всем'
ru1 Русский rustam-cpp 2024-03-14 15:49:08 55 Первая редакция (сохранено в черновиках)