Skip to content

Commit

Permalink
Use np.allclose() in mulgrid unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
acroucher committed Feb 20, 2020
1 parent 489f03c commit 59d5217
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions tests/test_mulgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def get_well_positions(self): return np.array(sum([w.pos for w in self.welllist]
def compare(self, other, testcase):
"""Compares self with another mulgrid_stats object and reports results
to a unittest testcase."""
tol = 1.e-7
wellpostol = 0.06 # need larger tolerance for well positions, due to roundoff
msg = ' mismatch for geometry ' + self.filename
testcase.assertEqual(self.type, other.type, 'type' + msg)
Expand Down Expand Up @@ -107,27 +106,26 @@ def test_rect_grid_operations(self):
self.assertEqual(geo.num_layers, num_layers + 1)
self.assertEqual(geo.num_blocks, num_blocks)
# check area and centre:
tol = 1.e-7
lx = np.sum(dx)
ly = np.sum(dy)
a = lx * ly
c = 0.5*np.array([lx, ly])
self.assertAlmostEqual(geo.area, a)
self.assertTrue(np.linalg.norm(geo.centre - c) <= tol)
self.assertTrue(np.allclose(geo.centre, c))
# translate, rotate:
d = np.array([5321.5, -1245.2, 1000.])
theta = 37.6
geo.translate(d)
c2 = c + d[:2]
self.assertAlmostEqual(geo.area, a)
self.assertTrue(np.linalg.norm(geo.centre - c2) <= tol)
self.assertTrue(np.allclose(geo.centre, c2))
geo.rotate(theta)
self.assertAlmostEqual(geo.area, a)
self.assertTrue(np.linalg.norm(geo.centre - c2) <= tol)
self.assertTrue(np.allclose(geo.centre, c2))
geo.rotate(-theta)
geo.translate(-d)
self.assertAlmostEqual(geo.area, a)
self.assertTrue(np.linalg.norm(geo.centre - c) <= tol)
self.assertTrue(np.allclose(geo.centre, c))

def test_read_g2(self):
"""reading g2 geometry"""
Expand Down Expand Up @@ -214,7 +212,7 @@ def test_fit_surface(self):
geo.fit_surface(d, alpha = 0.1, beta = 0.1, silent = True)
s = np.array([col.surface for col in cols])
r = np.load(os.path.join('mulgrid', 'fit_surface_result.npy'))
self.assertTrue((np.abs(s - r) <= tol).all())
self.assertTrue(np.allclose(s, r, atol = tol))

def test_refine(self):
"""refine()"""
Expand All @@ -229,7 +227,7 @@ def test_refine(self):
self.assertEqual(geo.num_nodes, 169)
areas = np.sort(np.array([col.area for col in geo.columnlist]))
a = np.sort(np.load(os.path.join('mulgrid', 'refine_areas.npy')))
self.assertTrue((np.abs(areas - a) <= tol).all())
self.assertTrue(np.allclose(areas, a, atol = tol))

def test_rename_column(self):
"""rename_column()"""
Expand Down

0 comments on commit 59d5217

Please sign in to comment.