github.com/leanovate/gopter@v0.2.9/gen/sized_test.go (about) 1 package gen_test 2 3 import ( 4 "testing" 5 6 "github.com/leanovate/gopter" 7 8 "github.com/leanovate/gopter/gen" 9 ) 10 11 func TestSized(t *testing.T) { 12 sizedInt := gen.Sized(func(size int) gopter.Gen { 13 return gen.IntRange(0, size) 14 }) 15 16 for i := 0; i < 100; i++ { 17 value, ok := sizedInt.Sample() 18 19 if !ok || value == nil { 20 t.Errorf("Invalid sized int: %#v", value) 21 } 22 v, ok := value.(int) 23 if !ok { 24 t.Errorf("Invalid sized int: %#v", value) 25 } 26 if v < 0 || v > 100 { 27 t.Errorf("Sized int out of range: %d", v) 28 } 29 } 30 }