Help us shape the future of Go! Take the 2026 Go Developer Survey

testing

package
v2.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertLaws

func AssertLaws[A, B, C any](t *testing.T,
	eqa EQ.Eq[A],
	eqb EQ.Eq[B],
	eqc EQ.Eq[C],

	ab func(A) B,
	bc func(B) C,
) func(a A) bool

AssertLaws asserts the monad laws for the Option monad. This function verifies that Option satisfies the functor, applicative, and monad laws.

The laws tested include:

  • Functor laws: identity and composition
  • Applicative laws: identity, composition, homomorphism, and interchange
  • Monad laws: left identity, right identity, and associativity

Parameters:

  • t: testing instance
  • eqa, eqb, eqc: equality predicates for types A, B, and C
  • ab: a function from A to B for testing
  • bc: a function from B to C for testing

Returns a function that takes a value of type A and returns true if all laws hold.

Example:

func TestOptionLaws(t *testing.T) {
    eqInt := eq.FromStrictEquals[int]()
    eqString := eq.FromStrictEquals[string]()
    eqBool := eq.FromStrictEquals[bool]()

    ab := strconv.Itoa
    bc := S.IsNonEmpty

    assert := AssertLaws(t, eqInt, eqString, eqBool, ab, bc)
    assert(42) // verifies laws hold for value 42
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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