Documentation
¶
Overview ¶
Package testing provides utilities for testing Either monad laws. This is useful for verifying that custom Either implementations satisfy the monad laws.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertLaws ¶
func AssertLaws[E, A, B, C any](t *testing.T, eqe EQ.Eq[E], 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 that the Either monad satisfies the monad laws. This includes testing:
- Identity laws (left and right identity)
- Associativity law
- Functor laws
- Applicative laws
Parameters:
- t: Testing context
- eqe, eqa, eqb, eqc: Equality predicates for the types
- ab: Function from A to B for testing
- bc: 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 TestEitherLaws(t *testing.T) {
eqInt := eq.FromStrictEquals[int]()
eqString := eq.FromStrictEquals[string]()
eqError := eq.FromStrictEquals[error]()
ab := strconv.Itoa
bc := func(s string) bool { return len(s) > 0 }
testing.AssertLaws(t, eqError, eqInt, eqString, eq.FromStrictEquals[bool](), ab, bc)(42)
}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.