Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

[testlib] Validators

Revision en3, by I_love_Hoang_Yen, 2015-06-09 12:34:31

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]

Tags testlib, validator, validators, polygon

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
ru11 Russian KAN 2022-07-07 20:21:26 2128
en24 English KAN 2022-07-07 20:16:48 4201 Tiny change: 'alidation()` which d' -> 'alidation(argc, argv)` which d'
ru10 Russian KAN 2022-07-07 19:00:36 2066 added global methods
ru9 Russian KAN 2022-07-07 18:43:02 2171 updated functions
ru8 Russian MikeMirzayanov 2018-12-29 14:28:59 20 Мелкая правка: ' readLong(int L, int R)|Аналог' -> ' readLong(long long L, long long R)|Аналог'
ru7 Russian arsijo 2018-11-02 01:08:48 527
en23 English arsijo 2018-11-02 01:01:28 400
ru6 Russian Zlobober 2016-10-01 20:36:24 32
en22 English Zlobober 2016-02-24 02:54:05 32
en21 English I_love_Hoang_Yen 2015-06-18 14:09:58 20 Tiny change: ' readLong(int L, int R)|Same a' -> ' readLong(long long L, long long R)|Same a'
ru5 Russian riadwaw 2015-06-10 22:35:00 20
en20 English I_love_Hoang_Yen 2015-06-10 21:00:28 20
ru4 Russian MikeMirzayanov 2015-06-10 12:29:16 118
en19 English MikeMirzayanov 2015-06-10 12:27:46 410
en18 English PrinceOfPersia 2015-06-10 08:57:32 218
ru3 Russian MikeMirzayanov 2015-06-10 02:25:07 67
en17 English MikeMirzayanov 2015-06-10 02:24:34 67
ru2 Russian MikeMirzayanov 2015-06-10 02:20:24 3
ru1 Russian elena 2015-06-10 02:18:13 7940 Первая редакция перевода на Русский
en16 English elena 2015-06-10 01:13:44 30 Tiny change: 'inus sign), note that it will match '-0'.\n - *' -> 'inus sign).\n - *'
en15 English MikeMirzayanov 2015-06-09 17:33:29 1546
en14 English PrinceOfPersia 2015-06-09 17:16:10 56
en13 English I_love_Hoang_Yen 2015-06-09 14:08:48 125
en12 English I_love_Hoang_Yen 2015-06-09 14:06:24 246 Tiny change: '| Same as readChar(' ').|\n|void ' -> '| Same as `readChar(' ')`.|\n|void '
en11 English I_love_Hoang_Yen 2015-06-09 13:56:28 86 Update styling
en10 English I_love_Hoang_Yen 2015-06-09 13:53:23 1840 (published)
en9 English I_love_Hoang_Yen 2015-06-09 13:38:13 291
en8 English I_love_Hoang_Yen 2015-06-09 13:34:33 28 Tiny change: ' C/C++)|\n\n|readInt' -
en7 English I_love_Hoang_Yen 2015-06-09 13:01:14 3 Tiny change: 'readInt(), readIntege' -> 'readInt(),\nreadIntege'
en6 English I_love_Hoang_Yen 2015-06-09 12:54:26 2 Tiny change: ' in range [L, R].|\n|readS' -> ' in range $[L, R]$.|\n|readS'
en5 English I_love_Hoang_Yen 2015-06-09 12:54:01 60
en4 English I_love_Hoang_Yen 2015-06-09 12:52:57 1888
en3 English I_love_Hoang_Yen 2015-06-09 12:34:31 206
en2 English I_love_Hoang_Yen 2015-06-09 12:04:31 331
en1 English I_love_Hoang_Yen 2015-06-09 12:01:01 1478 Initial revision (saved to drafts)