Skip to content

Instantly share code, notes, and snippets.

@MattMcFarland
Last active March 15, 2017 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattMcFarland/bc2b688ef324e8a9d1e1fabc5cdb538b to your computer and use it in GitHub Desktop.
Save MattMcFarland/bc2b688ef324e8a9d1e1fabc5cdb538b to your computer and use it in GitHub Desktop.
A simple example using JS Verify
const jsc = require('jsverify')
// With property based testing, we don't check for specific inputs and outputs, instead we are testing the boundaries of our code.
const additionIsCommutative = jsc.checkForall(jsc.integer, jsc.integer,
(a, b) => a + b === b + a)
const multiplicationIsDistributive = jsc.checkForall(jsc.integer, jsc.integer, jsc.integer,
(a, b, c) => a * (b + c) === a * b + a * c)
// log out whether or not the test passed
console.log({ additionIsCommutative, multiplicationIsDistributive })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment