Skip to content

Instantly share code, notes, and snippets.

@tokubass
Created December 23, 2018 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tokubass/5be743e5921685bbb2504c6ae74a5b69 to your computer and use it in GitHub Desktop.
Save tokubass/5be743e5921685bbb2504c6ae74a5b69 to your computer and use it in GitHub Desktop.
quick sample
package main
import (
"fmt"
"math/rand"
"reflect"
"testing/quick"
"time"
)
type Foo struct {
Int int8
}
func (f *Foo) Generate(rand *rand.Rand, size int) reflect.Value {
return reflect.ValueOf(Foo{Int: 1})
}
var r *rand.Rand
func init() {
r = rand.New(rand.NewSource(time.Now().UnixNano()))
}
func main() {
var foo = Foo{}
v, _ := quick.Value(reflect.TypeOf(foo), r)
fmt.Printf("result = %#v\n", v)
var fooPointer = &Foo{}
v, _ = quick.Value(reflect.TypeOf(fooPointer), r)
fmt.Printf("result = %#v\n", v)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment