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

     1  package gopter
     2  
     3  import (
     4  	"math/rand"
     5  	"time"
     6  )
     7  
     8  // TestParameters to run property tests
     9  type TestParameters struct {
    10  	MinSuccessfulTests int
    11  	// MinSize is an (inclusive) lower limit on the size of the parameters
    12  	MinSize int
    13  	// MaxSize is an (exclusive) upper limit on the size of the parameters
    14  	MaxSize         int
    15  	MaxShrinkCount  int
    16  	seed            int64
    17  	Rng             *rand.Rand
    18  	Workers         int
    19  	MaxDiscardRatio float64
    20  }
    21  
    22  func (t *TestParameters) Seed() int64 {
    23  	return t.seed
    24  }
    25  
    26  func (t *TestParameters) SetSeed(seed int64) {
    27  	t.seed = seed
    28  	t.Rng.Seed(seed)
    29  }
    30  
    31  // DefaultTestParameterWithSeeds creates reasonable default Parameters for most cases based on a fixed RNG-seed
    32  func DefaultTestParametersWithSeed(seed int64) *TestParameters {
    33  	return &TestParameters{
    34  		MinSuccessfulTests: 100,
    35  		MinSize:            0,
    36  		MaxSize:            100,
    37  		MaxShrinkCount:     1000,
    38  		seed:               seed,
    39  		Rng:                rand.New(NewLockedSource(seed)),
    40  		Workers:            1,
    41  		MaxDiscardRatio:    5,
    42  	}
    43  }
    44  
    45  // DefaultTestParameterWithSeeds creates reasonable default Parameters for most cases with an undefined RNG-seed
    46  func DefaultTestParameters() *TestParameters {
    47  	return DefaultTestParametersWithSeed(time.Now().UnixNano())
    48  }