Skip to content

Commit

Permalink
#858 improve coverage, document exception for InputParameter in evalu…
Browse files Browse the repository at this point in the history
…ate_ignoring_errors
  • Loading branch information
martinjrobins committed Mar 18, 2020
1 parent fa5373e commit d21f0b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pybamm/expression_tree/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,10 @@ def is_constant(self):
def evaluate_ignoring_errors(self, t=0):
"""
Evaluates the expression. If a node exists in the tree that cannot be evaluated
as a scalar or vector (e.g. Time, Parameter, Variable, StateVector,
InputParameter), then None is returned. Otherwise the result of the evaluation
is given
as a scalar or vector (e.g. Time, Parameter, Variable, StateVector), then None
is returned. If there is an InputParameter in the tree then a 1 is returned.
Otherwise the result of the evaluation is given.
See Also
--------
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_expression_tree/test_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ def test_symbol_evaluation(self):
with self.assertRaises(NotImplementedError):
a.evaluate()

def test_evaluate_ignoring_errors(self):
self.assertIsNone(pybamm.t.evaluate_ignoring_errors(t=None))
self.assertEqual(pybamm.t.evaluate_ignoring_errors(t=0), 0)
self.assertIsNone(pybamm.Parameter("a").evaluate_ignoring_errors())
self.assertIsNone(pybamm.StateVector(slice(0,1)).evaluate_ignoring_errors())
self.assertEqual(pybamm.InputParameter("a").evaluate_ignoring_errors(), 1)

def test_symbol_is_constant(self):
a = pybamm.Variable("a")
self.assertFalse(a.is_constant())
Expand Down

0 comments on commit d21f0b6

Please sign in to comment.