Documentation ¶
Index ¶
- Variables
- func ArrayOfN[T any](n int, g func(SimpleRNG) (T, SimpleRNG)) func(SimpleRNG) ([]T, SimpleRNG)
- func AssertionAnd[A any](assertions ...func(A) (bool, error)) func(A) (bool, error)
- func AssertionOr[A any](assertions ...func(A) (bool, error)) func(A) (bool, error)
- func Boolean() func(SimpleRNG) (bool, SimpleRNG)
- func ChooseArray[T any](start, stopInclusive int, kind func(SimpleRNG) (T, SimpleRNG)) func(SimpleRNG) ([]T, SimpleRNG)
- func ChooseDate(start int, stopExclusive int) func(SimpleRNG) (time.Time, SimpleRNG)
- func ChooseInt(start int, stopExclusive int) func(SimpleRNG) (int, SimpleRNG)
- func ExpectFailure[A any](t *testing.T, result Result)
- func ExpectSuccess[A any](t *testing.T, result Result)
- func FlatMap[A, B any](f func(SimpleRNG) (A, SimpleRNG), g func(A) func(SimpleRNG) (B, SimpleRNG)) func(SimpleRNG) (B, SimpleRNG)
- func Id[A any](a A) func(SimpleRNG) (A, SimpleRNG)
- func Int() func(SimpleRNG) (int, SimpleRNG)
- func Map[A, B any](s func(SimpleRNG) (A, SimpleRNG), f func(A) B) func(SimpleRNG) (B, SimpleRNG)
- func Map16[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q any](ra func(SimpleRNG) (A, SimpleRNG), rb func(SimpleRNG) (B, SimpleRNG), ...) func(SimpleRNG) (Q, SimpleRNG)
- func Map2[A, B, C any](ra func(SimpleRNG) (A, SimpleRNG), rb func(SimpleRNG) (B, SimpleRNG), ...) func(rng SimpleRNG) (C, SimpleRNG)
- func Map3[A, B, C, D any](ra func(SimpleRNG) (A, SimpleRNG), rb func(SimpleRNG) (B, SimpleRNG), ...) func(SimpleRNG) (D, SimpleRNG)
- func Map32[...](ra func(SimpleRNG) (A, SimpleRNG), rb func(SimpleRNG) (B, SimpleRNG), ...) func(SimpleRNG) (II, SimpleRNG)
- func Map4[A, B, C, D, E any](ra func(SimpleRNG) (A, SimpleRNG), rb func(SimpleRNG) (B, SimpleRNG), ...) func(SimpleRNG) (E, SimpleRNG)
- func Map8[A, B, C, D, E, F, G, H, I any](ra func(SimpleRNG) (A, SimpleRNG), rb func(SimpleRNG) (B, SimpleRNG), ...) func(SimpleRNG) (I, SimpleRNG)
- func Product[A, B any](fa func(SimpleRNG) (A, SimpleRNG), fb func(SimpleRNG) (B, SimpleRNG)) func(SimpleRNG) (Pair[A, B], SimpleRNG)
- func Sequence[T any](rs []func(SimpleRNG) (T, SimpleRNG)) func(SimpleRNG) ([]T, SimpleRNG)
- func String(unicodeMaxSize int) func(SimpleRNG) (string, SimpleRNG)
- func Weighted[A any](wgen []WeightedGen[A]) func(SimpleRNG) (A, SimpleRNG)
- type Falsified
- type Pair
- type Passed
- type Prop
- type PropName
- type Result
- type Run
- type RunParms
- type SimpleRNG
- type TestCases
- type WeightedGen
Constants ¶
This section is empty.
Variables ¶
var EmptyString = func() func(SimpleRNG) (string, SimpleRNG) { return Id("") }
var Float = func() func(SimpleRNG) (float64, SimpleRNG) { fa := func(a int) float64 { aa := a aaa := float64(aa) if aaa > 0 { return 1.0 / aaa } else { return float64(0) } } return Map(NonNegativeInt, fa) }
Generates A float64 floating point number
var NonNegativeInt = func(rng SimpleRNG) (int, SimpleRNG) { i, r := NextInt(rng) if i < 0 { return -(i + 1), r } else { return i, r } }
Generates A non-negative integer
Functions ¶
func AssertionAnd ¶
Combines a list of assertion functions of type "func(A) (bool, error)" into a new function that returns their logical AND Note that like Prop.And above it evaluates lazily. Branches are evaluated only until one fails.
func AssertionOr ¶
Combines a list of assertion functions of type "func(A) (bool, error)" into a single new function that returns their logical OR. Note that like Prop.Or above it evaluates lazily. As soon as a true function is encountered it returns. Otherwise it returns all the accumulated errors.
func ChooseArray ¶ added in v0.1.12
func ChooseArray[T any](start, stopInclusive int, kind func(SimpleRNG) (T, SimpleRNG)) func(SimpleRNG) ([]T, SimpleRNG)
Generates an array with A size in the indicated range using the given Gen
func ChooseDate ¶
Generates a random date (stopExclusive - start) days from or preceding 1999-12-31.
func Map16 ¶ added in v0.1.14
func Map16[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q any](ra func(SimpleRNG) (A, SimpleRNG), rb func(SimpleRNG) (B, SimpleRNG), rc func(SimpleRNG) (C, SimpleRNG), rd func(SimpleRNG) (D, SimpleRNG), re func(SimpleRNG) (E, SimpleRNG), rf func(SimpleRNG) (F, SimpleRNG), rg func(SimpleRNG) (G, SimpleRNG), rh func(SimpleRNG) (H, SimpleRNG), ri func(SimpleRNG) (I, SimpleRNG), rj func(SimpleRNG) (J, SimpleRNG), rk func(SimpleRNG) (K, SimpleRNG), rl func(SimpleRNG) (L, SimpleRNG), rm func(SimpleRNG) (M, SimpleRNG), rn func(SimpleRNG) (N, SimpleRNG), ro func(SimpleRNG) (O, SimpleRNG), rp func(SimpleRNG) (P, SimpleRNG), f func(a A, b B, c C, d D, e E, f F, g G, h H, i I, j J, k K, l L, m M, n N, o O, p P) Q) func(SimpleRNG) (Q, SimpleRNG)
func Map32 ¶ added in v0.1.14
func Map32[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, AA, BB, CC, DD, EE, FF, GG, HH, II any](ra func(SimpleRNG) (A, SimpleRNG), rb func(SimpleRNG) (B, SimpleRNG), rc func(SimpleRNG) (C, SimpleRNG), rd func(SimpleRNG) (D, SimpleRNG), re func(SimpleRNG) (E, SimpleRNG), rf func(SimpleRNG) (F, SimpleRNG), rg func(SimpleRNG) (G, SimpleRNG), rh func(SimpleRNG) (H, SimpleRNG), ri func(SimpleRNG) (I, SimpleRNG), rj func(SimpleRNG) (J, SimpleRNG), rk func(SimpleRNG) (K, SimpleRNG), rl func(SimpleRNG) (L, SimpleRNG), rm func(SimpleRNG) (M, SimpleRNG), rn func(SimpleRNG) (N, SimpleRNG), ro func(SimpleRNG) (O, SimpleRNG), rp func(SimpleRNG) (P, SimpleRNG), rq func(SimpleRNG) (Q, SimpleRNG), rr func(SimpleRNG) (R, SimpleRNG), rs func(SimpleRNG) (S, SimpleRNG), rt func(SimpleRNG) (T, SimpleRNG), ru func(SimpleRNG) (U, SimpleRNG), rv func(SimpleRNG) (V, SimpleRNG), rw func(SimpleRNG) (W, SimpleRNG), rx func(SimpleRNG) (X, SimpleRNG), raa func(SimpleRNG) (AA, SimpleRNG), rbb func(SimpleRNG) (BB, SimpleRNG), rcc func(SimpleRNG) (CC, SimpleRNG), rdd func(SimpleRNG) (DD, SimpleRNG), ree func(SimpleRNG) (EE, SimpleRNG), rff func(SimpleRNG) (FF, SimpleRNG), rgg func(SimpleRNG) (GG, SimpleRNG), rhh func(SimpleRNG) (HH, SimpleRNG), f func(a A, b B, c C, d D, e E, f F, g G, h H, i I, j J, k K, l L, m M, n N, o O, p P, q Q, r R, s S, t T, u U, v V, w W, x X, aa AA, bb BB, cc CC, dd DD, ee EE, ff FF, gg GG, hh HH) II) func(SimpleRNG) (II, SimpleRNG)
func Map8 ¶ added in v0.1.14
func Map8[A, B, C, D, E, F, G, H, I any](ra func(SimpleRNG) (A, SimpleRNG), rb func(SimpleRNG) (B, SimpleRNG), rc func(SimpleRNG) (C, SimpleRNG), rd func(SimpleRNG) (D, SimpleRNG), re func(SimpleRNG) (E, SimpleRNG), rf func(SimpleRNG) (F, SimpleRNG), rg func(SimpleRNG) (G, SimpleRNG), rh func(SimpleRNG) (H, SimpleRNG), f func(a A, b B, c C, d D, e E, f F, g G, h H) I) func(SimpleRNG) (I, SimpleRNG)
Types ¶
type Falsified ¶
type Falsified[A any] struct { Name string FailedCase A Successes int LastSuccessCase A Errors error Seed SimpleRNG }
func (Falsified[A]) IsFalsified ¶
type Passed ¶
func (Passed[A]) IsFalsified ¶
type Prop ¶
func ForAll ¶
func ForAll[A, B any](ge func(SimpleRNG) (A, SimpleRNG), name string, f func(A) B, assertions ...func(B) (bool, error)) Prop
* Given a Generator(ge), a generated-value transformation function(f), and a variadic list of predicate functions(assertions), ForAll produces a function(of type Prop) that will run a set number of test cases with a given generator.
Parameters:
ge - a generator of type "func(SimpleRNG) (A, SimpleRNG)" name - a name to assign the Prop f - a function of type "f func(A) B" that takes the generated type A and returns another type B and then passes it along to the list of assertion functions. assertions - a variadic list of assertion functions of type "func(B) (bool, error)", each returning a pair consisting of a boolean success and a possible list of errors.
Returns:
Prop - a data structure consisting of a descriptive name for the property and a function of type func(n RunParms) Result. Result is a sum type that can be either Falsified or Passed. The FailedCase and LastSuccessCase attributes of the Falsified type(type parameter A) contain the value that caused the test failure and the last successful value for the test.