2024-09-13 17:17:32 +00:00
|
|
|
package generator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"pgregory.net/rapid"
|
|
|
|
)
|
|
|
|
|
2024-09-13 17:24:43 +00:00
|
|
|
// Error returns a new error created by calling [errors.New] with a random string.
|
2024-09-13 17:17:32 +00:00
|
|
|
func Error() *rapid.Generator[error] {
|
|
|
|
return rapid.Map(rapid.String(), errors.New)
|
|
|
|
}
|
2024-09-13 17:24:43 +00:00
|
|
|
|
|
|
|
// SliceOfNZero returns a generator that makes slices of the zero value of T.
|
|
|
|
// The range of slice lengths are determined as in [rapid.SliceOfN].
|
|
|
|
func SliceOfNZero[T any](minLen, maxLen int) *rapid.Generator[[]T] {
|
|
|
|
return rapid.Map(rapid.IntRange(minLen, maxLen), func(n int) []T {
|
|
|
|
return make([]T, n)
|
|
|
|
})
|
|
|
|
}
|