gen

package
Version: v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2020 License: MIT Imports: 11 Imported by: 18

Documentation

Overview

Package gen contains all commonly used generators and shrinkers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlphaChar

func AlphaChar() gopter.Gen

AlphaChar generates arbitrary character runes (upper- and lowercase)

func AlphaLowerChar

func AlphaLowerChar() gopter.Gen

AlphaLowerChar generates arbitrary lowercase alpha character runes

func AlphaNumChar

func AlphaNumChar() gopter.Gen

AlphaNumChar generates arbitrary alpha-numeric character runes

func AlphaString

func AlphaString() gopter.Gen

AlphaString generates an arbitrary string with letters

func AlphaUpperChar

func AlphaUpperChar() gopter.Gen

AlphaUpperChar generates arbitrary uppercase alpha character runes

func AnyString

func AnyString() gopter.Gen

AnyString generates an arbitrary string

func AnyTime

func AnyTime() gopter.Gen

AnyTime generates an arbitrary time.Time struct (might be way out of bounds of any reason)

func Bool

func Bool() gopter.Gen

Bool generates an arbitrary bool value

func Complex128

func Complex128() gopter.Gen

Complex128 generate arbitrary complex128 numbers

func Complex128Box

func Complex128Box(min, max complex128) gopter.Gen

Complex128Box generate complex128 numbers within a rectangle/box in the complex plane

func Complex128Shrinker

func Complex128Shrinker(v interface{}) gopter.Shrink

Complex128Shrinker is a shrinker for complex128 numbers

func Complex64

func Complex64() gopter.Gen

Complex64 generate arbitrary complex64 numbers

func Complex64Box

func Complex64Box(min, max complex64) gopter.Gen

Complex64Box generate complex64 numbers within a rectangle/box in the complex plane

func Complex64Shrinker

func Complex64Shrinker(v interface{}) gopter.Shrink

Complex64Shrinker is a shrinker for complex64 numbers

func Const

func Const(value interface{}) gopter.Gen

Const creates a generator for a constant value Not the most exciting generator, but can be helpful from time to time

func Fail

func Fail(resultType reflect.Type) gopter.Gen

Fail is a generator that always fails to generate a value Useful as fallback

func Float32

func Float32() gopter.Gen

Float32 generates arbitrary float32 numbers that do not contain NaN or Inf

func Float32Range

func Float32Range(min, max float32) gopter.Gen

Float32Range generates float32 numbers within a given range

func Float32Shrinker

func Float32Shrinker(v interface{}) gopter.Shrink

Float32Shrinker is a shrinker for float32 numbers

func Float64

func Float64() gopter.Gen

Float64 generates arbitrary float64 numbers that do not contain NaN or Inf

func Float64Range

func Float64Range(min, max float64) gopter.Gen

Float64Range generates float64 numbers within a given range

func Float64Shrinker

func Float64Shrinker(v interface{}) gopter.Shrink

Float64Shrinker is a shrinker for float64 numbers

func Frequency

func Frequency(weightedGens map[int]gopter.Gen) gopter.Gen

Frequency combines multiple weighted generators of the the same result type The generators from weightedGens will be used accrding to the weight, i.e. generators with a hight weight will be used more often than generators with a low weight.

func Identifier

func Identifier() gopter.Gen

Identifier generates an arbitrary identifier string Identitiers are supporsed to start with a lowercase letter and contain only letters and digits

func Int

func Int() gopter.Gen

Int generate arbitrary int numbers

func Int16

func Int16() gopter.Gen

Int16 generate arbitrary int16 numbers

func Int16Range

func Int16Range(min, max int16) gopter.Gen

Int16Range generates int16 numbers within a given range

func Int16Shrinker

func Int16Shrinker(v interface{}) gopter.Shrink

Int16Shrinker is a shrinker for int16 numbers

func Int32

func Int32() gopter.Gen

Int32 generate arbitrary int32 numbers

func Int32Range

func Int32Range(min, max int32) gopter.Gen

Int32Range generates int32 numbers within a given range

func Int32Shrinker

func Int32Shrinker(v interface{}) gopter.Shrink

Int32Shrinker is a shrinker for int32 numbers

func Int64

func Int64() gopter.Gen

Int64 generates an arbitrary int64 number

func Int64Range

func Int64Range(min, max int64) gopter.Gen

Int64Range generates int64 numbers within a given range

