/** * A function that should generate a random value of a particular type. * @param size This is used to generate "larger" values. */ declare interface QCGenerator { (size: number) : T; } /** * An object that indicates the result of a quick_check test. */ interface QCResult { /** Indicates whether the assertion passed all the generated examples */ pass: boolean; /** The (non-shrunk) examples that failed the test (or the last generated examples in case of success). */ examples: any[]; /** The minimal (i.e. shrunk) examples that failed the test. */ minimalExamples?: any[]; /** A message indicating the status of the test run. This is suitable for printing to the user. */ message: string } /** * The behavior of quick check is based on the return type: * - `true` means a pass * - `false` means failure * - a string means a pass with the examples falling into a particular category * - `void` means this set of examples should be skipped */ declare type QCAssertionResult = boolean | string | void; /** * This function executes a check of the function `prop` using `generators` * @param prop The property you wish to execute. * @param generators The generators that supply values to the property. */ declare function qc(prop: (arg: T) => QCAssertionResult, generator : QCGenerator) : QCResult; declare function qc(prop: (arg1: T, arg2: U) => QCAssertionResult, generator1 : QCGenerator, generator2 : QCGenerator) : QCResult; declare function qc(prop: (arg1: T, arg2: U, arg3: V) => QCAssertionResult, generator1 : QCGenerator, generator2 : QCGenerator, generator3 : QCGenerator) : QCResult; declare function qc(prop: (...values: any[]) => QCAssertionResult, ...generators : QCGenerator[]) : QCResult; declare module qc { /** * This function executes a check of the function `prop` using `generators`, but ignores the result. * @param prop The property you wish to execute. * @param generators The generators that supply values to the property. */ function forAll(prop: (arg: T) => U, generator : QCGenerator): [U]; function forAll(prop: (arg1: T, arg2: U) => V, generator1 : QCGenerator, generator2 : QCGenerator): [V]; function forAll(prop: (arg1: T, arg2: U, arg3: V) => W, generator1 : QCGenerator, generator2 : QCGenerator, generator3 : QCGenerator): [W]; function forAll(prop: (...values: any[]) => T, ...generators: QCGenerator[]): [T]; /** * Generates a random value between 0 and 1. */ function random(): number; /** * Generates either `true` or `false`. */ var bool : QCGenerator; /** * Generates an integer between 0 and 255. */ var byte : QCGenerator; /** * Generates a new value from a constructor function (or a class). * @param cons A constructor function or a class. * @param generators quick_check.js generators that supply arguments to cons. * @return An instance of cons. */ function constructor(cons: {new(arg: U): T;}, generator: QCGenerator) : QCGenerator; function constructor(cons: {new(arg1: U, arg2: V): T;}, generator1: QCGenerator, generator2: QCGenerator) : QCGenerator; function constructor(cons: {new(arg1: U, arg2: V, arg3: W): T;}, generator1: QCGenerator, generator2: QCGenerator, generator3: QCGenerator) : QCGenerator; function constructor(cons: {new(...args: any[]): T;}, ...generators: QCGenerator[]) : QCGenerator; /** * Generates a new value using a custom function. * @param fun A function that generates the value * @param generators quick_check.js generators that supply arguments to `fun`. */ function fromFunction(fun: (arg: U) => T, generator: QCGenerator) : QCGenerator; function fromFunction(fun: (arg1: U, arg2: V) => T, generator1: QCGenerator, generator2: QCGenerator) : QCGenerator; function fromFunction(fun: (arg1: U, arg2: V, arg3: W) => T, generator1: QCGenerator, generator2: QCGenerator, generator3: QCGenerator) : QCGenerator; function fromFunction(fun: (...args: any[]) => T, ...generators: QCGenerator[]) : QCGenerator; interface ArrayOptions { /** How many elements the array should have. */ length?: number | QCGenerator; /** Whether the array should be sparse, i.e. include elements that are void. */ sparse?: boolean; } /** * Generates an array of values provided by the generator passed in. * @param generator A generator that provides the values in the resulting array. */ function arrayOf(generator: QCGenerator, options?: ArrayOptions) : QCGenerator; interface ArrayGenerator extends QCGenerator { /** * Generates a random subset of an array. * @param array The array that the elements will be drawn from. */ subsetOf(array: T[], options? : ArrayOptions) : QCGenerator[]; } /** * Generates a random array. */ var array : ArrayGenerator; function pick(...args: any[]) : QCGenerator; function oneOf(generator1: QCGenerator, generator2: QCGenerator) : QCGenerator; function oneOf(generator1: QCGenerator, generator2: QCGenerator, generator3: QCGenerator) : QCGenerator; function oneOf(...generators: QCGenerator[]) : QCGenerator; /** * Ensures that the generator passed in will not return any of the values passed. * Note that the performance of this method is inversely proportional to the probability * of the excluded values (i.e. if the probability of the values is 1, then the function * will never terminate). */ function except(generator: QCGenerator, ...values: T[]) : QCGenerator; /** * Generates a pure function that returns a random value of the `returnType`. * It has the property of returning the same value given the same arguments. */ function pureFunction(returnType: QCGenerator) : QCGenerator<(...args: any[]) => T>; /** * Allows to execute random side effects :) * @param obj An object or Class whose methods wiil be injected with random values and then called. * @param injectorConfig Allows injecting arbitrary values. * @return A generator for a value produced by the `$final method` of `obj`. */ function procedure(obj: any, injectorConfig?: Object) : QCGenerator; interface NumberGenerator extends QCGenerator { /** * Generates a larger version of the number. This can have a performance impact on your tests. */ large: QCGenerator; } interface IntGenerator extends NumberGenerator { /** * Generates an integer between `min` and `max`. */ between(min: number, max: number) : QCGenerator; } /** * Returns a number between zero and size. */ var intUpto : QCGenerator; /** * Generates a possitive real number. */ var ureal : NumberGenerator; /** * Generates a real number. */ var real : NumberGenerator; /** * Generates a positive integer. */ var uint : NumberGenerator; /** * Generates an integer. */ var int : IntGenerator; /** * Generates a natural number (like uint, but excluding zero). */ var natural: NumberGenerator; interface RangeGenerator { (generator?: QCGenerator) : QCGenerator<[number, number]>; /** * Generates an array of two numbers where the second is guaranteed to be greater or equal than the first. */ inclusive(generator?: QCGenerator) : QCGenerator<[number, number]>; } /** * Generates an array of two numbers where the second is guaranteed to be greater than the first. * By default the numbers are supplied by qc.real, but you can customize the generator. */ var range: RangeGenerator; /** * Generates a random number based on a D&D style dice string. * @param config A string that represents dics, i.e. `3d6`. */ function dice(config: string): QCGenerator; /** * Generates a random object based on a template object, where functions get * called with a size param to generate a random value. * @param template Any values will be copied verbatim, functions will get called. */ function objectLike(template: Object) : QCGenerator; /** * Generates an object where the values are produced by a suplied generator. * @param generator This generator will be called to produce the values. * @param keyGenerator This generator will be called to produce the keys. * By default this will be `qc.string`. * Remember that Objects have to have string keys. */ function objectOf(generator: QCGenerator, keyGenerator?: QCGenerator) : QCGenerator; /** * Generates a random object. */ var object : QCGenerator; /** * Generates a string of length 1. */ var char : QCGenerator; interface StringGenerator extends QCGenerator { /** * Generates a string containing only ascii characters. */ ascii: QCGenerator; /** * Generates a string by concatenating the results of all the generators passed in. * @param generators An array of generators that produce strings. */ concat(generators: QCGenerator[]) : QCGenerator; /** * Generates a string that matches a supplied regular expression. * @param pattern The pattern that will be used to produce the target string. */ matching(pattern: RegExp) : QCGenerator; } /** * Generates a completely random string. */ var string : StringGenerator; /** * Generates a random, but valid, date. */ var date : QCGenerator; interface AnyGenerator extends QCGenerator { /** * Generates a 'simple' value which could be a boolean, number, string, null or undefined. */ simple: QCGenerator; /** * Generates a random value, that will however not contain any functions. */ datatype: QCGenerator; } /** * Generates a completely random value. No assumptions about the type of the return value should be made. * However the current implementation only actually returns limited built-in types. */ var any : AnyGenerator; /** * Generates a valid web color string. */ var color: QCGenerator; /** * Generates a pair of lat, long coordinates. */ var location: QCGenerator<[number, number]>; /** * An ES6 compatible iterator structure. */ interface Iterator { next() : { value? : T, done: boolean } } /** * A shrinker is an object responsible for reducing data of a particular data type. */ interface Shrinker { /** * Returns whether the passed in value is applicable to the current shrinker. * Typically this will be a typecheck of some sort. */ valid(value: any) : boolean; /** * Should (preferably lazily) compute smaller versions of the value passed in. * To avoid non-termination, a smaller value shrunk should never produce the original value. */ shrinker(value: T) : Iterator; } /** * Reduces an arbitrary value to a smaller value. * @param value The value to shrink. * @param hint This can be a shrinker if you believe that this shrinker is applicable to the value in question. * This is a performance optimization. * @param registry By default the global registry of shrinkers will be used to perform shrinking. * This value allows you to override this. */ function shrink(value: T, hint?: Shrinker, registry?: Shrinker[]): Shrinker; /** * Constructs a shrinker and adds it to the global repository. * @param valid Returns whether the passed in value is applicable to the current shrinker. * Typically this will be a typecheck of some sort. * @param shrinker Should (preferably lazily) compute smaller versions of the value passed in. * To avoid non-termination, a smaller value shrunk should never produce the original value. */ function addShrinker(valid: (value: any) => boolean, shrinker: (value : T) => Iterator) : Shrinker; /** * Wraps a value in a generator. */ function of(value: T) : QCGenerator; /** * Applies a function to a generator producing a new generator. * Curried. * @param f A function that transforms a value into another value. * @param generator A generator that produces the initial value of f. */ function map(f: (arg: T) => U, generator: QCGenerator) : QCGenerator; function map(f: (arg: T) => U) : (generator: QCGenerator) => QCGenerator; /** * Unwraps generators of generators into generators. */ function join(generator: QCGenerator>) : QCGenerator; } declare module jasmine { interface Matchers { forAll(...generators : QCGenerator[]) : boolean; } } interface QUnitAssert { forAll(prop: (...values: any[]) => QCAssertionResult, ...generators : QCGenerator[]) : any; }