Created
February 28, 2016 17:24
-
-
Save nphyx/c6634aae73e29523635a to your computer and use it in GitHub Desktop.
A simple should.js extension for testing approximate values for array-like things. Works like approximately, but with arrays. Usage: [9.3567, 1.23456, 1.11112].should.be.nearly([9.36, 1.24, 1.12], 0.01);
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
const should = require("should"); | |
should.Assertion.add("nearly", function(arr, delta) { | |
try { | |
for(let i = 0, len = arr.length; i < len; i++) { | |
this.obj[i].should.be.approximately(arr[i], delta); | |
} | |
} | |
catch(e) { | |
throw new Error("expected ["+this.obj.toString()+"] to be approximately ["+arr.toString()+"] ± "+delta); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment