FuzzyTest
Helper class for performing fuzzy property-based tests of Helios scripts.
Constructor
new helios.FuzzyTest(
seed: number = 0,
runsPerTest: number = 100,
simplify: boolean = false
)
The simplify
argument specifies whether optimized versions of the Helios sources should also be tested.
Methods
ascii
Returns a generator for ByteArrayData
instances representing ascii strings.
fuzzy_test.ascii(
minLength: number = 0,
maxLength: number = 64
): (() => helios.ByteArrayData)
bool
Returns a generator for primitive boolean instances.
fuzzy_test.bool(): (() => helios.ConstrData)
bytes
Returns a generator for ByteArrayData
.
fuzzy_test.bytes(
minLength: number = 0,
maxLength: number = 64
): (() => helios.ByteArrayData)
int
Returns a generator for IntData
.
fuzzy_test.int(
min: number = -10000000,
max: number = 10000000
): (() => helios.IntData)
list
Returns a generator for ListData
, where every item is generated by the given itemGenerator
.
fuzzy_test.list(
itemGenerator: () => helios.UplcData,
minLength: number = 0,
maxLength: number = 10
): (() => helios.ListData)
map
Returns a generator for MapData
, where every key and value is generated by the given keyGenerator
and valueGenerator
respectively.
fuzzy_test.map(
keyGenerator: () => helios.UplcData,
valueGenerator: () => helios.UplcData,
minLength: number = 0,
maxLength: number = 10
): (() => helios.MapData)
option
Returns a generator for ConstrData
instances representing random options. The probability of none occurences can be configured.
fuzzy_test.option(
someGenerator: () => helios.UplcData,
noneProbability: number = 0.5
): (() => helios.ConstrData)
string
Returns a generator for ByteArrayData
instances representing utf-8 strings.
fuzzy_test.string(
minLength: number = 0,
maxLength: number = 64
): (() => helios.ByteArrayData)
test
Perform a fuzzy/property-based test-run of a Helios source. One value generator must be specified per argument of main
.
Throws an error if the propTest
fails.
The propTest
can simply return a boolean
, or can return an object with boolean values, and if any of these booleans is false
the propTest
fails (the keys can be used to provide extra information).
fuzzy_test.test(
argGens: (() => helios.UplcData)[],
src: string,
propTest: (
args: helios.UplcValue[],
res: helios.UplcValue | helios.UserError
) => (boolean | Object.<string, boolean>)
): Promise<void>