tgen
Loading...
Searching...
No Matches

List generator. More...

Inheritance diagram for tgen::list< T >:

Classes

struct  value
 List value. More...

Public Member Functions

 list (int size, T value_left, T value_right)
 Creates list generator defined by size and range of values.
 list (int size, std::set< T > values)
 Creates list generator defined by value set.
listfix (int idx, T val)
 Restricts generator s.t. value at index is fixed.
listequal (int idx_1, int idx_2)
 Restricts generator s.t. values at two indices are equal.
listequal (std::set< int > indices)
 Restricts generator s.t. all values in index set are equal.
listequal_range (int left, int right)
 Restricts generator s.t. all values at index range are equal.
listall_equal ()
 Restricts generator s.t. all values are equal.
listdifferent (std::set< int > indices)
 Restricts generator s.t. all values in index set are different.
listdifferent (int idx_1, int idx_2)
 Restricts generator s.t. values at two indices are different.
listdifferent_range (int left, int right)
 Restricts generator s.t. all values at index range are different.
listall_different ()
 Restricts generator s.t. all values are different.
value gen () const
 Generates a random value from the set of valid lists.
Public Member Functions inherited from tgen::gen_base< list< T > >
auto gen_list (int size, Args &&...args) const
 Generates a list of several generation calls.
auto gen_until (Pred predicate, int max_tries, Args &&...args) const
 Generates a random value from the valid set until a condition is met.
auto distinct (Args &&...args) const
 Creates distinct generator for current generator.

Detailed Description

template<typename T>
struct tgen::list< T >

List generator.

Defines a set of lists, subject to restrictions.

A uniformly random tgen::list::value from this set of lists (that satisfies the restrictions) can be generated with tgen::list::gen.

Definition at line 1190 of file tgen.h.

Constructor & Destructor Documentation

◆ list() [1/2]

template<typename T>
tgen::list< T >::list ( int size,
T value_left,
T value_right )
inline

Creates list generator defined by size and range of values.

Template Parameters
TIntegral type to be stored in the list.
Parameters
sizeSize of the list.
value_leftLeft endpoint of value range.
value_rightRight endpoint of value range.

Defines a generator of lists of length size with values in [value_left, value_right].

Examples

// Lists of 10 ints from 1 to 100.
auto seq_gen = tgen::list<int>(10, 1, 100);
List generator.
Definition tgen.h:1190

Definition at line 1205 of file tgen.h.

◆ list() [2/2]

template<typename T>
tgen::list< T >::list ( int size,
std::set< T > values )
inline

Creates list generator defined by value set.

Template Parameters
TIntegral type to be stored in the list.
Parameters
sizeSize of the list.
valuesValue set.

Defines a generator of lists of length size with values in values.

Examples

// Lists of 10 ints that are either 3, 6, or 9.
auto seq_gen = tgen::list<int>(10, {3, 6, 9});

Definition at line 1215 of file tgen.h.

Member Function Documentation

◆ all_different()

template<typename T>
list & tgen::list< T >::all_different ( )
inline

Restricts generator s.t. all values are different.

Equivalent to tgen::list::different({0, 1, ... size-1}).

Note
If you add this restriction, do not add another tgen::list::different restriction! Generation might fail otherwise.

Examples

// Lists of 5 different ints from 1 to 5.
auto seq_gen = tgen::list<int>(5, 1, 5).all_different();
list & all_different()
Restricts generator s.t. all values are different.
Definition tgen.h:1312

Definition at line 1312 of file tgen.h.

◆ all_equal()

template<typename T>
list & tgen::list< T >::all_equal ( )
inline

Restricts generator s.t. all values are equal.

Equivalent to tgen::list::equal({0, 1, ... size-1}).

Examples

// Lists of 5 equal ints from 1 to 5.
auto seq_gen = tgen::list<int>(5, 1, 5).all_equal();
list & all_equal()
Restricts generator s.t. all values are equal.
Definition tgen.h:1285

Definition at line 1285 of file tgen.h.

◆ different() [1/2]

template<typename T>
list & tgen::list< T >::different ( int idx_1,
int idx_2 )
inline

Restricts generator s.t. values at two indices are different.

Parameters
idx_1First index.
idx_2Second index.

Equivalent to tgen::list::different({idx_1, idx_2}).

Examples

// Lists of 10 ints from 1 to 5 with the first and last values different.
auto seq_gen = tgen::list<int>(10, 1, 5).different(0, 9);
list & different(std::set< int > indices)
Restricts generator s.t. all values in index set are different.
Definition tgen.h:1290

Definition at line 1297 of file tgen.h.

◆ different() [2/2]

