From f86fd1774f899cb52f92b8a1aea66800cc90563a Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Wed, 24 Jan 2018 04:15:46 +0100 Subject: [PATCH] Update README.md --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/README.md b/README.md index 05e9079a501..010ac135ecf 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ It can be parametrized using its second argument. export interface Parameters { seed?: number; // optional, initial seed of the generator: Date.now() by default num_runs?: number; // optional, number of runs before success: 100 by default + logger?: (v: string) => void; // optional, log output: console.log by default } ``` @@ -106,6 +107,47 @@ interface Details { function check(property: IProperty, params?: Parameters); ``` +- `fc.sample`: sample generated values of an `Arbitrary` or `Property` + +It builds an array containing all the values that would have been generated for the equivalent test. + +It also accept `Parameters` as configuration in order to help you diagnose the shape of the inputs that will be received by your property. + +```typescript +function sample(generator: Arbitrary): Ts[]; +function sample(generator: Arbitrary, params: Parameters): Ts[]; +function sample(generator: Arbitrary, num_generated: number): Ts[]; + +function sample(generator: IProperty): Ts[]; +function sample(generator: IProperty, params: Parameters): Ts[]; +function sample(generator: IProperty, num_generated: number): Ts[]; +``` + +- `fc.statistics`: classify the values produced by an `Arbitrary` or `Property` + +It provides useful statistics concerning generated values. +In order to be able to gather those statistics it has to be provided with a classifier function that can classify the generated value in zero, one or more categories (free labels). + +It also accept `Parameters` as configuration in order to help you diagnose the shape of the inputs that will be received by your property. + +Statistics are dumped into `console.log` but can be redirected to another source by modifying the `logger` key in `Parameters`. + +```typescript +function statistics(generator: Arbitrary, classify: (v: Ts) => string): void; +function statistics(generator: Arbitrary, classify: (v: Ts) => string, params: Parameters): void; +function statistics(generator: Arbitrary, classify: (v: Ts) => string, num_generated: number): void; +function statistics(generator: Arbitrary, classify: (v: Ts) => string[]): void; +function statistics(generator: Arbitrary, classify: (v: Ts) => string[], params: Parameters): void; +function statistics(generator: Arbitrary, classify: (v: Ts) => string[], num_generated: number): void; + +function statistics(generator: IProperty, classify: (v: Ts) => string): void; +function statistics(generator: IProperty, classify: (v: Ts) => string, params: Parameters): void; +function statistics(generator: IProperty, classify: (v: Ts) => string, num_generated: number): void; +function statistics(generator: IProperty, classify: (v: Ts) => string[]): void; +function statistics(generator: IProperty, classify: (v: Ts) => string[], params: Parameters): void; +function statistics(generator: IProperty, classify: (v: Ts) => string[], num_generated: number): void; +``` + ## Arbitraries Arbitraries are responsible for the random generation (but deterministic) and shrink of datatypes.