Skip to content

Instantly share code, notes, and snippets.

Avatar

Matt McFarland MattMcFarland

  • Software Engineer
  • Dayton, OH
View GitHub Profile
View chance random user.js
const Chance = require('chance')
const chance = new Chance()
chance.mixin({
user: () => ({
first: chance.first(),
last: chance.last(),
email: chance.email()
})
});
console.log('here is a random user!', chance.user())
View jsc check vs checkForAll.js
jsc.checkForall(jsc.integer, jsc.integer, (a, b) => a + b === b + a)
// is the same as
jsc.check(jsc.forall(jsc.integer, jsc.integer, (a, b) => a + b === b + a))
View jsc options.js
const options = {
tests: 5, // test count to run, default 100
size: 50, // maximum size of generated values, default 50
quiet: false, // do not console.log if true
rngState: '074e9b5f037a8c21d6', // state string for the rng
}
View jsverify and tape.js
test('addition is commutative', (t) => {
t.plan(1)
t.equal(jsc.checkForall(jsc.integer, jsc.integer, (a, b) => a + b === b + a), true)
})
@MattMcFarland
MattMcFarland / jsverify jasmine.js
Last active Oct 29, 2018
js verify with jasmine
View jsverify jasmine.js
describe('Maths', () => {
it('addition is commutative', () => {
expect(jsc.checkForall(jsc.integer, jsc.integer, (a, b) => a + b === b + a)).toBeTrue()
})
})
@MattMcFarland
MattMcFarland / with chai.js
Created Mar 15, 2017
js verify with chai
View with chai.js
// using should:
jsc.checkForall(jsc.integer, jsc.integer, (a, b) => a + b === b + a).should.be.true
// using expect:
expect(jsc.checkForall(jsc.integer, jsc.integer, (a, b) => a + b === b + a)).to.be.true
@MattMcFarland
MattMcFarland / with mocha.js
Last active Mar 10, 2018
jsverify with mocha
View with mocha.js
describe('Maths', () => {
it('addition is commutative', () => {
jsc.assertForall(jsc.integer, jsc.integer, (a, b) => a + b === b + a)
// same as:
assert(jsc.checkForall(jsc.integer, jsc.integer, (a, b) => a + b === b + a) === true)
})
})
@MattMcFarland
MattMcFarland / jsvNode.js
Created Mar 15, 2017
jsverify with node
View jsvNode.js
// node assertion library
assert(jsc.checkForall(jsc.integer, jsc.integer, (a, b) => a + b === b + a) === true)
// same as:
jsc.assertForall(jsc.integer, jsc.integer, (a, b) => a + b === b + a)
@MattMcFarland
MattMcFarland / js-verify-simple-example.js
Last active Mar 15, 2017
A simple example using JS Verify
View js-verify-simple-example.js
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 })
@MattMcFarland
MattMcFarland / failure-example.js
Last active Mar 15, 2017
An example of what happens when JS Verify fails a test
View failure-example.js
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 })