test-fuzzy-array
v1.0.1
Published
tap/tape utility to compare arrays with an epislon
Downloads
46
Maintainers
Readme
test-fuzzy-array
A tap/tape utility to compare arrays with an epislon value. Defaults to float epsilon, and provides clear logging on test pass/failure.
var test = require('tape')
var Fuzz = require('test-fuzzy-array')
test('compares arrays with an epislon', function(t) {
var epsilon = 0.01
var almostEqual = Fuzz(t, epsilon)
almostEqual(['foo', 1, 0.0025], ['foo', 1, 0.0026])
t.end()
})
Result:
Usage
almostEqual = Fuzz(t[, epsilon[, relativeTolerance]])
Returns an almostEqual
function that operates on the given test
instance of tape, tap and similar interfaces. Epsilon defaults to float precision. Relative tolerance defaults to epsilon value.
The function has the signature:
almostEqual(value, expected, msg)
notAlmostEqual = almostEqual.not
The return value of Fuzz has a not
function which is the negated version.
Examples:
var Fuzzy = require('test-fuzzy-array')
test('arrays are almost equal', function(t) {
var almostEqual = Fuzzy(t)
var notAlmostEqual = almostEqual.not
almostEqual(['foo', 1, 1], ['foo', 1, 1 + 1e-12])
notAlmostEqual([], ['foo', 1, 0.0026])
t.end()
})
License
MIT, see LICENSE.md for details.