testing

package
v2.13.3 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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