Documentation ¶
Index ¶
- func GenerateN[T any](g Gen[T], n uint) []T
- func Seed(seed int64)
- type Gen
- func Between[T Numeric](min, max T) Gen[T]
- func FlatMap[T any, K any](gen Gen[T], flatMapFunc func(T) Gen[K]) Gen[K]
- func Infer[T any](valueGenerators ...*WrappedGen) (Gen[T], error)
- func Map[T any, K any](gen Gen[T], compositionAction func(T) K) Gen[K]
- func Map10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, K any](g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], g6 Gen[T6], ...) Gen[K]
- func Map11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, K any](g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], g6 Gen[T6], ...) Gen[K]
- func Map12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, K any](g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], g6 Gen[T6], ...) Gen[K]
- func Map13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, K any](g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], g6 Gen[T6], ...) Gen[K]
- func Map14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, K any](g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], g6 Gen[T6], ...) Gen[K]
- func Map15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, K any](g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], g6 Gen[T6], ...) Gen[K]
- func Map2[T1 any, T2 any, K any](g1 Gen[T1], g2 Gen[T2], compose func(T1, T2) K) Gen[K]
- func Map3[T1 any, T2 any, T3 any, K any](g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], compose func(T1, T2, T3) K) Gen[K]
- func Map4[T1, T2, T3, T4, K any](g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], compose func(T1, T2, T3, T4) K) Gen[K]
- func Map5[T1, T2, T3, T4, T5, K any](g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], ...) Gen[K]
- func Map6[T1, T2, T3, T4, T5, T6, K any](g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], g6 Gen[T6], ...) Gen[K]
- func Map7[T1, T2, T3, T4, T5, T6, T7, K any](g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], g6 Gen[T6], ...) Gen[K]
- func Map8[T1, T2, T3, T4, T5, T6, T7, T8, K any](g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], g6 Gen[T6], ...) Gen[K]
- func Map9[T1, T2, T3, T4, T5, T6, T7, T8, T9, K any](g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], g6 Gen[T6], ...) Gen[K]
- func OneOf[T any](values ...T) Gen[T]
- func Only[T any](value T) Gen[T]
- func Pure[T any](generator func() T) Gen[T]
- func Sequential[T Numeric](from, to, step T) Gen[T]
- func StringGen(alphabet string, minLength uint, maxLength uint) Gen[string]
- func TimeBetween(start time.Time, end time.Time) Gen[time.Time]
- func TimeSeq(from, to time.Time, step time.Duration) Gen[time.Time]
- type Numeric
- type WrappedGen
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Gen ¶
type Gen[T any] interface { // Generate generates a single value of type `T` Generate() T }
Gen describes how to generate a value of a specific type `T`. The behavior of the Gen only depends on the structs implementing it.
------ float types ------ ArbitraryFloat32 is an arbitrary float32 generator within float32 min value / 2 and float32 max value / 2
ArbitraryFloat64 is an arbitrary float64 generator within float64 min value / 2 and float32 max value / 2
------ int types ------ ArbitraryInt is an arbitrary int generator within int min value / 2 and int max value / 2
ArbitraryInt32 is an arbitrary int32 generator within int32 min value / 2 and int32 max value / 2
ArbitraryInt64 is an arbitrary int64 generator within int64 min value / 2 and int64 max value / 2
var ArbitraryRune Gen[rune] = ArbitraryInt32
------ rune ------ ArbitraryRune is an arbitrary rune generator.
------ uint types ------ ArbitraryUint is an arbitrary uint generator within 0 and uint max value
ArbitraryUint16 is an arbitrary uint16 generator within 0 and uint16 max value
ArbitraryUint32 is an arbitrary uint32 generator within 0 and uint32 max value
ArbitraryUint64 is an arbitrary uint64 generator within 0 and uint64 max value
ArbitraryUint8 is an arbitrary uint8 generator within 0 and uint8 max value
func Between ¶
Between generates values within the given range. The order of the parameters doesn't actually matter, but it's more convenient to pass them properly. If max equals min, it returns an Only generator
func FlatMap ¶
FlatMap creates a flattened lazy generator given the base generator as `gen`, and a bind function.
func Infer ¶
func Infer[T any](valueGenerators ...*WrappedGen) (Gen[T], error)
Infer can infer generators for the given type parameter `T`, using the given wrapped generators. In case if the type T contains functions or types that gen's adhoc does not currently support, it returns an error, and if not, it returns the generator.
func Map ¶
Map creates a lazy generator, which when it's Generate method is invoked, it does the composition action on generated value by gen.
func Map10 ¶ added in v0.3.0
func Map10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, K any]( g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], g6 Gen[T6], g7 Gen[T7], g8 Gen[T8], g9 Gen[T9], g10 Gen[T10], compose func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) K, ) Gen[K]
Map10 takes 10 generators, and a composition action, and returns a generator which when invoked, will use the composition action and the given generators to generate new values
func Map11 ¶ added in v0.3.1
func Map11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, K any]( g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], g6 Gen[T6], g7 Gen[T7], g8 Gen[T8], g9 Gen[T9], g10 Gen[T10], g11 Gen[T11], compose func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) K, ) Gen[K]
Map11 takes 11 generators, and a composition action, and returns a generator which when invoked, will use the composition action and the given generators to generate new values
func Map12 ¶ added in v0.3.1
func Map12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, K any]( g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], g6 Gen[T6], g7 Gen[T7], g8 Gen[T8], g9 Gen[T9], g10 Gen[T10], g11 Gen[T11], g12 Gen[T12], compose func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) K, ) Gen[K]
Map12 takes 12 generators, and a composition action, and returns a generator which when invoked, will use the composition action and the given generators to generate new values
func Map13 ¶ added in v0.3.1
func Map13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, K any]( g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], g6 Gen[T6], g7 Gen[T7], g8 Gen[T8], g9 Gen[T9], g10 Gen[T10], g11 Gen[T11], g12 Gen[T12], g13 Gen[T13], compose func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) K, ) Gen[K]
Map13 takes 13 generators, and a composition action, and returns a generator which when invoked, will use the composition action and the given generators to generate new values
func Map14 ¶ added in v0.3.1
func Map14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, K any]( g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], g6 Gen[T6], g7 Gen[T7], g8 Gen[T8], g9 Gen[T9], g10 Gen[T10], g11 Gen[T11], g12 Gen[T12], g13 Gen[T13], g14 Gen[T14], compose func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) K, ) Gen[K]
Map14 takes 14 generators, and a composition action, and returns a generator which when invoked, will use the composition action and the given generators to generate new values
func Map15 ¶ added in v0.3.1
func Map15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, K any]( g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], g6 Gen[T6], g7 Gen[T7], g8 Gen[T8], g9 Gen[T9], g10 Gen[T10], g11 Gen[T11], g12 Gen[T12], g13 Gen[T13], g14 Gen[T14], g15 Gen[T15], compose func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) K, ) Gen[K]
Map15 takes 15 generators, and a composition action, and returns a generator which when invoked, will use the composition action and the given generators to generate new values
func Map2 ¶ added in v0.3.0
Map2 takes 2 generators, and a composition action, and returns a generator which when invoked, will use the composition action and the given generators to generate new values
func Map3 ¶ added in v0.3.0
func Map3[T1 any, T2 any, T3 any, K any](g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], compose func(T1, T2, T3) K) Gen[K]
Map3 takes 3 generators, and a composition action, and returns a generator which when invoked, will use the composition action and the given generators to generate new values
func Map4 ¶ added in v0.3.0
func Map4[T1, T2, T3, T4, K any]( g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], compose func(T1, T2, T3, T4) K, ) Gen[K]
Map4 takes 4 generators, and a composition action, and returns a generator which when invoked, will use the composition action and the given generators to generate new values
func Map5 ¶ added in v0.3.0
func Map5[T1, T2, T3, T4, T5, K any]( g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], compose func(T1, T2, T3, T4, T5) K, ) Gen[K]
Map5 takes 5 generators, and a composition action, and returns a generator which when invoked, will use the composition action and the given generators to generate new values
func Map6 ¶ added in v0.3.0
func Map6[T1, T2, T3, T4, T5, T6, K any]( g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], g6 Gen[T6], compose func(T1, T2, T3, T4, T5, T6) K, ) Gen[K]
Map6 takes 6 generators, and a composition action, and returns a generator which when invoked, will use the composition action and the given generators to generate new values
func Map7 ¶ added in v0.3.0
func Map7[T1, T2, T3, T4, T5, T6, T7, K any]( g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], g6 Gen[T6], g7 Gen[T7], compose func(T1, T2, T3, T4, T5, T6, T7) K, ) Gen[K]
Map7 takes 7 generators, and a composition action, and returns a generator which when invoked, will use the composition action and the given generators to generate new values
func Map8 ¶ added in v0.3.0
func Map8[T1, T2, T3, T4, T5, T6, T7, T8, K any]( g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], g6 Gen[T6], g7 Gen[T7], g8 Gen[T8], compose func(T1, T2, T3, T4, T5, T6, T7, T8) K, ) Gen[K]
Map8 takes 8 generators, and a composition action, and returns a generator which when invoked, will use the composition action and the given generators to generate new values
func Map9 ¶ added in v0.3.0
func Map9[T1, T2, T3, T4, T5, T6, T7, T8, T9, K any]( g1 Gen[T1], g2 Gen[T2], g3 Gen[T3], g4 Gen[T4], g5 Gen[T5], g6 Gen[T6], g7 Gen[T7], g8 Gen[T8], g9 Gen[T9], compose func(T1, T2, T3, T4, T5, T6, T7, T8, T9) K, ) Gen[K]
Map9 takes 9 generators, and a composition action, and returns a generator which when invoked, will use the composition action and the given generators to generate new values
func OneOf ¶
OneOf picks out a value among those values that it's given. If the values contain only one element, it returns an Only generator.
func Pure ¶ added in v0.2.2
Pure is the most basic Gen type-class constructor, which returns a T generator given the generate function
func Sequential ¶
Sequential is a sequential generator that holds the current state of the generator. It will generate numerics, between `from` and `to` (inclusive), with the given `step` size.
func StringGen ¶
StringGen is a string generator that generates random strings using the given alphabet and minLength and maxLength.
func TimeBetween ¶
TimeBetween is a generator for `time.Time` that will generate random `time.Time`s between the given start and end.
type Numeric ¶
type Numeric interface { uint8 | uint16 | uint32 | uint64 | uint | int8 | int16 | int32 | int64 | int | float32 | float64 }
Numeric represents numeric types constraint.
type WrappedGen ¶
type WrappedGen struct {
// contains filtered or unexported fields
}
WrappedGen basically wraps `Gen`s to provide a generator that works with `reflect.Value`
func Wrap ¶
func Wrap[T any](g Gen[T]) *WrappedGen
Wrap wraps around a `Gen` and returns a *WrappedGen.