Move SliceOfNZero to test/generator package

This commit is contained in:
2024-09-13 11:24:43 -06:00
parent c9ee9916eb
commit a223f18f02
2 changed files with 14 additions and 12 deletions

View File

@ -6,6 +6,15 @@ import (
"pgregory.net/rapid"
)
// Error returns a new error created by calling [errors.New] with a random string.
func Error() *rapid.Generator[error] {
return rapid.Map(rapid.String(), errors.New)
}
// 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)
})
}