jeudi 21 juillet 2016

"Almost Equal" in Jasmine

The Story:

In Python built-in unittest framework, there is an "approximate equality" assertion implemented via assertAlmostEqual() method:

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

Which has the number of decimal places to check configurable.

And, there is a numpy.testing.assert_almost_equal() which also works for the arrays of floats:

import numpy.testing as npt
import numpy as np

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

The Question:

How to make an "almost equal" assertion in Jasmine for floats and array of floats?

Aucun commentaire:

Enregistrer un commentaire