Skip to content

Commit c040c29

Browse files
committed
tests: Add tests for very simple derivatives
1 parent 1e1fb06 commit c040c29

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

tests/test_derivatives.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,3 +1229,38 @@ def test_expand_product_rule(self):
12291229
+ 10*self.f*Derivative(self.v, self.x)*Derivative(self.u, self.x) \
12301230
+ 5*self.f*self.u*Derivative(self.v, (self.x, 2))
12311231
assert diffify(expr.expand(product_rule=True)) == expanded
1232+
1233+
1234+
class TestDimension:
1235+
"""
1236+
Check the few cases where differentiating a dimension is allowed work correctly
1237+
and errors are raised otherwise.
1238+
"""
1239+
1240+
@classmethod
1241+
def setup_class(cls):
1242+
cls.grid = Grid(shape=(11, 11), extent=(1, 1))
1243+
cls.x, cls.y = cls.grid.dimensions
1244+
u = TimeFunction(name='u', grid=cls.grid, space_order=1)
1245+
cls.t = u.time_dim
1246+
1247+
def test_constant(self):
1248+
assert Derivative(self.x, self.x) == 1
1249+
1250+
def test_null(self):
1251+
assert Derivative(self.x, (self.x, 2)) == 0
1252+
assert Derivative(self.x, self.x, self.y) == 0
1253+
assert Derivative(self.x, self.x, self.y) == 0
1254+
assert Derivative(self.x, self.x, self.y, self.t) == 0
1255+
assert Derivative(self.x, self.y, self.t, self.x) == 0
1256+
assert Derivative(self.x, self.y, self.t, (self.x, 2)) == 0
1257+
1258+
def test_error(self):
1259+
with pytest.raises(ValueError):
1260+
Derivative(self.x, self.t)
1261+
1262+
with pytest.raises(ValueError):
1263+
Derivative(self.x, self.y, self.t)
1264+
1265+
with pytest.raises(ValueError):
1266+
Derivative(self.x, (self.x, 0))

0 commit comments

Comments
 (0)