Skip to content

Instantly share code, notes, and snippets.

@MattMcFarland
Last active March 15, 2017 06:58
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/e07cb064c5212a9ebcaa4d87f5696981 to your computer and use it in GitHub Desktop.
Save MattMcFarland/e07cb064c5212a9ebcaa4d87f5696981 to your computer and use it in GitHub Desktop.
An example of what happens when JS Verify fails a test
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 additionIsCommunative = 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)
const subtractionIsCommutative = jsc.checkForall(jsc.integer, jsc.integer,
(a, b) => a - b === b - a)
// log out whether or not the test passed
console.log({ additionIsCommunative, multiplicationIsDistributive, subtractionIsCommutative })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment