github.com/leanovate/gopter@v0.2.9/arbitrary/forall.go (about) 1 package arbitrary 2 3 import ( 4 "fmt" 5 "reflect" 6 7 "github.com/leanovate/gopter" 8 "github.com/leanovate/gopter/prop" 9 ) 10 11 /* 12 ForAll creates a property that requires the check condition to be true for all 13 values, if the condition falsiies the generated values will be shrunk. 14 15 "condition" has to be a function with the any number of parameters that can 16 generated in context of the Arbitraries. The function may return a simple bool, 17 a *PropResult, a boolean with error or a *PropResult with error. 18 */ 19 func (a *Arbitraries) ForAll(condition interface{}) gopter.Prop { 20 conditionVal := reflect.ValueOf(condition) 21 conditionType := conditionVal.Type() 22 23 if conditionType.Kind() != reflect.Func { 24 return prop.ErrorProp(fmt.Errorf("Param of ForrAll has to be a func: %v", conditionType.Kind())) 25 } 26 27 gens := make([]gopter.Gen, conditionType.NumIn()) 28 for i := 0; i < conditionType.NumIn(); i++ { 29 gens[i] = a.GenForType(conditionType.In(i)) 30 } 31 32 return prop.ForAll(condition, gens...) 33 }