version: 1.10

package quick

import "testing/quick"

Overview

Package quick implements utility functions to help with black box testing.

The testing/quick package is frozen and is not accepting new features.

Index

Package files

quick.go

func Check

  1. func Check(f interface{}, config *Config) error

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:

  1. func TestOddMultipleOfThree(t *testing.T) {
  2. f := func(x int) bool {
  3. y := OddMultipleOfThree(x)
  4. return y%2 == 1 && y%3 == 0
  5. }
  6. if err := quick.Check(f, nil); err != nil {
  7. t.Error(err)
  8. }
  9. }

func CheckEqual

  1. func CheckEqual(f, g interface{}, 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 Value

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

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.

type CheckEqualError

  1. type CheckEqualError struct {
  2. CheckError
  3. Out1 []interface{}
  4. Out2 []interface{}
  5. }

A CheckEqualError is the result CheckEqual finding an error.

func (*CheckEqualError) Error

  1. func (s *CheckEqualError) Error() string

type CheckError

  1. type CheckError struct {
  2. Count int
  3. In []interface{}
  4. }

A CheckError is the result of Check finding an error.

func (*CheckError) Error

  1. func (s *CheckError) Error() string

type Config

  1. type Config struct {
  2. // MaxCount sets the maximum number of iterations.
  3. // If zero, MaxCountScale is used.
  4. MaxCount int
  5. // MaxCountScale is a non-negative scale factor applied to the
  6. // default maximum.
  7. // If zero, the default is unchanged.
  8. MaxCountScale float64
  9. // Rand specifies a source of random numbers.
  10. // If nil, a default pseudo-random source will be used.
  11. Rand *rand.Rand
  12. // Values specifies a function to generate a slice of
  13. // arbitrary reflect.Values that are congruent with the
  14. // arguments to the function being tested.
  15. // If nil, the top-level Value function is used to generate them.
  16. Values func([]reflect.Value, *rand.Rand)
  17. }

A Config structure contains options for running a test.

type Generator

  1. type Generator interface {
  2. // Generate returns a random instance of the type on which it is a
  3. // method using the size as a size hint.
  4. Generate(rand *rand.Rand, size int) reflect.Value
  5. }

A Generator can generate random values of its own type.

type SetupError

  1. type SetupError string

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

func (SetupError) Error

  1. func (s SetupError) Error() string