Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
29 lines (25 sloc) 716 Bytes
package gen
import (
"reflect"
"github.com/leanovate/gopter"
)
// OneConstOf generate one of a list of constant values
func OneConstOf(consts ...interface{}) gopter.Gen {
if len(consts) == 0 {
return Fail(reflect.TypeOf(nil))
}
return func(genParams *gopter.GenParameters) *gopter.GenResult {
idx := genParams.Rng.Intn(len(consts))
return gopter.NewGenResult(consts[idx], gopter.NoShrinker)
}
}
// OneGenOf generate one value from a a list of generators
func OneGenOf(gens ...gopter.Gen) gopter.Gen {
if len(gens) == 0 {
return Fail(reflect.TypeOf(nil))
}
return func(genParams *gopter.GenParameters) *gopter.GenResult {
idx := genParams.Rng.Intn(len(gens))
return gens[idx](genParams)
}
}
You can’t perform that action at this time.