### Install Kitimat with Jest Source: https://github.com/garbles/kitimat/blob/master/README.md Command to install Kitimat, Kitimat-Jest, and Jest as development dependencies. ```bash yarn install kitimat kitimat-jest jest --dev ``` -------------------------------- ### Kitimat Boolean Fuzzer Example Source: https://github.com/garbles/kitimat/blob/master/README.md Shows how to create and use a boolean Fuzzer with the `check` function. The fuzzer generates boolean values that are then passed to the test callback. ```typescript import { check, Fuzzer, boolean } from 'kitimat-jest'; import { someFunc } from './some-func'; const fuzzer: Fuzzer = boolean(); check('something', [fuzzer], val => { expect(typeof val).toEqual('boolean'); expect(someFunc(val)).toEqual(true); }); ``` -------------------------------- ### Basic Kitimat Jest Example Source: https://github.com/garbles/kitimat/blob/master/README.md Demonstrates a typical Kitimat test suite using Jest. It includes a standard Jest test and property-based checks for sorting an array of integers. ```typescript // my-sort.test.ts import { check, integer, array } from 'kitimat-jest'; import { sort } from './my-sort'; it('sorts some numbers', () => { const sorted = sort([6, 1, 2]); expect(sorted).toEqual([1, 2, 6]); }); check('length does not change', [array(integer())], arr => { const sorted = sort(arr); expect(sorted.length).toEqual(arr.length); }); check('idempotent', [array(integer())], arr => { const once = sort(arr); const twice = sort(sort(arr)); expect(once).toEqual(twice); }); check('ordered', [array(integer())], arr => { const sorted = sort(arr); for (let i = 0; i < sorted.length; i++) { const prev = sorted[i]; const next = sorted[i + 1]; expect(prev).toBeLessThanOrEqual(next); } }); ``` -------------------------------- ### Configure Kitimat with cosmiconfig Source: https://context7.com/garbles/kitimat/llms.txt Configure Kitimat using standard configuration files like `.kitimatrc`, `kitimat.config.js`, or the `kitimat` key in `package.json`. ```javascript // kitimat.config.js module.exports = { maxNumTests: 100, // Number of test cases per property (default: 100) seed: 12345, // Fixed seed for reproducible tests (default: Date.now()) timeout: 5000, // Jest timeout in milliseconds (default: 5000) }; // .kitimatrc (JSON format) { "maxNumTests": 200, "seed": 42, "timeout": 10000 } // package.json { "kitimat": { "maxNumTests": 100, "seed": 12345 } } ``` -------------------------------- ### Kitimat Configuration Source: https://github.com/garbles/kitimat/blob/master/README.md Configuration options for Kitimat, which can be set in a .kitimatrc file, kitimat.config.js, or the 'kitimat' key in package.json. ```APIDOC ## Configuration Options Kitimat uses cosmiconfig for configuration. You can set options in: - `.kitimatrc` - `kitimat.config.js` - `package.json` (under the `"kitimat"` key) These values can be overridden on a test-by-test basis. ### `maxNumTests: number = 100` The number of test cases generated for each property. Defaults to 100. ### `seed: number = Date.now()` The seed for generating pseudo-random values. If set to a constant, the same values will be generated on every run. Otherwise, Kitimat uses `Date.now()`. This can be overridden by the `KITIMAT_SEED` environment variable. ### `timeout: number = 5000` Jest only. The number of milliseconds for a single property before Jest triggers a timeout error. ``` -------------------------------- ### Define a Counter Model and Oracle for kitimat-model Source: https://context7.com/garbles/kitimat/llms.txt This snippet demonstrates defining a state machine model and an oracle for testing a counter. It includes states, actions, and validation logic. ```typescript import { Graph, State, Action, Branch } from 'kitimat-model'; import { constant, integer, Fuzzer } from 'kitimat'; // Define your model (abstract representation) type CounterModel = { count: number }; // Define your oracle (actual system under test) class CounterOracle { private value = 0; increment() { this.value++; } decrement() { this.value--; } getValue() { return this.value; } } // Define states const zeroState: State = { name: 'zero', branches: [], description: (model) => `Counter at zero (model: ${model.count})`, validate: (model, oracle) => { return model.count === 0 && oracle.getValue() === 0; }, }; const positiveState: State = { name: 'positive', branches: [], description: (model) => `Counter positive (model: ${model.count})`, validate: (model, oracle) => { return model.count > 0 && oracle.getValue() === model.count; }, }; // Define actions const incrementAction: Action = { fuzzer: constant(undefined), apply: (model, oracle) => { oracle.increment(); }, description: () => 'Increment counter', nextModel: (model) => ({ count: model.count + 1 }), preValidate: () => true, postValidate: (prev, next, oracle) => oracle.getValue() === next.count, }; // Build the graph const graph = new Graph(zeroState, { count: 0 }); graph.addState(positiveState); graph.addBranch(zeroState, positiveState, incrementAction); ``` -------------------------------- ### Create Tuple Fuzzer with zip5() Source: https://github.com/garbles/kitimat/blob/master/README.md Use `zip5()` to create a Fuzzer for a five-element tuple. It takes five fuzzers as arguments, one for each element of the tuple. ```typescript import { check, Fuzzer, zip5, integer } from 'kitimat-jest'; import { someFunc } from './some-func'; const fuzzer: Fuzzer<[number, number, number, number, number]> = zip5( integer(), integer(), integer(), integer(), integer(), ); check('something', [fuzzer], val => { expect(Array.isArray(true)).toEqual(true); expect(val.every(x => typeof x === 'number')).toEqual(true); expect(val).toHaveLength(5); expect(someFunc(val)).toEqual(true); }); ``` -------------------------------- ### Create a String Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Use `string` to create a Fuzzer that generates arbitrary strings. Options can specify a maximum size. ```typescript import { check, Fuzzer, string } from 'kitimat-jest'; import { someFunc } from './some-func'; const fuzzer: Fuzzer = string(); check('something', [fuzzer], val => { expect(typeof val).toEqual('string'); expect(someFunc(val)).toEqual(true); }); ``` -------------------------------- ### Create Tuple Fuzzer with zip3() Source: https://github.com/garbles/kitimat/blob/master/README.md Use `zip3()` to create a Fuzzer for a three-element tuple. It takes three fuzzers as arguments, one for each element of the tuple. ```typescript import { check, Fuzzer, zip3, integer } from 'kitimat-jest'; import { someFunc } from './some-func'; const fuzzer: Fuzzer<[number, number, number]> = zip3(integer(), integer(), integer()); check('something', [fuzzer], val => { expect(Array.isArray(true)).toEqual(true); expect(val.every(x => typeof x === 'number')).toEqual(true); expect(val).toHaveLength(3); expect(someFunc(val)).toEqual(true); }); ``` -------------------------------- ### Create Tuple Fuzzer with zip() Source: https://github.com/garbles/kitimat/blob/master/README.md Use `zip()` to create a Fuzzer for a two-element tuple. It takes two fuzzers as arguments, one for each element of the tuple. ```typescript import { check, Fuzzer, zip, integer } from 'kitimat-jest'; import { someFunc } from './some-func'; const fuzzer: Fuzzer<[number, number]> = zip(integer(), integer()); check('something', [fuzzer], val => { expect(Array.isArray(true)).toEqual(true); expect(val.every(x => typeof x === 'number')).toEqual(true); expect(val).toHaveLength(2); expect(someFunc(val)).toEqual(true); }); ``` -------------------------------- ### Create Tuple Fuzzer with zip4() Source: https://github.com/garbles/kitimat/blob/master/README.md Use `zip4()` to create a Fuzzer for a four-element tuple. It takes four fuzzers as arguments, one for each element of the tuple. ```typescript import { check, Fuzzer, zip4, integer } from 'kitimat-jest'; import { someFunc } from './some-func'; const fuzzer: Fuzzer<[number, number, number, number]> = zip4(integer(), integer(), integer(), integer()); check('something', [fuzzer], val => { expect(Array.isArray(true)).toEqual(true); expect(val.every(x => typeof x === 'number')).toEqual(true); expect(val).toHaveLength(4); expect(someFunc(val)).toEqual(true); }); ``` -------------------------------- ### Create an ASCII String Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Use `asciiString` to create a Fuzzer that generates arbitrary ASCII strings. Options can specify a maximum size. ```typescript import { check, Fuzzer, asciiString } from 'kitimat-jest'; import { someFunc } from './some-func'; const fuzzer: Fuzzer = asciiString(); check('something', [fuzzer], val => { expect(typeof val).toEqual('string'); expect(someFunc(val)).toEqual(true); }); ``` -------------------------------- ### Create an Integer Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Use `integer` to create a Fuzzer that generates arbitrary integers. Options can specify size constraints. ```typescript import { check, Fuzzer, integer } from 'kitimat-jest'; import { someFunc } from './some-func'; const fuzzer: Fuzzer = integer(); check('something', [fuzzer], val => { expect(typeof val).toEqual('number'); expect(someFunc(val)).toEqual(true); }); ``` -------------------------------- ### Create a Positive Float Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Use `posFloat` to create a Fuzzer that generates non-negative floating-point numbers. Options can specify a maximum size. ```typescript import { check, Fuzzer, posFloat } from 'kitimat-jest'; import { someFunc } from './some-func'; const fuzzer: Fuzzer = posFloat(); check('something', [fuzzer], val => { expect(val).toBeGreaterThanOrEqual(0); expect(someFunc(val)).toEqual(true); }); ``` -------------------------------- ### Create a Number Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Use `number` to create a Fuzzer that generates arbitrary numbers. Options can specify size constraints. ```typescript import { check, Fuzzer, number } from 'kitimat-jest'; import { someFunc } from './some-func'; const fuzzer: Fuzzer = number(); check('something', [fuzzer], val => { expect(typeof val).toEqual('number'); expect(someFunc(val)).toEqual(true); }); ``` -------------------------------- ### Create a Float Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Use `float` to create a Fuzzer that generates arbitrary floating-point numbers. Options can specify size constraints. ```typescript import { check, float } from 'kitimat-jest'; import { someFunc } from './some-func'; const fuzzer: Fuzzer = float(); check('something', [fuzzer], val => { expect(typeof val).toEqual('number'); expect(someFunc(val)).toEqual(true); }); ``` -------------------------------- ### array(a: Fuzzer, opts?: { maxSize?: number }): Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Takes a Fuzzer of some type and creates an array Fuzzer of that type. This allows for generating arrays of specific data types with a maximum size constraint. ```APIDOC ## array(a: Fuzzer, opts?: { maxSize?: number }): Fuzzer ### Description Takes a Fuzzer of some type and creates an array Fuzzer of that type. This allows for generating arrays of specific data types with a maximum size constraint. ### Method N/A (This is a function to create a Fuzzer, not an API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ts import { array, integer } from 'kitimat-jest'; const fuzzer = array(integer(), { maxSize: 10 }); ``` ### Response #### Success Response (200) N/A (This function returns a Fuzzer object) #### Response Example ```json { "type": "Fuzzer", "elementFuzzer": { "type": "Fuzzer" }, "maxSize": 10 } ``` ``` -------------------------------- ### Create Weighted Fuzzer with Frequency Source: https://context7.com/garbles/kitimat/llms.txt Use `frequency` to create a Fuzzer that selects from multiple Fuzzers with specified relative weights. Weights determine the probability distribution. ```typescript import { check, frequency, posInteger, negInteger, constant, Fuzzer } from 'kitimat-jest'; // 90% positive integers, 10% negative integers const mostlyPositive: Fuzzer = frequency([ [9, posInteger()], [1, negInteger()], ]); // Custom distribution with specific values const specialNumbers: Fuzzer = frequency([ [5, constant(0)], // 50% zeros [3, posInteger()], // 30% positive [2, negInteger()], // 20% negative ]); check('mostly positive numbers', [mostlyPositive], (num) => { expect(typeof num).toEqual('number'); }); ``` -------------------------------- ### string(opts?: { maxSize?: number }): Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Creates a string Fuzzer. This fuzzer generates random strings up to a specified maximum length. ```APIDOC ## string(opts?: { maxSize?: number }): Fuzzer ### Description Creates a string Fuzzer. This fuzzer generates random strings up to a specified maximum length. ### Method N/A (This is a function to create a Fuzzer, not an API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ts import { string } from 'kitimat-jest'; const fuzzer = string({ maxSize: 100 }); ``` ### Response #### Success Response (200) N/A (This function returns a Fuzzer object) #### Response Example ```json { "type": "Fuzzer", "maxSize": 100 } ``` ``` -------------------------------- ### asciiString(opts?: { maxSize?: number }): Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Creates an ASCII string Fuzzer. This fuzzer generates random ASCII strings up to a specified maximum length. ```APIDOC ## asciiString(opts?: { maxSize?: number }): Fuzzer ### Description Creates an ASCII string Fuzzer. This fuzzer generates random ASCII strings up to a specified maximum length. ### Method N/A (This is a function to create a Fuzzer, not an API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ts import { asciiString } from 'kitimat-jest'; const fuzzer = asciiString({ maxSize: 50 }); ``` ### Response #### Success Response (200) N/A (This function returns a Fuzzer object) #### Response Example ```json { "type": "Fuzzer", "maxSize": 50 } ``` ``` -------------------------------- ### Create a Negative Integer Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Use `negInteger` to create a Fuzzer that generates non-positive integers. Options can specify a minimum size. ```typescript import { check, Fuzzer, negInteger } from 'kitimat-jest'; import { someFunc } from './some-func'; const fuzzer: Fuzzer = negInteger(); check('something', [fuzzer], val => { expect(val).toBeLessThanOrEqual(0); expect(someFunc(val)).toEqual(true); }); ``` -------------------------------- ### integer(opts?: { minSize?: number, maxSize?: number }): Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Creates an integer Fuzzer. This fuzzer can generate random integers within specified size constraints. ```APIDOC ## integer(opts?: { minSize?: number, maxSize?: number }): Fuzzer ### Description Creates an integer Fuzzer. This fuzzer can generate random integers within specified size constraints. ### Method N/A (This is a function to create a Fuzzer, not an API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ts import { integer } from 'kitimat-jest'; const fuzzer = integer({ minSize: 1, maxSize: 100 }); ``` ### Response #### Success Response (200) N/A (This function returns a Fuzzer object) #### Response Example ```json { "type": "Fuzzer", "minSize": 1, "maxSize": 100 } ``` ``` -------------------------------- ### Frequency Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Creates a fuzzer that generates values based on specified weights for different fuzzers. ```APIDOC ## frequency(arr: [number, Fuzzer][]): Fuzzer ### Description Takes a list of tuples (`[number, Fuzzer]`) and returns a Fuzzer of weighted values. ### Method `frequency(arr: [number, Fuzzer][]): Fuzzer` ### Parameters #### Request Body - **arr** (Array<[number, Fuzzer]>) - Required - An array of tuples, where each tuple contains a weight (number) and a Fuzzer. ### Request Example ```typescript import { Fuzzer, frequency, posInteger, negInteger } from 'kitimat-jest'; /** * 90% of generated values will be positive integers, 10% negative integers. */ const fuzzer: Fuzzer = frequency([ [9, posInteger()], [1, negInteger()]; ]) ``` ### Response #### Success Response (200) - **Fuzzer** - A Fuzzer that generates values according to the specified weights. #### Response Example ```json 123 ``` ``` -------------------------------- ### Create a Negative Float Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Use `negFloat` to create a Fuzzer that generates non-positive floating-point numbers. Options can specify a minimum size. ```typescript import { check, Fuzzer, negFloat } from 'kitimat-jest'; import { someFunc } from './some-func'; const fuzzer: Fuzzer = negFloat(); check('something', [fuzzer], val => { expect(val).toBeLessThanOrEqual(0); expect(someFunc(val)).toEqual(true); }); ``` -------------------------------- ### Create an Array Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Use `array` to create a Fuzzer that generates arrays of a specified element type. Requires a Fuzzer for the element type and optionally accepts size constraints. ```typescript import { check, Fuzzer, array, integer } from 'kitimat-jest'; import { someFunc } from './some-func'; const fuzzer: Fuzzer = array(integer()); check('something', [fuzzer], val => { expect(Array.isArray(true)).toEqual(true); expect(val.every(x => typeof x === 'number')).toEqual(true); expect(someFunc(val)).toEqual(true); }); ``` -------------------------------- ### Create a Positive Integer Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Use `posInteger` to create a Fuzzer that generates non-negative integers. Options can specify a maximum size. ```typescript import { check, Fuzzer, posInteger } from 'kitimat-jest'; import { someFunc } from './some-func'; const fuzzer: Fuzzer = posInteger(); check('something', [fuzzer], val => { expect(val).toBeGreaterThanOrEqual(0); expect(someFunc(val)).toEqual(true); }); ``` -------------------------------- ### Fuzzer - integer Source: https://context7.com/garbles/kitimat/llms.txt Creates a Fuzzer that generates random integer values within optional bounds. Defaults to range [-1e9, 1e9]. Automatically shrinks toward 0 or the minimum value. ```APIDOC ## integer - Integer Fuzzer ### Description Generates random integer values. Supports optional minimum and maximum bounds. Automatically shrinks failing test cases towards 0 or the minimum bound. ### Method `integer` (function) ### Endpoint N/A (This is a library function, not an API endpoint) ### Parameters - **options** (object) - Optional - Configuration options for the integer fuzzer. - **minSize** (number) - Optional - The minimum value for the generated integer. Defaults to -1e9. - **maxSize** (number) - Optional - The maximum value for the generated integer. Defaults to 1e9. ### Request Example ```typescript import { check, integer, Fuzzer } from 'kitimat-jest'; // Default integer fuzzer const intFuzzer: Fuzzer = integer(); // Bounded integer fuzzer const boundedInt: Fuzzer = integer({ minSize: -100, maxSize: 100 }); check('integer in range', [integer({ minSize: 0, maxSize: 10 })], (num) => { expect(Number.isInteger(num)).toBe(true); expect(num).toBeGreaterThanOrEqual(0); expect(num).toBeLessThanOrEqual(10); }); ``` ### Response - **Fuzzer** - A Fuzzer instance that generates integer values. ``` -------------------------------- ### Create Equal-Weight Selection Fuzzer with oneOf Source: https://context7.com/garbles/kitimat/llms.txt Use `oneOf` for uniform distribution across multiple Fuzzers. Simpler syntax than `frequency` when all options have equal probability. ```typescript import { check, oneOf, constant, integer, string, Fuzzer } from 'kitimat-jest'; // Equally likely to be any of these values const primaryColors: Fuzzer = oneOf([ constant('red'), constant('green'), constant('blue'), ]); // Mix of different types with equal probability const mixedTypes: Fuzzer = oneOf([ integer({ minSize: 0, maxSize: 10 }), integer({ minSize: 100, maxSize: 200 }), constant(42), ]); check('primary colors', [primaryColors], (color) => { expect(['red', 'green', 'blue']).toContain(color); }); ``` -------------------------------- ### Create a Constant Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Use `constant` to wrap a fixed value in a Fuzzer. This is useful for testing scenarios where a specific input is always expected. ```typescript import { check, Fuzzer, constant } from 'kitimat-jest'; import { someFunc } from './some-func'; const fuzzer: Fuzzer = constant('my string'); check('something', [fuzzer], val => { expect(val).toEqual('my string'); expect(someFunc(val)).toEqual(true); }); ``` -------------------------------- ### posFloat(opts?: { maxSize?: number }): Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Creates a positive float Fuzzer. This fuzzer generates non-negative floating-point numbers up to a specified maximum size. ```APIDOC ## posFloat(opts?: { maxSize?: number }): Fuzzer ### Description Creates a positive float Fuzzer. This fuzzer generates non-negative floating-point numbers up to a specified maximum size. ### Method N/A (This is a function to create a Fuzzer, not an API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ts import { posFloat } from 'kitimat-jest'; const fuzzer = posFloat({ maxSize: 50.5 }); ``` ### Response #### Success Response (200) N/A (This function returns a Fuzzer object) #### Response Example ```json { "type": "Fuzzer", "minSize": 0.0, "maxSize": 50.5 } ``` ``` -------------------------------- ### maybe API Source: https://github.com/garbles/kitimat/blob/master/README.md The maybe method creates a Fuzzer that can optionally return undefined for a given Fuzzer type. ```APIDOC ## maybe(a: Fuzzer): Fuzzer ### Description Takes a Fuzzer and creates a new Fuzzer where the value is either the type of the original Fuzzer or `undefined`. _*Also an instance method on Fuzzer._ ### Method Instance method on Fuzzer or static function. ### Endpoint N/A (Instance method or static function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ts import { check, Fuzzer, string } from 'kitimat-jest'; import { someFunc } from './some-func'; const fuzzer: Fuzzer = string().maybe(); check('something', [fuzzer], val => { expect(someFunc(val)).toEqual(true); }); ``` ### Response #### Success Response (200) N/A (Instance method or static function) #### Response Example N/A ``` -------------------------------- ### float(opts?: { minSize?: number, maxSize?: number }): Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Creates a float Fuzzer. This fuzzer can generate random floating-point numbers within specified size constraints. ```APIDOC ## float(opts?: { minSize?: number, maxSize?: number }): Fuzzer ### Description Creates a float Fuzzer. This fuzzer can generate random floating-point numbers within specified size constraints. ### Method N/A (This is a function to create a Fuzzer, not an API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ts import { float } from 'kitimat-jest'; const fuzzer = float({ minSize: 0.1, maxSize: 10.5 }); ``` ### Response #### Success Response (200) N/A (This function returns a Fuzzer object) #### Response Example ```json { "type": "Fuzzer", "minSize": 0.1, "maxSize": 10.5 } ``` ``` -------------------------------- ### negInteger(opts?: { minSize?: number }): Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Creates a negative integer Fuzzer. This fuzzer generates non-positive integers down to a specified minimum size. ```APIDOC ## negInteger(opts?: { minSize?: number }): Fuzzer ### Description Creates a negative integer Fuzzer. This fuzzer generates non-positive integers down to a specified minimum size. ### Method N/A (This is a function to create a Fuzzer, not an API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ts import { negInteger } from 'kitimat-jest'; const fuzzer = negInteger({ minSize: -50 }); ``` ### Response #### Success Response (200) N/A (This function returns a Fuzzer object) #### Response Example ```json { "type": "Fuzzer", "minSize": -50, "maxSize": 0 } ``` ``` -------------------------------- ### number(opts?: { minSize?: number, maxSize?: number }): Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Creates a number Fuzzer. This fuzzer can generate random numbers within specified size constraints. ```APIDOC ## number(opts?: { minSize?: number, maxSize?: number }): Fuzzer ### Description Creates a number Fuzzer. This fuzzer can generate random numbers within specified size constraints. ### Method N/A (This is a function to create a Fuzzer, not an API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ts import { number } from 'kitimat-jest'; const fuzzer = number({ minSize: 1, maxSize: 100 }); ``` ### Response #### Success Response (200) N/A (This function returns a Fuzzer object) #### Response Example ```json { "type": "Fuzzer", "minSize": 1, "maxSize": 100 } ``` ``` -------------------------------- ### Create Weighted Fuzzer with frequency() Source: https://github.com/garbles/kitimat/blob/master/README.md Use `frequency()` to create a Fuzzer that generates values based on specified weights. It takes an array of tuples, where each tuple contains a weight and a Fuzzer. ```typescript import { check, Fuzzer, frequency, posInteger, negInteger } from 'kitimat-jest'; import { someFunc } from './some-func'; /** * 90% of generated values will be positive integers, 10% negative integers. */ const fuzzer: Fuzzer = frequency([ [9, posInteger()], [1, negInteger()]; ]) check('something', [fuzzer], val => { expect(typeof val).toEqual('number'); expect(someFunc(val)).toEqual(true); }); ``` -------------------------------- ### Kitimat Check API Usage Source: https://github.com/garbles/kitimat/blob/master/README.md Illustrates various ways to use the `check` function from Kitimat Jest, including with multiple fuzzers, async/await, `done` callback, and skip/only modifiers. ```typescript import { check, boolean, integer, string } from 'kitimat-jest'; import { someFunc } from './some-func'; check('something', [boolean(), integer(), string()], (bool, int, str) => { expect(typeof bool).toEqual('boolean'); expect(typeof int).toEqual('number'); expect(typeof str).toEqual('string'); }); /** * Use async/await with same behavior as Jest it. */ check('something async', [boolean()], async bool => { const result = await someFunc(bool); expect(result).toEqual(true); }); /** * Use done with same behavior as Jest it. */ check('something async with done', [boolean()], async (bool, done) => { someFunc(bool).then(result => { expect(result).toEqual(true); done(); }); }); /** * Same behavior as Jest it. This test will be skipped. */ check.skip('skip something', [boolean()], bool => { // ... }); /** * Same behavior as Jest it. This is the only test in the suite that will run. */ check.only('only run this thing', [string()], str => { // ... }); ``` -------------------------------- ### Array Fuzzer with Element Fuzzer Source: https://context7.com/garbles/kitimat/llms.txt Creates an array fuzzer by providing an element fuzzer. Supports maximum size and shrinks by removing elements or shrinking individual elements. ```typescript import { check, array, integer, string, Fuzzer } from 'kitimat-jest'; const intArray: Fuzzer = array(integer()); const shortStringArray: Fuzzer = array(string(), { maxSize: 5 }); check('array of integers', [array(integer({ minSize: 0, maxSize: 100 }))], (arr) => { expect(Array.isArray(arr)).toBe(true); arr.forEach(item => { expect(typeof item).toEqual('number'); expect(item).toBeGreaterThanOrEqual(0); }); }); ``` ```typescript import { sort } from './my-sort'; check('sort preserves length', [array(integer())], (arr) => { expect(sort(arr).length).toEqual(arr.length); }); check('sort is idempotent', [array(integer())], (arr) => { expect(sort(arr)).toEqual(sort(sort(arr))); }); check('sort produces ordered output', [array(integer())], (arr) => { const sorted = sort(arr); for (let i = 0; i < sorted.length - 1; i++) { expect(sorted[i]).toBeLessThanOrEqual(sorted[i + 1]); } }); ``` -------------------------------- ### Kitimat Exists API Usage Source: https://github.com/garbles/kitimat/blob/master/README.md Demonstrates the `exists` function from Kitimat Jest, which is similar to `check` but completes on the first successful test case and fails if no success is found within the configured number of tests. ```typescript import { exists, boolean } from 'kitimat-jest'; exists('something async', [boolean()], async bool => { expect(result).toEqual(true); }); ``` -------------------------------- ### exists API Source: https://github.com/garbles/kitimat/blob/master/README.md The `exists` function is similar to `check` but completes on the first successful test case and fails if no successful test case is found within the configured number of attempts. ```APIDOC ## `exists(description: string, fuzzers: Fuzzer[], callback: Function, options: Options): void` A light wrapper around Jest `it`, but accepts a list of Fuzzers and generates values, passing them into the `it` callback. Similar to `check` except that it completes on the first successful test case. `exists` fails if it does not find a successful test case after the configured number of test cases. ### Parameters - **description** (string) - Required - A description of the test case. - **fuzzers** (Fuzzer[]) - Required - An array of Fuzzer instances to generate test data. - **callback** (Function) - Required - The test function that receives the generated values. - **options** (Options) - Optional - Configuration options for the check. ### Request Example ```ts import { exists, boolean } from 'kitimat-jest'; exists('something async', [boolean()], async bool => { expect(result).toEqual(true); }); ``` ``` -------------------------------- ### Combine Fuzzers into Tuple Fuzzers Source: https://context7.com/garbles/kitimat/llms.txt Use `zip`, `zip3`, `zip4`, and `zip5` to create Fuzzers that generate coordinated values in tuples. Ensures generated values are linked. ```typescript import { check, zip, zip3, zip4, zip5, integer, string, boolean, Fuzzer } from 'kitimat-jest'; const pair: Fuzzer<[number, number]> = zip(integer(), integer()); const triple: Fuzzer<[number, string, boolean]> = zip3(integer(), string(), boolean()); const quad: Fuzzer<[number, number, number, number]> = zip4(integer(), integer(), integer(), integer()); const quint: Fuzzer<[number, number, number, number, number]> = zip5( integer(), integer(), integer(), integer(), integer() ); check('tuple pair', [zip(integer(), string())], ([num, str]) => { expect(typeof num).toEqual('number'); expect(typeof str).toEqual('string'); }); check('point coordinates', [zip(integer(), integer())], ([x, y]) => { const distance = Math.sqrt(x * x + y * y); expect(distance).toBeGreaterThanOrEqual(0); }); ``` -------------------------------- ### negFloat(opts?: { minSize?: number }): Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Creates a negative float Fuzzer. This fuzzer generates non-positive floating-point numbers down to a specified minimum size. ```APIDOC ## negFloat(opts?: { minSize?: number }): Fuzzer ### Description Creates a negative float Fuzzer. This fuzzer generates non-positive floating-point numbers down to a specified minimum size. ### Method N/A (This is a function to create a Fuzzer, not an API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ts import { negFloat } from 'kitimat-jest'; const fuzzer = negFloat({ minSize: -50.5 }); ``` ### Response #### Success Response (200) N/A (This function returns a Fuzzer object) #### Response Example ```json { "type": "Fuzzer", "minSize": -50.5, "maxSize": 0.0 } ``` ``` -------------------------------- ### Create Optional Values with maybe Source: https://context7.com/garbles/kitimat/llms.txt Wrap a Fuzzer with `maybe` to generate either the value or `undefined`. The default distribution is 75% value and 25% undefined. ```typescript import { check, maybe, string, integer, Fuzzer } from 'kitimat-jest'; // Using function form const maybeInt: Fuzzer = maybe(integer()); // Using instance method const optionalString: Fuzzer = string().maybe(); check('optional value handling', [string().maybe()], (val) => { if (val !== undefined) { expect(typeof val).toEqual('string'); } else { expect(val).toBeUndefined(); } }); // Testing optional fields type Config = { required: string; optional: string | void; }; check('config with optional field', [ object({ required: string(), optional: string().maybe(), }) ], (config) => { expect(config.required).toBeDefined(); // optional may or may not be defined }); ``` -------------------------------- ### Existential Property Test - exists Source: https://context7.com/garbles/kitimat/llms.txt The `exists` function is similar to `check` but completes successfully on the first passing test case instead of running all iterations. It fails only if no passing case is found after `maxNumTests` attempts. Use this when you need to verify that at least one value satisfies a property. ```APIDOC ## exists - Existential Property Test ### Description Verifies if at least one generated value satisfies a given property. It stops and succeeds on the first passing test case, failing only if no passing case is found within the maximum number of attempts. ### Method `exists` (function) ### Endpoint N/A (This is a library function, not an API endpoint) ### Parameters - **name** (string) - Required - A descriptive name for the test. - **fuzzers** (Array>) - Required - An array of Fuzzer instances to generate test values. - **callback** (function) - Required - The test callback function that receives generated values as arguments. The test passes if the callback assertions succeed. - **options** (object) - Optional - Configuration options for the test runner. - **maxNumTests** (number) - Optional - The maximum number of test iterations to attempt. Defaults to 100. - **seed** (number) - Optional - A seed for the random number generator to ensure reproducible tests. ### Request Example ```typescript import { exists, integer, string } from 'kitimat-jest'; exists('some integer is greater than 50', [integer()], (num) => { expect(num).toBeGreaterThan(50); }); ``` ### Response N/A (This function executes tests and relies on Jest for reporting results.) ``` -------------------------------- ### flatMap API Source: https://github.com/garbles/kitimat/blob/master/README.md The flatMap method transforms a Fuzzer by applying a function that returns a new Fuzzer. It's useful for creating more complex data generation logic. ```APIDOC ## flatMap(fn: (a: A) => Fuzzer | Promise>, a: Fuzzer): Fuzzer ### Description Takes a mapping function that returns a new Fuzzer and a Fuzzer. Maps all generated values to create a new Fuzzer of a new type. _*Also an instance method on Fuzzer._ ### Method Instance method on Fuzzer or static function. ### Endpoint N/A (Instance method or static function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ts import { check, Fuzzer, string, array, constant } from 'kitimat-jest'; import { someFunc } from './some-func'; const fuzzer: Fuzzer = string().flatMap(str => { return array(constant(str)); }); check('something', [fuzzer], val => { expect(Array.isArray(true)).toEqual(true); expect(val.every(x => typeof x === 'string')).toEqual(true); expect(someFunc(val)).toEqual(true); }); ``` ### Response #### Success Response (200) N/A (Instance method or static function) #### Response Example N/A ``` -------------------------------- ### Fuzzer - boolean Source: https://context7.com/garbles/kitimat/llms.txt Creates a Fuzzer that generates random boolean values with automatic shrinking toward `false`. ```APIDOC ## boolean - Boolean Fuzzer ### Description Generates random boolean values (`true` or `false`). Automatically shrinks failing test cases towards `false`. ### Method `boolean` (function) ### Endpoint N/A (This is a library function, not an API endpoint) ### Parameters None ### Request Example ```typescript import { check, boolean, Fuzzer } from 'kitimat-jest'; const boolFuzzer: Fuzzer = boolean(); check('boolean properties', [boolean()], (val) => { expect(typeof val).toEqual('boolean'); expect([true, false]).toContain(val); }); ``` ### Response - **Fuzzer** - A Fuzzer instance that generates boolean values. ``` -------------------------------- ### posInteger(opts?: { maxSize?: number }): Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Creates a positive integer Fuzzer. This fuzzer generates non-negative integers up to a specified maximum size. ```APIDOC ## posInteger(opts?: { maxSize?: number }): Fuzzer ### Description Creates a positive integer Fuzzer. This fuzzer generates non-negative integers up to a specified maximum size. ### Method N/A (This is a function to create a Fuzzer, not an API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ts import { posInteger } from 'kitimat-jest'; const fuzzer = posInteger({ maxSize: 50 }); ``` ### Response #### Success Response (200) N/A (This function returns a Fuzzer object) #### Response Example ```json { "type": "Fuzzer", "minSize": 0, "maxSize": 50 } ``` ``` -------------------------------- ### Create a Positive Number Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Use `posNumber` to create a Fuzzer that generates non-negative numbers. Options can specify a maximum size. ```typescript import { check, Fuzzer, posNumber } from 'kitimat-jest'; import { someFunc } from './some-func'; const fuzzer: Fuzzer = posNumber(); check('something', [fuzzer], val => { expect(val).toBeGreaterThanOrEqual(0); expect(someFunc(val)).toEqual(true); }); ``` -------------------------------- ### Object Fuzzer Source: https://github.com/garbles/kitimat/blob/master/README.md Creates a Fuzzer for an object type by providing fuzzers for each of its properties. ```APIDOC ## object({ [K in keyof A]: Fuzzer }): Fuzzer ### Description Takes an object where the values are fuzzers and creates an object Fuzzer of that type. ### Method `object(properties: { [K in keyof A]: Fuzzer }): Fuzzer` ### Parameters #### Request Body - **properties** (object) - Required - An object where keys are property names and values are Fuzzers for those properties. ### Request Example ```typescript import { Fuzzer, object, asciiString, posInteger } from 'kitimat-jest'; type Person = { name: string; age: number; }; const fuzzer: Fuzzer = object({ name: asciiString(), age: posInteger(), }); ``` ### Response #### Success Response (200) - **Fuzzer** - A Fuzzer that generates objects of type A. #### Response Example ```json { "name": "exampleName", "age": 123 } ``` ```