javascript - "Almost Equal" in Jasmine -


the story:

in python built-in unittest framework, there "approximate equality" assertion implemented via assertalmostequal() method:

x = 0.1234567890 y = 0.1234567891 self.assertalmostequal(x, y) 

which has number of decimal places check configurable.

and, there numpy.testing.assert_almost_equal() works arrays of floats:

import numpy.testing npt import numpy np  npt.assert_almost_equal(np.array([1.0,2.3333333333333]), np.array([1.0,2.33333334])) 

the question:

how make "almost equal" assertion in javascript/jasmine floats , array of floats?

for single float, use tobecloseto:

expect(x).tobecloseto(y, 7) 

for float array, seems best loop on , call tobecloseto each pair of elements (or write own matcher). see expect array of float numbers close array in jasmine.


Comments