Skip to content

Instantly share code, notes, and snippets.

View MattMcFarland's full-sized avatar

Matt McFarland MattMcFarland

  • Software Engineer
  • Dayton, OH
View GitHub Profile
@MattMcFarland
MattMcFarland / chance random and js verify.js
Created March 15, 2017 00:11
chance random and js verify
const jsc = require('jsverify')
const Chance = require('chance')
const chance = new Chance()
chance.mixin({
user: () => ({
first: chance.first(),
last: chance.last(),
email: chance.email()
})
})
@MattMcFarland
MattMcFarland / chance random user.js
Created March 15, 2017 00:10
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())
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))
@MattMcFarland
MattMcFarland / jsc options.js
Last active March 15, 2017 07:16
jsc options
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
}
@MattMcFarland
MattMcFarland / jsverify and tape.js
Last active March 15, 2017 07:03
js verify with tape
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 October 29, 2018 14:44
js verify with jasmine
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 March 15, 2017 00:07
js verify with chai
// 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 March 10, 2018 19:47
jsverify with mocha
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 March 15, 2017 00:05
jsverify with node
// 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 March 15, 2017 06:46
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 })