Array Generators

qc.arrayOf(generator, [options])

Generates an array consisting of values produces by the generator passed. So qc.arrayOf(qc.uint) would produce something like [8, 34, 46].

The options argument is an object that can have these keys:

KeyTypeDescription
lengthNumber or Generator that produces a numberThis will be the length of the generated array. For example, to have an array of 3 to 5 items, you could do qc.arrayOf(qc.int, {length: qc.int.between(3, 5)})
sparseBooleanIf true (defaults to false), the array returned may be sparse.

qc.array

Generate a random array of any random type.

qc.array.subsetOf(array, [options])

Generates a subset of the passed array. By this we mean that for every element of the generated array, it will be a member of the passed array. Furthermore the element will not appear in the result array more times that in the passed array.

For example qc.array.subsetOf([1, 2]) will generate one of [], [1], [2] or [1, 2].

The options argument is an object that can have these keys:

KeyTypeDescription
lengthNumber or Generator that produces a numberThis will be the length of the generated array. For example, to have an array of 3 to 5 items, you could do qc.arrayOf(qc.int, {length: qc.int.between(3, 5)})
sparseBooleanIf true (defaults to false), the array returned may be sparse.