Go 语言

Go 语言教程 Go 语言环境安装 Go 语言结构 Go 语言基础语法 Go 语言数据类型 Go 语言变量 Go 语言常量 Go 语言运算符 Go 语言条件语句 Go 语言 if 语句 Go 语言 if...else 语句 Go 语言 if 语句嵌套 Go 语言 switch 语句 Go 语言 select 语句 Go 语言循环语句 Go 语言 for 循环 Go 语言循环嵌套 Go 语言 break 语句 Go 语言 continue 语句 Go 语言 goto 语句 Go 语言函数 Go 语言函数值传递值 Go 语言函数引用传递值 Go 语言函数作为值 Go 语言函数闭包 Go 语言函数方法 Go 语言变量作用域 Go 语言数组 Go 语言多维数组 Go 语言向函数传递数组 Go 语言指针 Go 语言指针数组 Go 语言指向指针的指针 Go 语言指针作为函数参数 Go 语言结构体 Go 语言切片(Slice) Go 语言范围(Range) Go 语言Map(集合) Go 语言递归函数 Go 语言类型转换 Go 语言接口 Go 错误处理 Go 语言开发工具Go 语言标准库

Go 语言标准库


package quick

import "testing/quick"

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

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

Package Files

quick.go

func Check Uses

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:

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 CheckEqual Uses

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 Uses

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 Uses

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

A CheckEqualError is the result CheckEqual finding an error.

func (*CheckEqualError) Error Uses

func (s *CheckEqualError) Error() string

type CheckError Uses

type CheckError struct {
    Count int
    In    []interface{}
}

A CheckError is the result of Check finding an error.

func (*CheckError) Error Uses

func (s *CheckError) Error() string

type Config Uses

type Config struct {
    // MaxCount sets the maximum number of iterations. If zero,
    // MaxCountScale is used.
    MaxCount int
    // MaxCountScale is a non-negative scale factor applied to the default
    // maximum. If zero, the default is unchanged.
    MaxCountScale float64
    // If non-nil, rand is a source of random numbers. Otherwise a default
    // pseudo-random source will be used.
    Rand *rand.Rand
    // If non-nil, the Values function generates a slice of arbitrary
    // reflect.Values that are congruent with the arguments to the function
    // being tested. Otherwise, the top-level Value function is used
    // to generate them.
    Values func([]reflect.Value, *rand.Rand)
}

A Config structure contains options for running a test.

type Generator Uses

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

A Generator can generate random values of its own type.

type SetupError Uses

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 Uses

func (s SetupError) Error() string