@auturge/testing v1.0.0
auturge/testing
Installation
$ npm install @auturge/testing
AnyRandom
AnyRandom: Generate pseudo-random entities for testing purposes.
NOTE that some methods include one or more alias methods. These methods provide identical behavior, simply under a different method name.
Boolean
AnyRandom.boolean(): boolean; AnyRandom.bool(): boolean;
Returns a random boolean (true or false).
Date
AnyRandom.date(): Date;
Returns a random date between 01-JAN-1970 and now.
AnyRandom.date(earliest: Date, latest: Date): Date;
Returns a random date within the range defined by the earliest and latest dates.
Sign
AnyRandom.sign(includeZero?: boolean = false): number;
Returns a random sign.
When the optional parameter includeZero is false, or not provided, returns either -1 or 1.
When includeZero is true, returns -1, 0, or 1.
8-bit Integer (byte)
AnyRandom.uint8(): number; AnyRandom.byte(): number;
Returns a random unsigned 'byte' (8-bit integer) on the interval [0, 255].
AnyRandom.uint8(minValue: number, maxValue: number): number; AnyRandom.byte(minValue: number, maxValue: number): number;
Returns a random unsigned byte within the range defined by minValue and maxValue.
NOTE that minValue and maxValue must both be on the interval [0, 255].
AnyRandom.int8(): number; AnyRandom.sbyte(): number;
Returns a random signed byte on the interval [-128, 127].
AnyRandom.int8(minValue: number, maxValue: number): number; AnyRandom.sbyte(minValue: number, maxValue: number): number;
Returns a random signed byte within the range defined by minValue and maxValue.
NOTE that minValue and maxValue must both be on the interval [-128, 127].
16-bit Integer
AnyRandom.uint16(): number; AnyRandom.ushort(): number;
Returns a random unsigned 16-bit integer on the interval [0, 65535].
AnyRandom.uint16(minValue: number, maxValue: number): number; AnyRandom.ushort(minValue: number, maxValue: number): number;
Returns a random unsigned 16-bit integer within the range defined by minValue and maxValue.
NOTE that minValue and maxValue must both be on the interval [0, 65535].
AnyRandom.int16(): number; AnyRandom.short(): number;
Returns a random signed 16-bit integer on the interval [–32768, 32767].
AnyRandom.uint16(minValue: number, maxValue: number): number; AnyRandom.ushort(minValue: number, maxValue: number): number;
Returns a random signed 16-bit integer within the range defined by minValue and maxValue.
NOTE that minValue and maxValue must both be on the interval [-32768, 32767].
32-bit Integer
AnyRandom.uint32(): number; AnyRandom.uint(): number;
Returns a random unsigned 32-bit integer on the interval [0, 4294967295].
AnyRandom.uint32(minValue: number, maxValue: number): number; AnyRandom.uint(minValue: number, maxValue: number): number;
Returns a random unsigned 32-bit integer within the range defined by minValue and maxValue.
NOTE that minValue and maxValue must both be on the interval [0, 4294967295].
AnyRandom.int32(): number; AnyRandom.int(): number;
Returns a random signed 32-bit integer on the interval [-2147483648, 2147483647].
AnyRandom.int32(minValue: number, maxValue: number): number; AnyRandom.int(minValue: number, maxValue: number): number;
Returns a random signed 32-bit integer within the range defined by minValue and maxValue.
NOTE that minValue and maxValue must both be on the interval [-2147483648, 2147483647].
64-bit Double-Precision Floating Point Number
AnyRandom.double(): number; AnyRandom.number(): number;
Returns a random 64-bit double-precision floating-point number on the interval [0, 1).
NOTE that this is the same behavior as Math.random().
AnyRandom.double(minValue: number, maxValue: number): number; AnyRandom.number(minValue: number, maxValue: number): number;
Returns a random 64-bit double-precision floating-point number within the range defined by minValue and maxValue.
32-bit Single-Precision Floating Point Number
AnyRandom.float(): number; AnyRandom.single(): number;
Returns a random 32-bit single-precision floating-point number on the interval (-infinity, infinity).
AnyRandom.float(minValue: number, maxValue: number): number; AnyRandom.single(minValue: number, maxValue: number): number;
Returns a random 32-bit single-precision floating-point number within the range defined by minValue and maxValue.
Character Sets
Character
AnyRandom.char(): string;
Returns a single random character, taken from the ATOM character set.
AnyRandom.char(characterSet: string | CharacterSet): string;
Returns a single random character, taken from the given characterSet.
Character Array
AnyRandom.charArray(): string[];
Returns an array of characters, between 0 and 32 characters long, taken from the ATOM character set.
AnyRandom.charArray(minLength: number, maxLength: number): string[];
Returns an array of characters, between minLength and maxLength characters long, where the elements are taken from the ATOM character set.
AnyRandom.charArray(minLength: number, maxLength: number, characterSet: string | CharacterSet): string[];
Returns an array of characters, between minLength and maxLength characters long, where the elements are taken from the given characterSet.
String
AnyRandom.string(): string;
Returns a random string, between 0 and 32 characters long, where the characters are taken from the ATOM character set.
AnyRandom.string(minLength: number, maxLength: number): string;
Returns a random string, between minLength and maxLength characters long, where the characters are taken from the ATOM character set.
AnyRandom.string(minLength: number, maxLength: number, characterSet: string | CharacterSet): string;
Returns a random string, between minLength and maxLength characters long, where the characters are taken from the given characterSet.
UUID
AnyRandom.uuid(): string;
or
AnyRandom.guid(): string;
Returns a quasi-random (v4) UUID as a string.
WARNING: Randomness and/or uniqueness are not guaranteed!
DO NOT use this method to produce UUIDs in production code!
enum
AnyRandom.enum<T>(enumeration: T): T[keyof T];
Returns a randomly-chosen entry from the given enum.
WARNING: This only works for enums with keys of type
string.
oneOf
AnyRandom.oneOf<T>(array: T[]): T;
Returns a randomly-chosen entry from the given array.
arrayOf
AnyRandom.arrayOf<T>(generator: () => T): T[];
Returns an array of between 5 any 10 elements, using the specified generator function.
AnyRandom.arrayOf<T>(generator: () => T, count: number): T[];
Returns an array of count elements, using the specified generator function.
AnyRandom.arrayOf<T>(generator: () => T, minCount: number, maxCount: number): T[];
Returns an array with a number of elements between minCount and maxCount, using the specified generator function.
URL
AnyRandom.url(): string;
Returns a quasi-random URL, with an empty path, no query, and no fragment(s).
AnyRandom.url(includePath: boolean, includeQuery: boolean, includeFragment: boolean): string;
Returns a quasi-random URL, including the specified parts.
License
Distributed under the MIT license. See LICENSE for more information.