func Int64Shrinker

func Int64Shrinker(v interface{}) gopter.Shrink

Int64Shrinker is a shrinker for int64 numbers

func Int8

func Int8() gopter.Gen

Int8 generate arbitrary int8 numbers

func Int8Range

func Int8Range(min, max int8) gopter.Gen

Int8Range generates int8 numbers within a given range

func Int8Shrinker

func Int8Shrinker(v interface{}) gopter.Shrink

Int8Shrinker is a shrinker for int8 numbers

func IntRange

func IntRange(min, max int) gopter.Gen

IntRange generates int numbers within a given range

func IntShrinker

func IntShrinker(v interface{}) gopter.Shrink

IntShrinker is a shrinker for int numbers

func MapOf added in v0.2.1

func MapOf(keyGen, elementGen gopter.Gen) gopter.Gen

MapOf generates an arbitrary map of generated kay values. genParams.MaxSize sets an (exclusive) upper limit on the size of the map genParams.MinSize sets an (inclusive) lower limit on the size of the map

func MapShrinker added in v0.2.1

func MapShrinker(keyShrinker, elementShrinker gopter.Shrinker) gopter.Shrinker

MapShrinker creates a map shrinker from shrinker for the key values. The length of the map will be shrunk as well

func MapShrinkerOne added in v0.2.1

func MapShrinkerOne(keyShrinker, elementShrinker gopter.Shrinker) gopter.Shrinker

MapShrinkerOne creates a map shrinker from a shrinker for the key values of a map. The length of the map will remain (mostly) unchanged, instead each key value pair is shrunk after the other.

func NumChar

func NumChar() gopter.Gen

NumChar generates arbitrary numberic character runes

func NumString

func NumString() gopter.Gen

NumString generates an arbitrary string with digits

func OneConstOf

func OneConstOf(consts ...interface{}) gopter.Gen

OneConstOf generate one of a list of constant values

func OneGenOf

func OneGenOf(gens ...gopter.Gen) gopter.Gen

OneGenOf generate one value from a a list of generators

func PtrOf

func PtrOf(elementGen gopter.Gen) gopter.Gen

PtrOf generates either a pointer to a generated element or a nil pointer

func PtrShrinker

func PtrShrinker(elementShrinker gopter.Shrinker) gopter.Shrinker

PtrShrinker convert a value shrinker to a pointer to value shrinker

func RegexMatch

func RegexMatch(regexStr string) gopter.Gen

RegexMatch generates matches for a given regular expression regexStr is supposed to conform to the perl regular expression syntax

func RetryUntil

func RetryUntil(gen gopter.Gen, condition interface{}, maxRetries int) gopter.Gen

RetryUntil creates a generator that retries a given generator until a condition in met. condition: has to be a function with one parameter (matching the generated value of gen) returning a bool. Note: The new generator will only create an empty result once maxRetries is reached. Depending on the hit-ratio of the condition is may result in long running tests, use with care.

func Rune

func Rune() gopter.Gen

Rune generates an arbitrary character rune

func RuneNoControl

func RuneNoControl() gopter.Gen

RuneNoControl generates an arbitrary character rune that is not a control character

func RuneRange

func RuneRange(min, max rune) gopter.Gen

RuneRange generates runes within a given range

func Size

func Size() gopter.Gen

Size just extracts the MaxSize field of the GenParameters. This can be helpful to generate limited integer value in a more structued manner.

func Sized added in v0.2.5

func Sized(f func(int) gopter.Gen) gopter.Gen

Sized derives a generator from based on size This honors the `MinSize` and `MaxSize` of the `GenParameters` of the test suite. Keep an eye on memory consumption, by default MaxSize is 100.

func SliceOf

func SliceOf(elementGen gopter.Gen, typeOverrides ...reflect.Type) gopter.Gen

SliceOf generates an arbitrary slice of generated elements genParams.MaxSize sets an (exclusive) upper limit on the size of the slice genParams.MinSize sets an (inclusive) lower limit on the size of the slice

func SliceOfN

func SliceOfN(desiredlen int, elementGen gopter.Gen, typeOverrides ...reflect.Type) gopter.Gen

SliceOfN generates a slice of generated elements with definied length

func SliceShrinker

func SliceShrinker(elementShrinker gopter.Shrinker) gopter.Shrinker

