diff --git a/.travis.yml b/.travis.yml index b0f0775f..a4426161 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,3 +50,4 @@ matrix: if: type != pull_request addons: sauce_connect: true + - env: JASMINE_LONG_PROPERTY_TESTS=y diff --git a/package.json b/package.json index e2ba236f..bc602f6f 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "ejs": "^2.5.5", "eslint": "^5.16.0", "express": "^4.16.4", + "fast-check": "^1.21.0", "fast-glob": "^2.2.6", "grunt": "^1.0.4", "grunt-cli": "^1.3.2", diff --git a/spec/property/matchersUtilSpec.js b/spec/property/matchersUtilSpec.js new file mode 100644 index 00000000..384a1f14 --- /dev/null +++ b/spec/property/matchersUtilSpec.js @@ -0,0 +1,69 @@ +describe('matchersUtil -- property tests', function() { + 'use strict'; + var fc = require('fast-check'); + + function basicAnythingSettings() { + return { + key: fc.oneof(fc.string(), fc.constantFrom('k1', 'k2', 'k3')), + // Limiting depth & number of keys allows fast-check to try + // a lot more scalar values. + maxDepth: 2, + maxKeys: 5, + withBoxedValues: true, + withMap: true, + withSet: true + }; + } + + function numRuns() { + var many = 5000000; + + // Be thorough but very slow when specified (usually on CI). + if (process.env.JASMINE_LONG_PROPERTY_TESTS) { + console.log( + 'Using', + many, + 'runs of fc.assert because JASMINE_LONG_PROPERTY_TESTS was set. This may take several minutes.' + ); + return many; + } else { + return undefined; + } + } + + describe('equals', function() { + it('is symmetric', function() { + fc.assert( + fc.property( + fc.anything(basicAnythingSettings()), + fc.anything(basicAnythingSettings()), + function(a, b) { + return ( + jasmineUnderTest.matchersUtil.equals(a, b) === + jasmineUnderTest.matchersUtil.equals(b, a) + ); + } + ), + { + numRuns: numRuns(), + examples: [[0, 5e-324]] + } + ); + }); + + it('is reflexive', function() { + var anythingSettings = basicAnythingSettings(); + anythingSettings.withMap = false; + fc.assert( + fc.property(fc.dedup(fc.anything(anythingSettings), 2), function( + values + ) { + return jasmineUnderTest.matchersUtil.equals(values[0], values[1]); + }), + { + numRuns: numRuns() + } + ); + }); + }); +}); diff --git a/spec/support/jasmine-browser.js b/spec/support/jasmine-browser.js index 41c9e703..bbc9c4ac 100644 --- a/spec/support/jasmine-browser.js +++ b/spec/support/jasmine-browser.js @@ -15,7 +15,7 @@ module.exports = { '**/*.js' ], specDir: 'spec', - specFiles: ['**/*[Ss]pec.js', '!npmPackage/**/*'], + specFiles: ['**/*[Ss]pec.js', '!npmPackage/**/*', '!property/**/*'], helpers: [ 'helpers/asyncAwait.js', 'helpers/BrowserFlags.js', diff --git a/spec/support/jasmine.json b/spec/support/jasmine.json index 033207ec..6ce73409 100644 --- a/spec/support/jasmine.json +++ b/spec/support/jasmine.json @@ -2,6 +2,7 @@ "spec_dir": "spec", "spec_files": [ "core/**/*[Ss]pec.js", + "property/**/*[Ss]pec.js", "npmPackage/**/*[Ss]pec.js" ], "helpers": [