Skip to content

Latest commit

 

History

History
440 lines (372 loc) · 10.5 KB

Documentation.md

File metadata and controls

440 lines (372 loc) · 10.5 KB

Documentation



Wrapper

class Wrapper(func, *args, **kwargs)

Wrapper of a function.

It could be used to reduce repetition of calling a function with the same arguments.

Args:

  • func: The function needs to be wrapped.
  • *args: The positional arguments of func.
  • **kwargs: The keyword arguments of func.

Example:

>>> from pygentest import *
>>> f = Wrapper(randint, 1, 10)
>>> f()
3

>>> f()
6

List of methods:

  • __call__()

    Call the instance as the wrapped function.


Value generators

  1. randint(a, b)

    Get a random integer in inclusive range [a,b].

    In fact, it is alias for random.randint.

    Args:

    • a: Lowerbound of range.
    • b: Upperbound of range.

  2. randfloat(a, b)

    Get a random number in the range [a, b) or [a, b] depending on rounding.

    In fact, it is alias for random.uniform.

    Args:

    • a: Lowerbound of range.
    • b: Upperbound of range.

  3. randchar(chars)

    Get a random character from the given list of character.

    Args:

    • chars: List of character.

Sequence generators

  1. randlist_any(size, wrapgen, sorted=False, reverse=False)

    Get a random list of length size, with elements generated by wrapgen.

    Note: wrapgen must have type Wrapper.

    Args:

    • size: Length of list.
    • wrapgen: Wrapped generator for elements.
    • sorted: True if the returned list is sorted. Defaults to False.
    • reverse: True if the returned list is sorted in descending order. Defaults to False.

  2. randlist_uniqueint(size, a, b, sorted=False, reverse=False)

    Get a random list of unique integers in inclusive range [a,b].

    The algorithm used to implement this function is inspired by Knuth shuffle.

    Args:

    • size: Length of list.
    • a: Lower bound of the range.
    • b: Upper bound of the range.
    • sorted: True if the returned list is sorted. Defaults to False.
    • reverse: True if the returned list is sorted in descending order. Defaults to False.

  3. randmatrix_any(numrow, numcol, wrapgen)

    Get a random list of size numrow by numcol, with elements generated by wrapgen.

    Note: wrapgen must have type Wrapper.

    Args:

    • numrow: Number of rows.
    • numcol: Number of columns.
    • wrapgen: Wrapped generator for elements.

  4. randstring(length, chars)

    Get a random string of length length whose characters randomly chosen from chars.

    Args:

    • length: Length of string.
    • chars: List of characters.

  5. randlist_string(size, length, chars)

    Get a random list of size strings of length length with characters from chars.

    Args:

    • size: Length of list.
    • length: Length of each string.
    • chars: List of characters.

Graph generators

  1. randgraph(V, E, /, directed=False, loop=False, *, _1_indexed=True)

    Get edge list of a random graph with V vertices and E edges.

    An error will be raise if V is non-positive, or less

    Args:

    • V: Number of vertices.
    • E: Number of edges.
    • directed: True if graph is directed. Defaults to False.
    • loop: True if graph allows loop. Defaults to False.
    • _1_indexed: True if vertices are 1-indexed. Defaults to True.

  2. randlist_uniqueint(size, a, b, sorted=False, reverse=False)

    Get edge list of a random graph with V vertices, and the probability for each pair of vertices to be connected is p.

    Args:

    • V: Number of vertices.
    • p: Probability for each pair of vertices to be connected. Defaults to 0.5.
    • directed: True if graph is directed. Defaults to False.
    • loop: True if graph allows loop. Defaults to False.
    • _1_indexed: True if vertices are 1-indexed. Defaults to True.

  3. randmultigraph(V, E, /, loop=False, *, _1_indexed=True)

    Get edge list of a random multigraph with V vertices and E edges.

    Args:

    • V: Number of vertices.
    • E: Number of edges.
    • loop: True if graph allows loop. Defaults to False.
    • _1_indexed: True if vertices are 1-indexed. Defaults to True.

  4. randtree_rooted(V, *, _1_indexed=True)

    Get list of parent vertex of each vertex in a random rooted tree.

    The tree is rooted at vertex 1 if the verticed are 1-indexed, and 0, otherwise.

    Args:

    • V: Number of vertices.
    • _1_indexed: True if vertices are 1-indexed. Defaults to True.

  5. randtree(V, *, _1_indexed=True)

    Get edge list of a random tree with V vertices.

    This function is constructed based on randtree_rooted.

    Args:

    • V: Number of vertices.
    • _1_indexed: True if vertices are 1-indexed. Defaults to True.

  6. randgraph_connected(V, E, *, _1_indexed=True)

    Get edge list of a random connected undirected graph with V vertices and E edges.

    This function is constructed based on randtree.

    Args:

    • V: Number of vertices.
    • E: Number of edges.
    • _1_indexed: True if vertices are 1-indexed. Defaults to True.

  7. randDAG(V, E, /, connected=True, *, _1_indexed=True)

    Get edge list of a random directed acyclic graph with V vertices and E edges.

    This function is constructed based on randgraph and randgraph_connected.

    Args:

    • V: Number of vertices.
    • E: Number of edges.
    • connected: True if graph is (weakly) connected. Defaults to True.
    • _1_indexed: True if vertices are 1-indexed. Defaults to True.

Miscellaneous generators

  1. randperm(n, k)

    Get a random permutation of k number chosen from base set {1,2,...,n}

    Args:

    • n: Size of base set.
    • k: Size of permutation.

  2. randpartition_integer(n, k)

    Randomly partition positive integer n into k summands.

    Here is more information about integer partition.

    Args:

    • n: Partitioned number.
    • k: Number of summands.

  3. randpartition_set(baseset, k)

    Randomly partition baseset into k subsets.

    Here is more information about partition of a set.

    Args:

    • baseset: Base set.
    • k: Number of summands.

  4. randpolygon_lattice(n, minX, maxX, minY, maxY)

    Get a random convex lattice polygon with n vertices with the given bound for coordinates.

    A lattice polygon is a polygon whose every vertex has integer coordinates.

    Args:

    • n: Number of vertices.
    • minX: Lowerbound of x-coordinate.
    • maxX: Upperbound of x-coordinate.
    • minY: Lowerbound of y-coordinate.
    • maxY: Upperbound of y-coordinate.