github.com/leanovate/gopter@v0.2.9/gen/sized.go (about)

     1  package gen
     2  
     3  import (
     4  	"github.com/leanovate/gopter"
     5  )
     6  
     7  // Sized derives a generator from based on size
     8  // This honors the `MinSize` and `MaxSize` of the `GenParameters` of the test suite.
     9  // Keep an eye on memory consumption, by default MaxSize is 100.
    10  func Sized(f func(int) gopter.Gen) gopter.Gen {
    11  	return func(params *gopter.GenParameters) *gopter.GenResult {
    12  		var size int
    13  		if params.MaxSize == params.MinSize {
    14  			size = params.MaxSize
    15  		} else {
    16  			size = params.Rng.Intn(params.MaxSize-params.MinSize) + params.MinSize
    17  		}
    18  		return f(size)(params)
    19  	}
    20  }