Testcase generation for random inputs.
tgen is a C++ header for writing random testcase generators quickly and safely.
Instead of manually coding ad-hoc generators, use powerful algorithmic machinery to guarantee simple, correct and uniform generation.
There is support for arrays, permutations, maths, and more.
tgen provides two complementary styles:
- Operations: sample and operate on data directly.
// Generates random prime in [1, 1e6]
std::cout << tgen::math::gen_prime(1, 1e6) << std::endl;- Generators: describe constraints and sample random instances.
// Generates 20 distincts two-digit numbers.
std::cout << tgen::sequence<int>(20, 10, 99).distinct().gen() << std::endl;No loops. No backtracking. No custom generator code.
tgen works in a similar way as traditional generators, but has support for declarative generation, worst-case sampling, and many useful and powerful helpers.
Header-only. Download
wget https://raw.githubusercontent.com/brunomaletta/tgen/main/single_include/tgen.hand include
#include "tgen.h"Similar to traditional generators, there is registration and opts (arguments).
int main(int argc, char** argv) {
tgen::register_gen(argc, argv);
int n = tgen::opt<int>("n");
std::cout << tgen::permutation(tgen::next(1, n)).gen().add_1() << std::endl;
}We can run with n=100 by calling ./gen -n 100.