Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions _unittests/ut_pycode/test_extunittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,24 @@ def test_arr(self):
self.assertRaise(lambda: self.assertEqualArray(None, df),
AssertionError)

def test_arr_decimal(self):
from numpy import array
df = array([[0, 1], [1, 2.01]])
df1 = array([[0, 1], [1, 2]])
self.assertEqualArray(df, df1, decimal=1)

def test_arr_atol(self):
from numpy import array
df = array([[0.5, 1], [1, 2]])
df1 = array([[0, 1], [1, 2]])
self.assertEqualArray(df, df1, atol=0.5)

def test_arr_rtol(self):
from numpy import array
df = array([[0, 1], [1, 2.2]])
df1 = array([[0, 1], [1, 2]])
self.assertEqualArray(df, df1, rtol=0.11)

def test_nan(self):
from numpy import array, nan
df = array([[nan, 1], [1, 2]])
Expand Down
13 changes: 8 additions & 5 deletions src/pyquickhelper/pycode/unittestclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,15 @@ def assertEqualArray(self, d1, d2, squeeze=False, **kwargs):
raise AssertionError("d1 is None, d2 is not")
if d2 is None:
raise AssertionError("d1 is not None, d2 is")
from numpy.testing import assert_almost_equal
import numpy
from numpy.testing import assert_almost_equal, assert_allclose
from numpy import squeeze
if squeeze:
d1 = numpy.squeeze(d1)
d2 = numpy.squeeze(d2)
assert_almost_equal(d1, d2, **kwargs)
d1 = squeeze(d1)
d2 = squeeze(d2)
if 'decimal' in kwargs:
assert_almost_equal(d1, d2, **kwargs)
else:
assert_allclose(d1, d2, **kwargs)

def assertHasNoNan(self, a): # pylint: disable=W0221
"""
Expand Down