Skip to content

Commit

Permalink
#617 improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rtimms committed Oct 1, 2019
1 parent ce9c04c commit 4775e42
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
25 changes: 16 additions & 9 deletions tests/unit/test_meshes/test_one_dimensional_submesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def test_symmetric_mesh_creation_no_parameters(self):
}

submesh_types = {
"negative particle": pybamm.GetExponential1DSubMesh(side="symmetric")
"negative particle": pybamm.GetExponential1DSubMesh(
side="symmetric", stretch=1.5
)
}
var_pts = {r: 20}
mesh = pybamm.Mesh(geometry, submesh_types, var_pts)
Expand Down Expand Up @@ -77,7 +79,7 @@ def test_left_mesh_creation_no_parameters(self):
submesh_types = {
"negative particle": pybamm.GetExponential1DSubMesh(side="left")
}
var_pts = {r: 20}
var_pts = {r: 21}
mesh = pybamm.Mesh(geometry, submesh_types, var_pts)

# create mesh
Expand Down Expand Up @@ -170,21 +172,26 @@ def test_exceptions(self):
# test too many lims
with self.assertRaises(pybamm.GeometryError):
mesh(lims, None)
lims = [0, 1]

# error if len(edges) != npts+1
x_n = pybamm.standard_spatial_vars.x_n

# error if npts+1 != len(edges)
lims = {x_n: {"min": 0, "max": 1}}
npts = {x_n.id: 10}
with self.assertRaises(pybamm.GeometryError):
mesh(lims, 5)
mesh(lims, npts)

# error if lims[0] not equal to edges[0]
lims = [0.1, 1]
lims = {x_n: {"min": 0.1, "max": 1}}
npts = {x_n.id: len(edges) - 1}
with self.assertRaises(pybamm.GeometryError):
mesh(lims, len(edges) - 1)
mesh(lims, npts)

# error if lims[-1] not equal to edges[-1]
lims = [0, 0.9]
lims = {x_n: {"min": 0, "max": 10}}
npts = {x_n.id: len(edges) - 1}
with self.assertRaises(pybamm.GeometryError):
mesh(lims, len(edges) - 1)
mesh(lims, npts)

def test_mesh_creation_no_parameters(self):
r = pybamm.SpatialVariable(
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_meshes/test_scikit_fem_submesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,12 @@ def test_exceptions(self):
with self.assertRaises(pybamm.GeometryError):
mesh(lims, npts)

# error if different coordinate system
lims = {var.y: {"min": 0, "max": 1}, var.r_n: {"min": 0, "max": 1}}
npts = {var.y.id: 3, var.r_n.id: 3}
with self.assertRaises(pybamm.DomainError):
mesh(lims, npts)


if __name__ == "__main__":
print("Add -v for more debug output")
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test_meshes/test_zero_dimensional_submesh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pybamm
import unittest


class TestSubMesh0D(unittest.TestCase):
def test_exceptions(self):
position = {"x": 0, "y": 0}
with self.assertRaises(pybamm.GeometryError):
pybamm.SubMesh0D(position)

def test_init(self):
position = {"x": 1}
mesh = pybamm.SubMesh0D(position)
mesh.add_ghost_meshes()


if __name__ == "__main__":
print("Add -v for more debug output")
import sys

if "-v" in sys.argv:
debug = True
pybamm.settings.debug_mode = True
unittest.main()

0 comments on commit 4775e42

Please sign in to comment.