Documentation
¶
Index ¶
- Variables
- func NewRand(t *testing.T) *rand.Rand
- func Pick[T any](g *Gen, slice []T) T
- func RandBool(r *rand.Rand) bool
- func RandMapKey[K comparable, V any](r *rand.Rand, m map[K]V) K
- func RandString(r *rand.Rand, length int) string
- func RandWeightedOp(r *rand.Rand, ops OpWeights) string
- func Shuffle[T any](g *Gen, slice []T)
- type AnotherEvent
- type CommandA
- type CommandB
- type CommandC
- type ComponentA
- type ComponentB
- type ComponentC
- type Gen
- type OpWeights
- type SimpleCommand
- type SimpleComponent
- type SimpleEvent
- type SimpleSystemEvent
- type SystemEventA
- type SystemEventB
- type SystemEventC
Constants ¶
This section is empty.
Variables ¶
var Seed uint64 //nolint:gochecknoglobals // intentionally global for test reproducibility
Functions ¶
func RandMapKey ¶
func RandMapKey[K comparable, V any](r *rand.Rand, m map[K]V) K
RandMapKey returns a random key from a map. Panics if the map is empty.
func RandString ¶ added in v0.10.0
RandString generates a random alphanumeric string of the given length.
func RandWeightedOp ¶
RandWeightedOp returns a random operation from a map, using each op's value as its weight.
Types ¶
type AnotherEvent ¶
type AnotherEvent struct {
Data string
}
func (AnotherEvent) MarshalWire ¶ added in v0.15.0
func (e AnotherEvent) MarshalWire() []byte
MarshalWire is a test double for generated event wire code (explicit encoding, no serialization lib).
func (AnotherEvent) Name ¶
func (AnotherEvent) Name() string
func (AnotherEvent) UnmarshalWire ¶ added in v0.15.0
func (AnotherEvent) UnmarshalWire(b []byte) (any, error)
type CommandA ¶ added in v0.10.0
type CommandA struct {
X, Y, Z float64
}
func (CommandA) MarshalWire ¶ added in v0.15.0
type CommandB ¶ added in v0.10.0
func (CommandB) MarshalWire ¶ added in v0.15.0
type CommandC ¶ added in v0.10.0
func (CommandC) MarshalWire ¶ added in v0.15.0
type ComponentA ¶
type ComponentA struct {
X, Y, Z float64
}
func (ComponentA) MarshalWire ¶ added in v0.15.0
func (c ComponentA) MarshalWire() []byte
func (ComponentA) Name ¶
func (ComponentA) Name() string
func (ComponentA) UnmarshalWire ¶ added in v0.15.0
func (ComponentA) UnmarshalWire(b []byte) (any, error)
type ComponentB ¶
func (ComponentB) MarshalWire ¶ added in v0.15.0
func (c ComponentB) MarshalWire() []byte
func (ComponentB) Name ¶
func (ComponentB) Name() string
func (ComponentB) UnmarshalWire ¶ added in v0.15.0
func (ComponentB) UnmarshalWire(b []byte) (any, error)
type ComponentC ¶
func (ComponentC) MarshalWire ¶ added in v0.15.0
func (c ComponentC) MarshalWire() []byte
func (ComponentC) Name ¶
func (ComponentC) Name() string
func (ComponentC) UnmarshalWire ¶ added in v0.15.0
func (ComponentC) UnmarshalWire(b []byte) (any, error)
type Gen ¶
type Gen struct {
// contains filtered or unexported fields
}
Gen is an exhaustive generator that iterates through all possible combinations of values.
The implementation is tricky, refer to the post for details.
On each iteration of `while (!g.done())` loop, Gen generates a sequence of numbers. Internally, it remembers this sequence together with bounds the user requested:
value: 3 1 4 4 bound: 5 4 4 4
To advance to the next iteration, Gen finds the smallest sequence of values which is larger than the current one, but still satisfies all the bounds. "Smallest" means that Gen tries to increment the rightmost number.
In the above example, the last two "4"s already match the bound, so we can't increment them. However, we can increment the second number, "1", to get 3 2 4 4. This isn’t the smallest sequence though, 3 2 0 0 is be smaller. So, after incrementing the rightmost number possible, we zero the rest.
See: <https://matklad.github.io/2021/11/07/generate-all-the-things.html>
type SimpleCommand ¶
type SimpleCommand struct {
Value int
}
func (SimpleCommand) MarshalWire ¶ added in v0.15.0
func (c SimpleCommand) MarshalWire() []byte
func (SimpleCommand) Name ¶
func (SimpleCommand) Name() string
func (SimpleCommand) UnmarshalWire ¶ added in v0.15.0
func (SimpleCommand) UnmarshalWire(data []byte) (any, error)
type SimpleComponent ¶
type SimpleComponent struct {
Value int
}
func (SimpleComponent) MarshalWire ¶ added in v0.15.0
func (c SimpleComponent) MarshalWire() []byte
func (SimpleComponent) Name ¶
func (SimpleComponent) Name() string
func (SimpleComponent) UnmarshalWire ¶ added in v0.15.0
func (SimpleComponent) UnmarshalWire(b []byte) (any, error)
type SimpleEvent ¶
type SimpleEvent struct {
Value int
}
func (SimpleEvent) MarshalWire ¶ added in v0.15.0
func (s SimpleEvent) MarshalWire() []byte
MarshalWire / UnmarshalWire are a test double for generated event wire code — the engine requires the wire codec. Deliberately an explicit encoding, not a serialization library, so testutils stays free of any wire-format dependency.
func (SimpleEvent) Name ¶
func (SimpleEvent) Name() string
func (SimpleEvent) UnmarshalWire ¶ added in v0.15.0
func (SimpleEvent) UnmarshalWire(b []byte) (any, error)
type SimpleSystemEvent ¶
type SimpleSystemEvent struct {
Value int
}
func (SimpleSystemEvent) MarshalWire ¶ added in v0.15.0
func (c SimpleSystemEvent) MarshalWire() []byte
func (SimpleSystemEvent) Name ¶
func (SimpleSystemEvent) Name() string
func (SimpleSystemEvent) UnmarshalWire ¶ added in v0.15.0
func (SimpleSystemEvent) UnmarshalWire(b []byte) (any, error)
type SystemEventA ¶
type SystemEventA struct {
X, Y, Z float64
}
func (SystemEventA) Name ¶
func (SystemEventA) Name() string
type SystemEventB ¶
func (SystemEventB) Name ¶
func (SystemEventB) Name() string
type SystemEventC ¶
func (SystemEventC) Name ¶
func (SystemEventC) Name() string