quick

package
v0.0.0-...-90c9d3a Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2010 License: BSD-3-Clause, GooglePatentClause Imports: 7 Imported by: 0

Documentation

Overview

This package implements utility functions to help with black box testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(function interface{}, config *Config) (err os.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

func CheckEqual(f, g interface{}, config *Config) (err os.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

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: in order to create arbitrary values for structs, all the members must be public.

Types

type CheckEqualError

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

A CheckEqualError is the result CheckEqual finding an error.

func (*CheckEqualError) String

func (s *CheckEqualError) String() string

type CheckError

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

A CheckError is the result of Check finding an error.

func (*CheckError) String

func (s *CheckError) String() string

type Config

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 float
	// 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, Values is a function which generates a slice of arbitrary
	// Values that are congruent with the arguments to the function being
	// tested. Otherwise, Values is used to generate the values.
	Values func([]reflect.Value, *rand.Rand)
}

A Config structure contains options for running a test.

type Generator

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

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) String

func (s SetupError) String() string

Jump to

Keyboard shortcuts

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