propcheck

package
v0.1.28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2023 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyString = func() func(SimpleRNG) (string, SimpleRNG) {
	return Id("")
}
View Source
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

View Source
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 ArrayOfN added in v0.1.12

func ArrayOfN[T any](n int, g func(SimpleRNG) (T, SimpleRNG)) func(SimpleRNG) ([]T, SimpleRNG)

Generates an array of N elements from the given generator

func AssertionAnd

func AssertionAnd[A any](assertions ...func(A) (bool, error)) func(A) (bool, error)

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

func AssertionOr[A any](assertions ...func(A) (bool, error)) func(A) (bool, error)

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 Boolean

func Boolean() func(SimpleRNG) (bool, SimpleRNG)

Generates A random boolean

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

func ChooseDate(start int, stopExclusive int) func(SimpleRNG) (time.Time, SimpleRNG)

Generates a random date (stopExclusive - start) days from or preceding 1999-12-31.

func ChooseInt

func ChooseInt(start int, stopExclusive int) func(SimpleRNG) (int, SimpleRNG)

Generates an integer between start and stop exclusive

func ExpectFailure

func ExpectFailure[A any](t *testing.T, result Result)

func ExpectSuccess

func ExpectSuccess[A any](t *testing.T, result Result)

func FlatMap

func FlatMap[A, B any](f func(SimpleRNG) (A, SimpleRNG), g func(A) func(SimpleRNG) (B, SimpleRNG)) func(SimpleRNG) (B, SimpleRNG)

func Id

func Id[A any](a A) func(SimpleRNG) (A, SimpleRNG)

func Int

func Int() func(SimpleRNG) (int, SimpleRNG)

Generate A random Int.

func Map

func Map[A, B any](s func(SimpleRNG) (A, SimpleRNG), f func(A) B) func(SimpleRNG) (B, SimpleRNG)

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 Map2

func Map2[A, B, C any](ra func(SimpleRNG) (A, SimpleRNG), rb func(SimpleRNG) (B, SimpleRNG), f func(a A, b B) C) func(rng SimpleRNG) (C, SimpleRNG)

func Map3

func Map3[A, B, C, D any](ra func(SimpleRNG) (A, SimpleRNG), rb func(SimpleRNG) (B, SimpleRNG),
	rc func(SimpleRNG) (C, SimpleRNG), f func(a A, b B, c C) D) func(SimpleRNG) (D, 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 Map4

func Map4[A, B, C, D, E any](ra func(SimpleRNG) (A, SimpleRNG), rb func(SimpleRNG) (B, SimpleRNG), rc func(SimpleRNG) (C, SimpleRNG),
	rd func(SimpleRNG) (D, SimpleRNG), f func(a A, b B, c C, d D) E) func(SimpleRNG) (E, 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)

func Product

func Product[A, B any](fa func(SimpleRNG) (A, SimpleRNG), fb func(SimpleRNG) (B, SimpleRNG)) func(SimpleRNG) (Pair[A, B], SimpleRNG)

func Sequence

func Sequence[T any](rs []func(SimpleRNG) (T, SimpleRNG)) func(SimpleRNG) ([]T, SimpleRNG)

func String

func String(unicodeMaxSize int) func(SimpleRNG) (string, SimpleRNG)

Be careful about specifying the stringMaxSize because if you make it too large you will probably never end up with an empty string. A rule of thumb is to make the stringMaxSize 1/3 of the number of test cases you are running.

func Weighted

func Weighted[A any](wgen []WeightedGen[A]) func(SimpleRNG) (A, SimpleRNG)

Generates A random value from A set of generators in proportion to an individual generator's weight in the list.

Types

type Falsified

type Falsified[A any] struct {
	Name            string
	FailedCase      A
	Successes       int
	LastSuccessCase A
	Errors          error
	Seed            SimpleRNG
}

func (Falsified[A]) IsFalsified

func (f Falsified[A]) IsFalsified() bool

func (Falsified[A]) String

func (w Falsified[A]) String() string

type Pair

type Pair[A, B any] struct {
	A A
	B B
}

func (Pair[A, B]) String

func (w Pair[A, B]) String() string

type Passed

type Passed[A any] struct {
	Seed SimpleRNG
}

func (Passed[A]) IsFalsified

func (f Passed[A]) IsFalsified() bool

func (Passed[A]) String

func (w Passed[A]) String() string

type Prop

type Prop struct {
	Run  Run
	Name PropName
}

func And

func And[A any](p1, p2 Prop) Prop

This is a lazily evaluated And that combines two properties.

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.

func Or

func Or[A any](p1, p2 Prop) Prop

This is a lazily evaluated Or that combines two properties.

func (Prop) String

func (w Prop) String() string

type PropName

type PropName = string

type Result

type Result interface {
	IsFalsified() bool
}

type Run

type Run = func(RunParms) Result

type RunParms

type RunParms struct {
	TestCases TestCases
	Rng       SimpleRNG
}

type SimpleRNG

type SimpleRNG struct {
	Seed int
}

func NextInt

func NextInt(r SimpleRNG) (int, SimpleRNG)

func (SimpleRNG) String

func (w SimpleRNG) String() string

type TestCases

type TestCases = int //The number of test cases to run.

type WeightedGen

type WeightedGen[A any] struct {
	Gen    func(rng SimpleRNG) (A, SimpleRNG)
	Weight int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL