Standard library / testing/quick

testing/quick.Generator

Custom generated values implement Generate with a random source and size hint. This example intentionally generates a fixed valid value. Expected stdout: '7 true\n'.

Formal Syntax & Structure

go syntaxgo
type Generator interface {  Generate(rand *rand.Rand, size int) reflect.Value}

Working Example

Example Snippetgo
package main
import (  "fmt"  "math/rand"  "reflect"  "testing/quick")
type small int
func (small) Generate(r *rand.Rand, size int) reflect.Value { return reflect.ValueOf(small(7)) }func main() {  var _ quick.Generator = small(0)  v, ok := quick.Value(reflect.TypeOf(small(0)), rand.New(rand.NewSource(42)))  fmt.Println(v.Int(), ok)}
Go Reference