template<typename T>
list & tgen::list< T >::different ( std::set< int > indices)
inline

Restricts generator s.t. all values in index set are different.

Parameters
indicesIndex set.
Note
Generation might fail if restrictions are considered to be too complex! The restrictions are considered too complex if the following condition does not hold. Consider the graph defined with vertices as the tgen::list::different sets added, and there is an edge between two vertices if they share an index. Note that you need to consider indices (directed or indirectly) connected by equality restrictions as being the same. This resulting graph must be a acyclic. Moreover, for every tree in this graph, all of its indices with a tgen::list::set operation must be covered by a single "different" restriction set.
Exceptions
std::runtime_errorif generation fails.

Examples

// Lists of 10 ints from 1 to 5 with the first half distinct.
auto seq_gen = tgen::list<int>(10, 1, 5).different({0, 1, 2, 3, 4});

Definition at line 1290 of file tgen.h.

◆ different_range()

template<typename T>
list & tgen::list< T >::different_range ( int left,
int right )
inline

Restricts generator s.t. all values at index range are different.

Parameters
leftLeft endpoint of index range (inclusive).
rightRight endpoint of index range (inclusive).

Equivalent to tgen::list::different({left, left+1, ... , right}).

Examples

// Lists of 10 ints from 1 to 5 with the first half all different.
auto seq_gen = tgen::list<int>(10, 1, 5).different_range(0, 4);
list & different_range(int left, int right)
Restricts generator s.t. all values at index range are different.
Definition tgen.h:1303

Definition at line 1303 of file tgen.h.

◆ equal() [1/2]

template<typename T>
list & tgen::list< T >::equal ( int idx_1,
int idx_2 )
inline

Restricts generator s.t. values at two indices are equal.

Parameters
idx_1First index.
idx_2Second index.

Equivalent to tgen::list::equal({idx_1, idx_2}).

Examples

// Lists of 10 ints from 1 to 5 that start and end with the same value.
auto seq_gen = tgen::list<int>(10, 1, 5).equal(0, 9);
list & equal(int idx_1, int idx_2)
Restricts generator s.t. values at two indices are equal.
Definition tgen.h:1253

Definition at line 1253 of file tgen.h.

◆ equal() [2/2]

template<typename T>
list & tgen::list< T >::equal ( std::set< int > indices)
inline

Restricts generator s.t. all values in index set are equal.

Parameters
indicesIndex set.

Examples

// Lists of 10 ints from 1 to 5 with the first half equal.
auto seq_gen = tgen::list<int>(10, 1, 5).equal({0, 1, 2, 3, 4});

Definition at line 1266 of file tgen.h.

◆ equal_range()

template<typename T>
list & tgen::list< T >::equal_range ( int left,
int right )
inline

Restricts generator s.t. all values at index range are equal.

Parameters
leftLeft endpoint of index range (inclusive).
rightRight endpoint of index range (inclusive).

Equivalent to tgen::list::equal({left, left+1, ... , right}).

Examples

// Lists of 10 ints from 1 to 5 with the first half all equal.
auto seq_gen = tgen::list<int>(10, 1, 5).equal_range(0, 4);
list & equal_range(int left, int right)
Restricts generator s.t. all values at index range are equal.
Definition tgen.h:1276

Definition at line 1276 of file tgen.h.

◆ fix()

template<typename T>
list & tgen::list< T >::fix ( int idx,
T val )
inline

Restricts generator s.t. value at index is fixed.

Parameters
idxIndex.
valValue.
Exceptions
std::runtime_errorif value is not in the value range/set.

Examples

// Lists of 10 ints from 1 to 5 that start with 1.
auto seq_gen = tgen::list<int>(10, 1, 5).fix(0, 1);
list & fix(int idx, T val)
Restricts generator s.t. value at index is fixed.
Definition tgen.h:1228

Definition at line 1228 of file tgen.h.

◆ gen()

template<typename T>
value tgen::list< T >::gen ( ) const
inline

Generates a random value from the set of valid lists.

Returns
A uniformly random tgen::list::value from the set of valid lists, given the added restrictions.
Exceptions
std::runtime_errorif there is no valid list satisfying all added restrictions, or if the added restrictions are considered to be too complex (see tgen::list::different).

Complexity

O(n log n).

Examples

// Generates and prints a random list of 5 ints from 1 to 5.
auto inst = tgen::list<int>(5, 1, 5).gen();
std::cout << inst << std::endl;
value gen() const
Generates a random value from the set of valid lists.
Definition tgen.h:1452

Definition at line 1452 of file tgen.h.


The documentation for this struct was generated from the following files:
  • /home/runner/work/tgen/tgen/single_include/tgen.h
  • list.dox