SliceShrinker creates a slice shrinker from a shrinker for the elements of the slice. The length of the slice will be shrunk as well

func SliceShrinkerOne

func SliceShrinkerOne(elementShrinker gopter.Shrinker) gopter.Shrinker

SliceShrinkerOne creates a slice shrinker from a shrinker for the elements of the slice. The length of the slice will remains unchanged, instead each element is shrunk after the other.

func StringShrinker

func StringShrinker(v interface{}) gopter.Shrink

StringShrinker is a shrinker for strings. It is very similar to a slice shrinker just that the elements themselves will not be shrunk.

func Struct

func Struct(rt reflect.Type, gens map[string]gopter.Gen) gopter.Gen

Struct generates a given struct type. rt has to be the reflect type of the struct, gens contains a map of field generators. Note that the result types of the generators in gen have to match the type of the correspoinding field in the struct. Also note that only public fields of a struct can be generated

func StructPtr

func StructPtr(rt reflect.Type, gens map[string]gopter.Gen) gopter.Gen

StructPtr generates pointers to a given struct type. Note that StructPtr does not generate nil, if you want to include nil in your testing you should combine gen.PtrOf with gen.Struct. rt has to be the reflect type of the struct, gens contains a map of field generators. Note that the result types of the generators in gen have to match the type of the correspoinding field in the struct. Also note that only public fields of a struct can be generated

func Time

func Time() gopter.Gen

Time generates an arbitrary time.Time within year [0, 9999]

func TimeRange

func TimeRange(from time.Time, duration time.Duration) gopter.Gen

TimeRange generates an arbitrary time.Time with a range from defines the start of the time range duration defines the overall duration of the time range

func TimeShrinker

func TimeShrinker(v interface{}) gopter.Shrink

TimeShrinker is a shrinker for time.Time structs

func UInt

func UInt() gopter.Gen

UInt generate arbitrary uint numbers

func UInt16

func UInt16() gopter.Gen

UInt16 generate arbitrary uint16 numbers

func UInt16Range

func UInt16Range(min, max uint16) gopter.Gen

UInt16Range generates uint16 numbers within a given range

func UInt16Shrinker

func UInt16Shrinker(v interface{}) gopter.Shrink

UInt16Shrinker is a shrinker for uint16 numbers

func UInt32

func UInt32() gopter.Gen

UInt32 generate arbitrary int32 numbers

func UInt32Range

func UInt32Range(min, max uint32) gopter.Gen

UInt32Range generates uint32 numbers within a given range

func UInt32Shrinker

func UInt32Shrinker(v interface{}) gopter.Shrink

UInt32Shrinker is a shrinker for uint32 numbers

func UInt64

func UInt64() gopter.Gen

UInt64 generates an arbitrary Uint64 number

func UInt64Range

func UInt64Range(min, max uint64) gopter.Gen

UInt64Range generates uint64 numbers within a given range

func UInt64Shrinker

func UInt64Shrinker(v interface{}) gopter.Shrink

UInt64Shrinker is a shrinker for uint64 numbers

func UInt8

func UInt8() gopter.Gen

UInt8 generate arbitrary uint8 numbers

func UInt8Range

func UInt8Range(min, max uint8) gopter.Gen

UInt8Range generates uint8 numbers within a given range

func UInt8Shrinker

func UInt8Shrinker(v interface{}) gopter.Shrink

UInt8Shrinker is a shrinker for uint8 numbers

func UIntRange

func UIntRange(min, max uint) gopter.Gen

UIntRange generates uint numbers within a given range

func UIntShrinker

func UIntShrinker(v interface{}) gopter.Shrink

UIntShrinker is a shrinker for uint numbers

func UnicodeChar

func UnicodeChar(table *unicode.RangeTable) gopter.Gen

UnicodeChar generates arbitrary character runes with a given unicode table

func UnicodeString

func UnicodeString(table *unicode.RangeTable) gopter.Gen

UnicodeString generates an arbitrary string from a given unicode table.

func Weighted

func Weighted(weightedGens []WeightedGen) gopter.Gen

Weighted combines multiple generators, where each generator has a weight. The weight of a generator is proportional to the probability that the generator gets selected.

Types

type WeightedGen

type WeightedGen struct {
	Weight int
	Gen    gopter.Gen
}

WeightedGen adds a weight number to a generator. To be used as parameter to gen.Weighted

Jump to

Keyboard shortcuts

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