Jngen: generic library for generating testcases

Revision en1, by ifsmirnov, 2017-07-04 00:34:40

Two years ago I came up with an idea (Russian only) of making a generic library for creating testcases. Months have passed, thoughts circulated in my mind over and over, and finally I sculpted something in code. Far many things are yet not implemented, but I already frequently use ones which are.

Here it is: https://github.com/ifsmirnov/jngen. You can download the library itself (its single header jngen.h) here.

Jngen works with arrays, graphs and trees. It also can generate some strings and geometry and provides command-line options parser and cool SVG drawer. Here are some working examples.

cout << Array::id(10).shuffled().add1() << endl; // permutation of elements from 1 to 10

cout << Tree::random(100000, 20) << endl; // "long" tree with elongation 20

pair<string, string> test = rnds.antiHash({{mod1, base1}, {mod2, base2}}, "a-z", 10000); // should be self-describing :)

cout << rndg.convexPolygon(1000, 1e9) << endl;

cout << Graph::random(100000, 200000).connected() << endl;

cout << rndm.randomPrime(1e18, 1e18 - 10000000) << endl;

Almost all code is documented, there are some real-world examples.

Getting started is very easy. If you work with testlib.h and use in your generators only registerGen and rnd.next, replace #include "testlib.h" with #include "jngen.h" and you'll see no difference. Compilation will last a bit longer, but there is a workaround which makes it compile even faster than testlib.

I'll be happy if you try it and share your feelings and feedback. Everyone finds his code and interfaces perfect until shows them to the community.

Currently the library has much more "basic" things and primitives than "real content" – I mean there are more bricks than practical testcases. We're working on it: soon several "test suites" will be added, and you'll be able to create reasonable tests for your, say, LCA-like-queries problem, in several lines of code.

I'd like to thank zemen, Endagorion and Errichto for useful discussions and advice, Endagorion, GlebsHP and CherryTree for their libraries from which I could borrow code learn upon and MikeMirzayanov for testlib which was a massive source of inspiration on early stages.

Tags jngen, generators, testlib

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
ru2 Russian ifsmirnov 2017-07-04 00:36:28 3 Мелкая правка: 'od1, base1, mod2, base2}, "a-z", ' -> 'od1, base1}, {mod2, base2}}, "a-z", '
en1 English ifsmirnov 2017-07-04 00:34:40 2687 Initial revision for English translation
ru1 Russian ifsmirnov 2017-07-03 18:55:56 2662 Первая редакция (опубликовано)