Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial import from 'jquery/qunit.git:addons/close-enough'.
Tree: https://github.com/jquery/qunit/tree/2400acdcd142c47ee8bc4ce51ca5921b14255cf8/addons/close-enough
- Loading branch information
1 parent
394ac3d
commit 1a3f742
Showing
12 changed files
with
247 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,14 +1,8 @@ | |||
lib-cov | .project | ||
*.seed | *~ | ||
*.log | *.diff | ||
*.csv | *.patch | ||
*.dat | .DS_Store | ||
*.out | .settings | ||
*.pid | node_modules | ||
*.gz | dist/ | ||
|
|||
pids | |||
logs | |||
results | |||
|
|||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,29 @@ | |||
{ | |||
"globals": { | |||
"QUnit": false | |||
}, | |||
|
|||
"bitwise": true, | |||
"camelcase": true, | |||
"curly": true, | |||
"eqeqeq": true, | |||
"forin": true, | |||
"immed": true, | |||
"latedef": false, | |||
"newcap": true, | |||
"noarg": true, | |||
"noempty": true, | |||
"nonew": true, | |||
"plusplus": false, | |||
"quotmark": "double", | |||
"undef": true, | |||
"unused": true, | |||
"trailing": true, | |||
|
|||
"proto": true, | |||
"sub": true, | |||
|
|||
"browser": true, | |||
|
|||
"onevar": true | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
Jörn Zaefferer <joern.zaefferer@gmail.com> <JZA@JZA-R60> | |||
Jörn Zaefferer <joern.zaefferer@gmail.com> | |||
Michael Righi <michael@righi.me> | |||
Timo Tijhof <krinklemail@gmail.com> | |||
James M. Greene <james.m.greene@gmail.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
language: node_js | |||
node_js: | |||
- "0.8" | |||
- "0.10" | |||
before_script: | |||
- npm install -g grunt-cli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
Michael Righi <michael@righi.me> | |||
Jörn Zaefferer <joern.zaefferer@gmail.com> | |||
Timo Tijhof <krinklemail@gmail.com> | |||
James M. Greene <james.m.greene@gmail.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,23 @@ | |||
/*jshint node:true */ | |||
module.exports = function(grunt) { | |||
|
|||
grunt.loadNpmTasks("grunt-git-authors"); | |||
grunt.loadNpmTasks("grunt-contrib-jshint"); | |||
grunt.loadNpmTasks("grunt-contrib-qunit"); | |||
|
|||
grunt.initConfig({ | |||
jshint: { | |||
options: { | |||
jshintrc: ".jshintrc" | |||
}, | |||
all: ["*.js", "test/**/*.js"] | |||
}, | |||
qunit: { | |||
all: ["test/index.html"] | |||
} | |||
}); | |||
|
|||
grunt.registerTask("test", ["jshint", "qunit"]); | |||
grunt.registerTask("default", ["test"]); | |||
|
|||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,21 @@ | |||
Copyright 2013 jQuery Foundation and other contributors | |||
http://jquery.com/ | |||
|
|||
Permission is hereby granted, free of charge, to any person obtaining | |||
a copy of this software and associated documentation files (the | |||
"Software"), to deal in the Software without restriction, including | |||
without limitation the rights to use, copy, modify, merge, publish, | |||
distribute, sublicense, and/or sell copies of the Software, and to | |||
permit persons to whom the Software is furnished to do so, subject to | |||
the following conditions: | |||
|
|||
The above copyright notice and this permission notice shall be | |||
included in all copies or substantial portions of the Software. | |||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,4 +1,26 @@ | |||
qunit-assert-close | # QUnit Close assertion plugin | ||
================== | |||
|
|
||
A QUnit plugin for asserting that a number is approximately equal (or not) to an expected number, within a given tolerance. | This plugin for [QUnit](https://github.com/jquery/qunit) adds `close` and `notClose` assertion methods | ||
to test that a number is approximately equal (or not) to an expected number, within a given tolerance. | |||
|
|||
### Usage ### | |||
|
|||
```js | |||
assert.close(actual, expected, maxDifference, message); | |||
assert.notClose(actual, expected, minDifference, message); | |||
``` | |||
|
|||
Where: | |||
- `maxDifference`: the maximum inclusive difference allowed (tolerance) between the `actual` and `expected` numbers | |||
- `minDifference`: the minimum exclusive difference allowed (tolerance) between the `actual` and `expected` numbers | |||
- `actual`, `expected`, `message`: The usual | |||
|
|||
### Example ### | |||
```js | |||
test('Example unit test', function(assert) { | |||
assert.close(3.141, Math.PI, 0.001); | |||
assert.notClose(3.1, Math.PI, 0.001); | |||
} | |||
``` | |||
For more examples, refer to the unit tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,43 @@ | |||
{ | |||
"name": "qunit-assert-close", | |||
"description": "A QUnit plugin for asserting that a number is approximately equal (or not) to an expected number, within a given tolerance.", | |||
"version": "1.0.0", | |||
"author": { | |||
"name": "jQuery Foundation and other contributors", | |||
"url": "https://github.com/JamesMGreene/qunit-assert-close/blob/master/AUTHORS.txt" | |||
}, | |||
"homepage": "https://github.com/JamesMGreene/qunit-assert-close", | |||
"repository": { | |||
"type": "git", | |||
"url": "git://github.com/JamesMGreene/qunit-assert-close.git" | |||
}, | |||
"bugs": { | |||
"url": "https://github.com/JamesMGreene/qunit-assert-close/issues" | |||
}, | |||
"license": { | |||
"name": "MIT", | |||
"url": "http://www.opensource.org/licenses/mit-license.php" | |||
}, | |||
"keywords": [ | |||
"qunit-plugin", | |||
"qunit-assert", | |||
"qunit", | |||
"assert", | |||
"close", | |||
"close-enough", | |||
"roughlyEquals", | |||
"closeTo", | |||
"approximate" | |||
], | |||
"main": "qunit-assert-close.js", | |||
"scripts": { | |||
"test": "grunt test" | |||
}, | |||
"devDependencies": { | |||
"grunt": "~0.4.1", | |||
"grunt-contrib-jshint": "~0.4.3", | |||
"grunt-contrib-qunit": "~0.2.1", | |||
"grunt-git-authors": "~1.2.0", | |||
"qunitjs": "1.x" | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,32 @@ | |||
QUnit.extend( QUnit.assert, { | |||
/** | |||
* Checks that the first two arguments are equal, or are numbers close enough to be considered equal | |||
* based on a specified maximum allowable difference. | |||
* | |||
* @example assert.close(3.141, Math.PI, 0.001); | |||
* | |||
* @param Number actual | |||
* @param Number expected | |||
* @param Number maxDifference (the maximum inclusive difference allowed between the actual and expected numbers) | |||
* @param String message (optional) | |||
*/ | |||
close: function(actual, expected, maxDifference, message) { | |||
var passes = (actual === expected) || Math.abs(actual - expected) <= maxDifference; | |||
QUnit.push(passes, actual, expected, message); | |||
}, | |||
|
|||
/** | |||
* Checks that the first two arguments are numbers with differences greater than the specified | |||
* minimum difference. | |||
* | |||
* @example assert.notClose(3.1, Math.PI, 0.001); | |||
* | |||
* @param Number actual | |||
* @param Number expected | |||
* @param Number minDifference (the minimum exclusive difference allowed between the actual and expected numbers) | |||
* @param String message (optional) | |||
*/ | |||
notClose: function(actual, expected, minDifference, message) { | |||
QUnit.push(Math.abs(actual - expected) > minDifference, actual, expected, message); | |||
} | |||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,37 @@ | |||
QUnit.module("qunit-assert-close plugin unit tests"); | |||
|
|||
QUnit.test("Close Numbers", function(assert) { | |||
var halfPi = Math.PI / 2, | |||
sqrt2 = Math.sqrt(2); | |||
|
|||
assert.close(7, 7, 0); | |||
assert.close(7, 7.1, 0.1); | |||
assert.close(7, 7.1, 0.2); | |||
|
|||
assert.close(3.141, Math.PI, 0.001); | |||
assert.close(3.1, Math.PI, 0.1); | |||
|
|||
assert.close(halfPi, 1.57, 0.001); | |||
|
|||
assert.close(sqrt2, 1.4142, 0.0001); | |||
|
|||
assert.close(Infinity, Infinity, 1); | |||
}); | |||
|
|||
QUnit.test("Distant Numbers", function(assert) { | |||
var halfPi = Math.PI / 2, | |||
sqrt2 = Math.sqrt(2); | |||
|
|||
assert.notClose(6, 7, 0); | |||
assert.notClose(7, 7.2, 0.1); | |||
assert.notClose(7, 7.2, 0.19999999999); | |||
|
|||
assert.notClose(3.141, Math.PI, 0.0001); | |||
assert.notClose(3.1, Math.PI, 0.001); | |||
|
|||
assert.notClose(halfPi, 1.57, 0.0001); | |||
|
|||
assert.notClose(sqrt2, 1.4142, 0.00001); | |||
|
|||
assert.notClose(Infinity, -Infinity, 5); | |||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,14 @@ | |||
<!DOCTYPE html> | |||
<html> | |||
<head> | |||
<meta charset="UTF-8"> | |||
<title>qunit-assert-close plugin unit tests</title> | |||
<link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css"> | |||
<script src="../node_modules/qunitjs/qunit/qunit.js"></script> | |||
<script src="../qunit-assert-close.js"></script> | |||
<script src="close-test.js"></script> | |||
</head> | |||
<body> | |||
<div id="qunit"></div> | |||
</body> | |||
</html> |