I want to write a property-based unit test that proves that the integer subtraction is not commutative. I have this with mocha and fast-check:
const fc = require('fast-check')
describe('The subtraction', () => {
it('is not commutative', () => {
fc.assert(
fc.property(
fc.integer(), fc.integer(), (a, b) => a - b !== b - a
)
)
})
})
After several runs I noticed that it fails when the condition a === b && a <= 0
is true. However, I am not sure if there are any other conditions that do not comply with a - b !== b - a
, so I am not sure if excluding that specific condition is right.
How can I write the test? Should I exclude the specific condition? Or should I check that at a - b !== b - a
is true for at least two given values? Or is there any other way to test it?
Examples using any other kind of javascript libraries for property-based testing are welcome too.