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

     1  /*
     2  Package arbitrary contains helpers to create contexts of arbitrary values, i.e.
     3  automatically combine generators as needed using reflection.
     4  
     5  A simple example might look like this:
     6  
     7      func TestIntParse(t *testing.T) {
     8        properties := gopter.NewProperties(nil)
     9        arbitraries := arbitrary.DefaultArbitraries()
    10  
    11        properties.Property("printed integers can be parsed", arbitraries.ForAll(
    12      		func(a int64) bool {
    13      			str := fmt.Sprintf("%d", a)
    14      			parsed, err := strconv.ParseInt(str, 10, 64)
    15      			return err == nil && parsed == a
    16      		}))
    17  
    18        properties.TestingRun(t)
    19      }
    20  
    21  Be aware that by default always the most generic generators are used. I.e. in
    22  the example above the gen.Int64 generator will be used and the condition will
    23  be tested for the full range of int64 numbers.
    24  
    25  To adapt this one might register a generator for a specific type in an
    26  arbitraries context. I.e. by adding
    27  
    28        arbitraries.RegisterGen(gen.Int64Range(-1000, 1000))
    29  
    30  any generated int64 number will be between -1000 and 1000.
    31  */
    32  package arbitrary