generator

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Eval

func Eval(expr parser.Expr, vars map[string]any) (any, bool)

Eval evaluates an expression against the given variable context.

func Shrink

func Shrink(
	input map[string]any,
	fields []*parser.Field,
	models map[string]*parser.Model,
	stillFails func(map[string]any) bool,
) map[string]any

Shrink attempts to find a minimal counterexample by shrinking each field in the input. The stillFails predicate re-executes against the real system to confirm the shrunk input still triggers the failure.

Types

type Generator

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

Generator produces random valid inputs from a contract and model definitions.

func New

func New(contract *parser.Contract, models []*parser.Model, seed uint64) *Generator

New creates a generator for the given contract and models with a reproducible seed.

func (*Generator) ContractInput

func (g *Generator) ContractInput() []*parser.Field

ContractInput returns the contract's input fields for use by the shrinking engine.

func (*Generator) GenerateInput

func (g *Generator) GenerateInput() (map[string]any, error)

GenerateInput produces one random valid input satisfying the contract's constraints. It uses rejection sampling: generate unconstrained values, then check constraints, retrying until valid. For the typical transfer spec this converges quickly.

func (*Generator) GenerateMatching

func (g *Generator) GenerateMatching(match func(map[string]any) bool) (map[string]any, error)

GenerateMatching generates an input satisfying both contract constraints and the given predicate. Uses rejection sampling.

func (*Generator) GenerateN

func (g *Generator) GenerateN(n int) ([]map[string]any, error)

GenerateN produces n random valid inputs.

Jump to

Keyboard shortcuts

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