quick

Imports

Imports #

"flag"
"fmt"
"math"
"math/rand"
"reflect"
"strings"
"time"

Constants & Variables

complexSize const #

complexSize is the maximum length of arbitrary values that contain other values.

const complexSize = 50

defaultConfig var #

var defaultConfig Config

defaultMaxCount var #

var defaultMaxCount *int = *ast.CallExpr

Type Aliases

SetupError type #

A SetupError is the result of an error in the way that check is being used, independent of the functions being tested.

type SetupError string

Interfaces

Generator interface #

A Generator can generate random values of its own type.

type Generator interface {
Generate(rand *rand.Rand, size int) reflect.Value
}

Structs

CheckEqualError struct #

A CheckEqualError is the result [CheckEqual] finding an error.

type CheckEqualError struct {
CheckError
Out1 []any
Out2 []any
}

CheckError struct #

A CheckError is the result of Check finding an error.

type CheckError struct {
Count int
In []any
}

Config struct #

A Config structure contains options for running a test.

type Config struct {
MaxCount int
MaxCountScale float64
Rand *rand.Rand
Values func([]reflect.Value, *rand.Rand)
}

Functions

Check function #

Check looks for an input to f, any function that returns bool, such that f returns false. It calls f repeatedly, with arbitrary values for each argument. If f returns false on a given input, Check returns that input as a *[CheckError]. For example: func TestOddMultipleOfThree(t *testing.T) { f := func(x int) bool { y := OddMultipleOfThree(x) return y%2 == 1 && y%3 == 0 } if err := quick.Check(f, nil); err != nil { t.Error(err) } }

func Check(f any, config *Config) error

CheckEqual function #

CheckEqual looks for an input on which f and g return different results. It calls f and g repeatedly with arbitrary values for each argument. If f and g return different answers, CheckEqual returns a *[CheckEqualError] describing the input and the outputs.

func CheckEqual(f any, g any, config *Config) error

Error method #

func (s SetupError) Error() string

Error method #

func (s *CheckEqualError) Error() string

Error method #

func (s *CheckError) Error() string

Value function #

Value returns an arbitrary value of the given type. If the type implements the [Generator] interface, that will be used. Note: To create arbitrary values for structs, all the fields must be exported.

func Value(t reflect.Type, rand *rand.Rand) (value reflect.Value, ok bool)

arbitraryValues function #

arbitraryValues writes Values to args such that args contains Values suitable for calling f.

func arbitraryValues(args []reflect.Value, f reflect.Type, config *Config, rand *rand.Rand) (err error)

functionAndType function #

func functionAndType(f any) (v reflect.Value, t reflect.Type, ok bool)

getMaxCount method #

getMaxCount returns the maximum number of iterations to run for a given Config.

func (c *Config) getMaxCount() (maxCount int)

getRand method #

getRand returns the *rand.Rand to use for a given Config.

func (c *Config) getRand() *rand.Rand

randFloat32 function #

randFloat32 generates a random float taking the full range of a float32.

func randFloat32(rand *rand.Rand) float32

randFloat64 function #

randFloat64 generates a random float taking the full range of a float64.

func randFloat64(rand *rand.Rand) float64

randInt64 function #

randInt64 returns a random int64.

func randInt64(rand *rand.Rand) int64

sizedValue function #

sizedValue returns an arbitrary value of the given type. The size hint is used for shrinking as a function of indirection level so that recursive data structures will terminate.

func sizedValue(t reflect.Type, rand *rand.Rand, size int) (value reflect.Value, ok bool)

toInterfaces function #

func toInterfaces(values []reflect.Value) []any

toString function #

func toString(interfaces []any) string

Generated with Arrow