From 92e9e08097493b1639d54b141c482820197302b5 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Fri, 29 Apr 2016 22:10:25 -0400 Subject: [PATCH] [Test] Show largest error component in assertArrayNear --- interfaces/cython/cantera/test/utilities.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/interfaces/cython/cantera/test/utilities.py b/interfaces/cython/cantera/test/utilities.py index 8a53ff6a7..c8f0a02fa 100644 --- a/interfaces/cython/cantera/test/utilities.py +++ b/interfaces/cython/cantera/test/utilities.py @@ -32,8 +32,21 @@ class CanteraTest(unittest.TestCase): A = np.asarray(A) B = np.asarray(B) - for a,b in zip(A.flat, B.flat): - self.assertNear(a,b, rtol, atol, msg) + worst = 0, '' + for i in np.ndindex(A.shape): + a = A[i] + b = B[i] + cmp = 2 * abs(a - b)/(abs(a) + abs(b) + 2 * atol / rtol) + if cmp > rtol: + message = ('AssertNear: {:.14g} - {:.14g} = {:.14g}\n'.format(a, b, a-b) + + 'Relative error for element {} of {:10e} exceeds rtol = {:10e}'.format(i, cmp, rtol)) + if msg: + message = msg + '\n' + message + if cmp > worst[0]: + worst = cmp, message + + if worst[0]: + self.fail(worst[1]) def compare(self, data, reference_file): """