garbage

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultInitialWeights

func DefaultInitialWeights() map[datamodel.Kind]int

DefaultInitialWeights provides the default map of weights that can be overridden by the InitialWeights option. The default is an equal weighting of 1 for every scalar kind and 10 for the recursive kinds.

func DefaultWeights

func DefaultWeights() map[datamodel.Kind]int

DefaultWeights provides the default map of weights that can be overridden by the Weights option. The default is an equal weighting of 1 for every kind.

func Generate

func Generate(rand *mathrand.Rand, opts ...Option) datamodel.Node

Generate produces random Nodes which can be useful for testing and benchmarking. By default, the Nodes produced are relatively small, averaging near the 1024 byte range when encoded (very roughly, with a wide spread).

Options can be used to adjust the average size and weights of occurances of different kinds within the complete Node graph.

Care should be taken when using a random source to generate garbage for testing purposes, that the randomness is stable across test runs, or a seed is captured in such a way that a failure can be reproduced (e.g. by printing it to stdout during the test run so it can be captured in CI for a failure).

Types

type Option

type Option func(*Options)

func InitialWeights

func InitialWeights(initialWeights map[datamodel.Kind]int) Option

InitialWeights sets a per-kind weighting for the root node. That is, the weights set here will determine the liklihood of the returned Node's direct .Kind(). These weights are ignored after the top-level Node (for recursive kinds, obviously for scalar kinds there is only a top-level Node).

The default initial weights bias toward Map and List kinds, by a ratio of 10:1—i.e. the recursive kinds are more likely to appear at the top-level.

func TargetBlockSize

func TargetBlockSize(blockSize uint64) Option

TargetBlockSize sets a very rough bias in number of bytes that the resulting Node may consume when encoded (i.e. the block size). This is a very approximate measure, but over enough repeated Generate() calls, the resulting Nodes, once encoded, should have a median that is somewhere in this vicinity.

The default target block size is 1024. This should be tuned in accordance with the anticipated average block size of the system under test.

func Weights

func Weights(weights map[datamodel.Kind]int) Option

Weights sets a per-kind weighting for nodes appearing throughout the returned graph. When assembling a graph, these weights determine the liklihood that a given kind will be selected for that node.

A weight of 0 will turn that kind off entirely. So, for example, if you wanted output data with no maps or bytes, then set both of those weights to zero, leaving the rest >0 and do the same for InitialWeights.

The default weights are set to 1—i.e. there is an equal liklihood that any of the valid kinds will be selected for any point in the graph.

This option is overridden by InitialWeights (which also has a default even if not set explicitly) for the top-level node.

type Options

type Options struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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