test('sorting function should produce an array in non-decreasing order', () => // 'fc.array(fc.integer())' generates random arrays of random integers fc.assert( fc.property(fc.array(fc.integer()), (arr) => const sortedArr = sort(arr); for (let i = 0; i < sortedArr.length - 1; ++i) // Check that each element is less than or equal to the next one if (sortedArr[i] > sortedArr[i+1]) return false; // Property violated
: A traditional test might look like this:
FOR %%D IN (C D E) DO FASTCHECK %%D: /q /l
The update installed in silence. For one terrible second, her vision went black. Then the world reappeared—but sharper, almost painfully detailed. Every face on the concourse came with a floating tag: Exhaustion 94% | Malnutrition 31% | Desperation 67% . Her own tag, reflected in a window, read: Lina, Courier Grade B-12 | Efficiency 88% | Guilt 41% (trending up) . fast check v 0.39
Real-world applications process complex objects. Fast-check allows you to combine simple arbitraries into advanced shapes using fc.record and fc.array : typescript
// Property: For any array of integers, sorting it and then sorting it again should // produce the same result as sorting it just once. test('sorting is idempotent', () => fc.assert( fc.property(fc.array(fc.integer()), (data) => const sortedOnce = [...data].sort((a, b) => a - b); const sortedTwice = [...sortedOnce].sort((a, b) => a - b); return JSON.stringify(sortedOnce) === JSON.stringify(sortedTwice); ) ); );
To appreciate how far the framework has come, here are some key features introduced in later versions: Every face on the concourse came with a
: With faster verification times and automated checks, developers can focus more on writing code and less on manually testing and debugging.
For example, instead of testing a sorting function with just [3, 1, 2] , a property-based test would state a property like "for all arrays, the output should be sorted." The framework then generates hundreds or thousands of random arrays to test this property, a task that would be impossible to do manually.
Understanding these three concepts is essential for using fast-check effectively: Fast-check allows you to combine simple arbitraries into
: With Fast Check v0.39 up and running, start verifying your code. Begin with simple checks and gradually move on to more complex properties.
It just waited.
Avoid random "driver download" sites; many host trojans disguised as v0.39. Always verify the file hash against community-provided values.