Imports #
"flag"
"fmt"
"math"
"math/rand"
"reflect"
"strings"
"time"
"flag"
"fmt"
"math"
"math/rand"
"reflect"
"strings"
"time"
complexSize is the maximum length of arbitrary values that contain other values.
const complexSize = 50
var defaultConfig Config
var defaultMaxCount *int = *ast.CallExpr
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
A Generator can generate random values of its own type.
type Generator interface {
Generate(rand *rand.Rand, size int) reflect.Value
}
A CheckEqualError is the result [CheckEqual] finding an error.
type CheckEqualError struct {
CheckError
Out1 []any
Out2 []any
}
A CheckError is the result of Check finding an error.
type CheckError struct {
Count int
In []any
}
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)
}
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 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
func (s SetupError) Error() string
func (s *CheckEqualError) Error() string
func (s *CheckError) Error() string
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 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)
func functionAndType(f any) (v reflect.Value, t reflect.Type, ok bool)
getMaxCount returns the maximum number of iterations to run for a given Config.
func (c *Config) getMaxCount() (maxCount int)
getRand returns the *rand.Rand to use for a given Config.
func (c *Config) getRand() *rand.Rand
randFloat32 generates a random float taking the full range of a float32.
func randFloat32(rand *rand.Rand) float32
randFloat64 generates a random float taking the full range of a float64.
func randFloat64(rand *rand.Rand) float64
randInt64 returns a random int64.
func randInt64(rand *rand.Rand) int64
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)
func toInterfaces(values []reflect.Value) []any
func toString(interfaces []any) string
Generated with Arrow