Skip to content

Commit

Permalink
Fixes for sympy (#4253)
Browse files Browse the repository at this point in the history
  • Loading branch information
kratman authored Jul 9, 2024
1 parent 65f2c82 commit 0cc59d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
14 changes: 8 additions & 6 deletions tests/unit/test_expression_tree/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,24 @@ def test_to_equation(self):
self.assertEqual(func.to_equation(), sympy.Symbol("test"))

# Test Arcsinh
self.assertEqual(pybamm.Arcsinh(a).to_equation(), sympy.asinh(a))
self.assertEqual(pybamm.Arcsinh(a).to_equation(), sympy.asinh("a"))

# Test Arctan
self.assertEqual(pybamm.Arctan(a).to_equation(), sympy.atan(a))
self.assertEqual(pybamm.Arctan(a).to_equation(), sympy.atan("a"))

# Test Exp
self.assertEqual(pybamm.Exp(a).to_equation(), sympy.exp(a))
self.assertEqual(pybamm.Exp(a).to_equation(), sympy.exp("a"))

# Test log
self.assertEqual(pybamm.Log(54.0).to_equation(), sympy.log(54.0))
value = 54.0
self.assertEqual(pybamm.Log(value).to_equation(), sympy.log(value))

# Test sinh
self.assertEqual(pybamm.Sinh(a).to_equation(), sympy.sinh(a))
self.assertEqual(pybamm.Sinh(a).to_equation(), sympy.sinh("a"))

# Test Function
self.assertEqual(pybamm.Function(np.log, 10).to_equation(), 10.0)
value = 10
self.assertEqual(pybamm.Function(np.log, value).to_equation(), value)

def test_to_from_json_error(self):
a = pybamm.Symbol("a")
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/test_expression_tree/test_unary_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,18 +699,19 @@ def test_to_equation(self):
self.assertEqual(pybamm.Floor(-2.5).to_equation(), sympy.Symbol("test"))

# Test Negate
self.assertEqual(pybamm.Negate(4).to_equation(), -4.0)
value = 4
self.assertEqual(pybamm.Negate(value).to_equation(), -value)

# Test AbsoluteValue
self.assertEqual(pybamm.AbsoluteValue(-4).to_equation(), 4.0)
self.assertEqual(pybamm.AbsoluteValue(-value).to_equation(), value)

# Test Gradient
self.assertEqual(pybamm.Gradient(a).to_equation(), sympy_Gradient("a"))

# Test Divergence
self.assertEqual(
pybamm.Divergence(pybamm.Gradient(a)).to_equation(),
sympy_Divergence(sympy_Gradient(a)),
sympy_Divergence(sympy_Gradient("a")),
)

# Test BoundaryValue
Expand Down

0 comments on commit 0cc59d9

Please sign in to comment.