Giter Club home page Giter Club logo

test-allclose's Introduction

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.

js-standard-style

install

use npm

npm install test-allclose

usage

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 fails

or arrays

allclose(t)([1, 2], [1, 2])
> test passes

allclose(t)([1, 2], [1, 3])
> test fails

or 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 fails

and 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

test-allclose's People

Contributors

freeman-lab avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.