github.com/leanovate/gopter@v0.2.9/gen_parameter_test.go (about) 1 package gopter_test 2 3 import ( 4 "math/rand" 5 "testing" 6 7 "github.com/leanovate/gopter" 8 ) 9 10 type fixedSeed struct { 11 fixed int64 12 } 13 14 func (f *fixedSeed) Int63() int64 { return f.fixed } 15 func (f *fixedSeed) Seed(seed int64) { f.fixed = seed } 16 17 func TestGenParameters(t *testing.T) { 18 parameters := &gopter.GenParameters{ 19 MaxSize: 100, 20 Rng: rand.New(&fixedSeed{}), 21 } 22 23 if !parameters.NextBool() { 24 t.Error("Bool should be true") 25 } 26 if parameters.NextInt64() != 0 { 27 t.Error("int64 should be 0") 28 } 29 if parameters.NextUint64() != 0 { 30 t.Error("uint64 should be 0") 31 } 32 33 parameters.Rng.Seed(1) 34 if parameters.NextBool() { 35 t.Error("Bool should be false") 36 } 37 if parameters.NextInt64() != 1 { 38 t.Error("int64 should be 1") 39 } 40 if parameters.NextUint64() != 3 { 41 t.Error("uint64 should be 3") 42 } 43 44 parameters.Rng.Seed(2) 45 if !parameters.NextBool() { 46 t.Error("Bool should be true") 47 } 48 if parameters.NextInt64() != -2 { 49 t.Error("int64 should be -2") 50 } 51 if parameters.NextUint64() != 6 { 52 t.Error("uint64 should be 6") 53 } 54 55 param1 := parameters.CloneWithSeed(1024) 56 param2 := parameters.CloneWithSeed(1024) 57 58 for i := 0; i < 100; i++ { 59 if param1.NextInt64() != param2.NextInt64() { 60 t.Error("cloned parameters create different random numbers") 61 } 62 } 63 }