Documentation
¶
Overview ¶
Package monoidlaws provides reusable test helpers that verify a monoid.Monoid[V] satisfies the algebraic laws (associativity and identity) required for safe use in Murmur pipelines.
Implementing a custom monoid? Wire up a sample generator and call:
monoidlaws.TestMonoid(t, m, gen, monoidlaws.WithSamples(64))
where `gen` is a func(int) V that returns the i-th sample. Optionally pass WithEqual to override the default equality check (useful for monoids whose internal representation has don't-care bits — encoded sketches, etc).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TestMonoid ¶
TestMonoid asserts the three monoid laws hold for m given a sample generator:
- Left identity: Combine(Identity(), x) == x
- Right identity: Combine(x, Identity()) == x
- Associativity: Combine(Combine(a, b), c) == Combine(a, Combine(b, c))
gen(i) returns the i-th sample; the helper draws cfg.samples samples, then exercises identity at each one and associativity over a representative subset of triples (cubic blow-up is the reason samples defaults to 32).
Failures are reported via t.Errorf with the offending input, so a single broken monoid produces a focused diagnostic rather than a wall of "FAIL".
Types ¶
type Option ¶
type Option[V any] func(*config[V])
Option configures TestMonoid.
func WithEqual ¶
WithEqual overrides the equality check. Default is reflect.DeepEqual. Use this for monoids whose Combine result is not bitwise-stable (e.g. floating point) — supply a tolerance-based comparator.
func WithSamples ¶
WithSamples sets how many sample values are drawn from the generator. Default 32. Bigger values explore more triples for the associativity check; cubic in samples.