fast-check allows us to create composite generators that suit our testing needs. We'll generate two numbers to create a point simulating an X and Y and assert that the distance should always be greater than or equal to 0.
Transcript
[00:00] For this example I've created a distance function which takes a pair of two-dimensional points and returns how much distance is between them. FastCheck allows us to create composite generators. Here we're using the FastCheck.record generator and we're passing in the definition of the object that we want to generate, which in our case should match our point definition up here by taking an X and a Y, both integers. And when we use test.prop, we can pass in our point generator twice, which will give us two points to work with when we write our test. And finally the property that we want to assert here is that distances are always greater than or equal to zero.
[00:43] And if we run this test we can see that it passes.