Skip to content

Commit

Permalink
0.9.9
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMirzayanov committed May 5, 2015
1 parent aaf8633 commit 6be6702
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/read.me
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ Testlib is simple library which helps you to write
* checkers
* validators
* generators
* interactors
for programming competitions problems.
You can find latest release of the library on http://code.google.com/p/testlib/
Problem development management system Polygon completely supports testlib.

== How to use? ==
Easest way is to read c++ sources in the checkers/, validators/ and generators/ folders.
Easest way is to read c++ sources in the checkers/, validators/, generators/ and interactors/ folders.
Also some classes and methods in testlib have documentation.

Thanks for using testlib,
Expand Down
67 changes: 67 additions & 0 deletions generators/gen-bipartite-graph.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "testlib.h"

#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <climits>
#include <cassert>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <algorithm>

#define forn(i, n) for (int i = 0; i < int(n); i++)

using namespace std;

int main(int argc, char* argv[])
{
registerGen(argc, argv, 1);

int n = atoi(argv[1]);
int m = atoi(argv[2]);
size_t k = atoi(argv[3]);

int t = rnd.next(-2, 2);

set<pair<int,int> > edges;

while (edges.size() < k)
{
int a = rnd.wnext(n, t);
int b = rnd.wnext(m, t);
edges.insert(make_pair(a, b));
}

vector<pair<int,int> > e(edges.begin(), edges.end());
shuffle(e.begin(), e.end());

vector<int> pa(n);
for (int i = 0; i < n; i++)
pa[i] = i + 1;
shuffle(pa.begin(), pa.end());

vector<int> pb(m);
for (int i = 0; i < m; i++)
pb[i] = i + 1;
shuffle(pb.begin(), pb.end());

cout << n << " " << m << " " << e.size() << endl;

forn(i, e.size())
cout << pa[e[i].first] << " " << pb[e[i].second] << endl;

return 0;
}
60 changes: 60 additions & 0 deletions generators/gen-rooted-tree-graph.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "testlib.h"

#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <climits>
#include <cassert>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <algorithm>

#define forn(i, n) for (int i = 0; i < int(n); i++)

using namespace std;

int main(int argc, char* argv[])
{
registerGen(argc, argv);

int n = atoi(argv[1]);
int t = atoi(argv[2]);

vector<int> p(n);
forn(i, n)
if (i > 0)
p[i] = rnd.wnext(i, t);

printf("%d\n", n);
vector<int> perm(n);
forn(i, n)
perm[i] = i;
shuffle(perm.begin() + 1, perm.end());

vector<int> pp(n);
for (int i = 1; i < n; i++)
pp[perm[i]] = perm[p[i]];

for (int i = 1; i < n; i++)
{
printf("%d", pp[i] + 1);
if (i + 1 < n)
printf(" ");
}
printf("\n");

return 0;
}
60 changes: 60 additions & 0 deletions generators/gen-tree-graph.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "testlib.h"

#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <climits>
#include <cassert>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <algorithm>

#define forn(i, n) for (int i = 0; i < int(n); i++)

using namespace std;

int main(int argc, char* argv[])
{
registerGen(argc, argv, 1);

int n = atoi(argv[1]);
int t = atoi(argv[2]);

vector<int> p(n);
forn(i, n)
if (i > 0)
p[i] = rnd.wnext(i, t);

printf("%d\n", n);
vector<int> perm(n);
forn(i, n)
perm[i] = i;
shuffle(perm.begin() + 1, perm.end());
vector<pair<int,int> > edges;

for (int i = 1; i < n; i++)
if (rnd.next(2))
edges.push_back(make_pair(perm[i], perm[p[i]]));
else
edges.push_back(make_pair(perm[p[i]], perm[i]));

shuffle(edges.begin(), edges.end());

for (int i = 0; i + 1 < n; i++)
printf("%d %d\n", edges[i].first + 1, edges[i].second + 1);

return 0;
}
28 changes: 28 additions & 0 deletions interactors/interactor-a-plus-b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "testlib.h"
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
setName("Interactor A+B");
registerInteraction(argc, argv);

// reads number of queries from test (input) file
int n = inf.readInt();
for (int i = 0; i < n; i++)
{
// reads query from test (input) file
int a = inf.readInt();
int b = inf.readInt();

// writes query to the solution, endl makes flush
cout << a << " " << b << endl;

// writes output file to be verified by checker later
tout << ouf.readInt() << endl;
}

// just message
quitf(_ok, "%d queries processed", n);
}
5 changes: 3 additions & 2 deletions read.me
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ Testlib is simple library which helps you to write
* checkers
* validators
* generators
* interactors
for programming competitions problems.
You can find latest release of the library on http://code.google.com/p/testlib/
Problem development management system Polygon completely supports testlib.

== How to use? ==
Easest way is to read c++ sources in the checkers/, validators/ and generators/ folders.
Also classes and methods in testlib have documentation.
Easest way is to read c++ sources in the checkers/, validators/, generators/ and interactors/ folders.
Also some classes and methods in testlib have documentation.

Thanks for using testlib,
Mike Mirzayanov
Expand Down
4 changes: 2 additions & 2 deletions testlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
#define _TESTLIB_H_

/*
* Copyright (c) 2005-2014
* Copyright (c) 2005-2015
*/

#define VERSION "0.9.8-SNAPSHOT"
#define VERSION "0.9.9"

/*
* Mike Mirzayanov
Expand Down

0 comments on commit 6be6702

Please sign in to comment.