1.1.0 • Published 10 years ago
test-allclose v1.1.0
test-allclose
Utility for tape to compare numbers, arrays, or nested arrays up to some tolerance, with helpful error output on test failure. Uses allclose and inspired by test-fuzzy-array.
install
use npm
npm install test-allcloseusage
require with
var allclose = require('test-allclose')then use with a test instance t of tape or similar
var close = allclose(t)to get a function close(a, b, [atol], [rtol]) that, when called on two arrays a and b, will execute tests using the test instance t and generate useful output on test failure
examples
setup tests using tape as usual
var test = require('tape')then inside a test call
test('arrays', function (t) {
allclose(t)([1, 2], [1, 3])
t.end()
})you can test numbers
allclose(t)(1, 1)
> test passes
allclose(t)(1, 2)
> test failsor arrays
allclose(t)([1, 2], [1, 2])
> test passes
allclose(t)([1, 2], [1, 3])
> test failsor nested arrays
allclose(t)([[1, 2], [3, 4]], [[1, 2], [3, 4]])
> test passes
allclose(t)([[1, 2], [3, 4]], [[1, 2], [3, 5]])
> test failsand you can optionally specify a tolerance
allclose(t)([1, 2], [1, 2.1])
> test fails
allclose(t)([1, 2], [1, 2.1], 0.3)
> test passes