Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Testcase Input Formatting Validator Template
// Original file - https://pastebin.com/Vk8tczPu
#include <iostream>
#include <assert.h>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
using namespace std;
long long readInt(long long l,long long r,char endd){
long long x=0;
int cnt=0;
int fi=-1;
bool is_neg=false;
while(true){
char g=getchar();
if(g=='-'){
assert(fi==-1);
is_neg=true;
continue;
}
if('0'<=g && g<='9'){
x*=10;
x+=g-'0';
if(cnt==0){
fi=g-'0';
}
cnt++;
assert(fi!=0 || cnt==1);
assert(fi!=0 || is_neg==false);
assert(!(cnt>19 || ( cnt==19 && fi>1) ));
} else if(g==endd){
if(is_neg){
x= -x;
}
assert(l<=x && x<=r);
return x;
} else {
assert(false);
}
}
}
string readString(int l,int r,char endd){
string ret="";
int cnt=0;
while(true){
char g=getchar();
assert(g!=-1);
if(g==endd){
break;
}
cnt++;
ret+=g;
}
assert(l<=cnt && cnt<=r);
return ret;
}
long long readIntSp(long long l,long long r){
return readInt(l,r,' ');
}
long long readIntLn(long long l,long long r){
return readInt(l,r,'\n');
}
string readStringLn(int l,int r){
return readString(l,r,'\n');
}
string readStringSp(int l,int r){
return readString(l,r,' ');
}
int main()
{
int T=readIntLn(1,3); // Ensures that an integer in the range [1, 3] is inputted, and that there is a New Line (Ln) right after that. This needs Unix-style line endings (ie. \n instead of \r\n). So generate the test files on an Unix machine (eg. Linux, Mac).
while(T--)
{
int n=readIntSp(1,1000000); // Ensures that an integer in the range [1, 1000000] is inputted, and that there is a space (Sp) right after that.
int m=readIntSp(0,1000000);
int k=readIntLn(1,1000000);
for(int i=1;i<=m;i++)
{
int u=readIntSp(1, n);
int v=readIntLn(1, n);
}
}
assert(getchar()==-1); // Ensures that there are no extra characters at the end.
cerr<<"SUCCESS\n"; // You should see this on the http://campus.codechef.com/files/stderr/SUBMISSION_ID page, at the bottom.
}
@thepushkarp

This comment has been minimized.

Copy link
Owner Author

@thepushkarp thepushkarp commented Apr 22, 2020

This file is to validate that the input sequence is correctly generated according to the constraints in the test-case input files.

You should see this on the http://campus.codechef.com/files/stderr/SUBMISSION_ID page, at the bottom.

SUCCESS on all Test-cases tells that the sequence generated is correct.

Make sure that the validation is written as explicitly as possible so no edge case misses the pattern and everything is covered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.