Skip to content

Commit

Permalink
#19: Plural error and test
Browse files Browse the repository at this point in the history
  • Loading branch information
jwallwork23 committed Apr 4, 2024
1 parent ecd42b5 commit 1e50f28
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion movement/tangling.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def check(self):
sj = self.scaled_jacobian.dat.data_with_halos
num_tangled = len(sj[sj < 0])
if num_tangled > 0:
msg = f"Mesh has {num_tangled} tangled elements."
plural = "s" if num_tangled > 1 else ""
msg = f"Mesh has {num_tangled} tangled element{plural}."
if self.raise_error:
raise ValueError(msg)
warnings.warn(msg)
Expand Down
15 changes: 12 additions & 3 deletions test/test_tangling.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,25 @@ class TestTangling(unittest.TestCase):
Unit tests for mesh tangling checking.
"""

def test_tangling_checker_error(self):
def test_tangling_checker_error1(self):
mesh = UnitSquareMesh(3, 3)
checker = MeshTanglingChecker(mesh, raise_error=True)
mesh.coordinates.dat.data[3] += 0.2
with self.assertRaises(ValueError) as cm:
checker.check()
msg = "Mesh has 1 tangled elements."
msg = "Mesh has 1 tangled element."
self.assertEqual(str(cm.exception), msg)

def test_tangling_checker_warning(self):
def test_tangling_checker_error2(self):
mesh = UnitSquareMesh(3, 3)
checker = MeshTanglingChecker(mesh, raise_error=True)
mesh.coordinates.dat.data[3] += 0.5
with self.assertRaises(ValueError) as cm:
checker.check()
msg = "Mesh has 3 tangled elements."
self.assertEqual(str(cm.exception), msg)

def test_tangling_checker_warning1(self):
mesh = UnitSquareMesh(3, 3)
checker = MeshTanglingChecker(mesh, raise_error=False)
self.assertEqual(checker.check(), 0)
Expand Down

0 comments on commit 1e50f28

Please sign in to comment.