exhaustigen

package
v0.0.0-...-dd06ff7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

exhaustigen implements a simple utility tool for exhaustive testing described by Alex Kladov on his blog: https://matklad.github.io//2021/11/07/generate-all-the-things.html This implementation is ported from a Rust implementation of the idea by the creator of Rust, Graydon Hoare: https://github.com/graydon/exhaustigen-rs/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenBoundBy

func GenBoundBy[T any](g *Gen, bound int, f func(*Gen) T) iter.Seq[T]

GenBoundBy generates a variable-length sequence (up to bound) of values produced by calling f(gen).

func GenBoundComb

func GenBoundComb(g *Gen, bound, n int) iter.Seq[int]

GenBoundComb generates variable-size (up to bound) combinations with replacement from n elements. Yields indices in [0, n).

func GenComb

func GenComb(g *Gen, n int) iter.Seq[int]

GenComb generates variable-size combinations with replacement from n elements. Yields indices in [0, n). Equivalent to GenBoundComb(g, n, n).

func GenElts

func GenElts(g *Gen, lenBound, eltBound int) iter.Seq[int]

GenElts generates variable-length sequences of bounded ints. Length <= lenBound, each element <= eltBound.

func GenFixedBy

func GenFixedBy[T any](g *Gen, fixed int, f func(*Gen) T) iter.Seq[T]

GenFixedBy generates a fixed-length sequence of values produced by calling f(gen).

func GenFixedComb

func GenFixedComb(g *Gen, fixed, n int) iter.Seq[int]

GenFixedComb generates fixed-size combinations with replacement from n elements. Yields indices in [0, n).

func GenPerm

func GenPerm(g *Gen, n int) iter.Seq[int]

GenPerm generates permutations of n elements. Yields indices in [0, n).

func GenSubset

func GenSubset(g *Gen, n int) iter.Seq[int]

GenSubset generates subsets of n elements. Yields indices of included elements.

Types

type Gen

type Gen struct {
	// contains filtered or unexported fields
}

Gen exhaustively enumerates all combinations of nondeterministic choices. It tracks variable-radix digit counters, incrementing like an odometer on each Done() call.

func (*Gen) Done

func (g *Gen) Done() bool

Done returns false while there are unexplored combinations. On each call, it advances the odometer. Call this in the head of a for loop.

func (*Gen) Flip

func (g *Gen) Flip() bool

Flip returns false, then true.

func (*Gen) Gen

func (g *Gen) Gen(bound int) int

Gen returns a value (eventually every value) between 0 and bound inclusive.

func (*Gen) Pick

func (g *Gen) Pick(n int) int

Pick returns an index (eventually every index) into a collection of size n.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL