Skip to content

brunomaletta/tgen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

201 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tgen

Testcase generation for random inputs.

MIT License C++17 Tests Documentation


🎯 Overview

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.


⚡ Quick examples

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.


⚖️ Why not testlib / jngen?

tgen works in a similar way as traditional generators, but has support for declarative generation, worst-case sampling, and many useful and powerful helpers.

📦 Instalation

Header-only. Download

wget https://raw.githubusercontent.com/brunomaletta/tgen/main/single_include/tgen.h

and include

#include "tgen.h"

🎲 Generation

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.


📚 Documentation

About

tgen is a C++ header for writing random testcase generators quickly and safely.

Resources

License

Stars

Watchers

Forks

Contributors