Skip to content

Commit 47abb19

Browse files
JDBetteridgemloubout
authored andcommitted
tests: Add tests for very simple derivatives
1 parent 2dd24f4 commit 47abb19

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
@@ -1250,3 +1250,38 @@ def test_fallback_wrong_custom_size(self):
12501250
exp1 = - .5 * (v._subs(x, x - x.spacing) - v._subs(x, x + x.spacing))/x.spacing
12511251
assert simplify(eq0.rhs - exp0) == 0
12521252
assert simplify(eq1.rhs - exp1) == 0
1253+
1254+
1255+
class TestDimension:
1256+
"""
1257+
Check the few cases where differentiating a dimension is allowed work correctly
1258+
and errors are raised otherwise.
1259+
"""
1260+
1261+
@classmethod
1262+
def setup_class(cls):
1263+
cls.grid = Grid(shape=(11, 11), extent=(1, 1))
1264+
cls.x, cls.y = cls.grid.dimensions
1265+
u = TimeFunction(name='u', grid=cls.grid, space_order=1)
1266+
cls.t = u.time_dim
1267+
1268+
def test_constant(self):
1269+
assert Derivative(self.x, self.x) == 1
1270+
1271+
def test_null(self):
1272+
assert Derivative(self.x, (self.x, 2)) == 0
1273+
assert Derivative(self.x, self.x, self.y) == 0
1274+
assert Derivative(self.x, self.x, self.y) == 0
1275+
assert Derivative(self.x, self.x, self.y, self.t) == 0
1276+
assert Derivative(self.x, self.y, self.t, self.x) == 0
1277+
assert Derivative(self.x, self.y, self.t, (self.x, 2)) == 0
1278+
1279+
def test_error(self):
1280+
with pytest.raises(ValueError):
1281+
Derivative(self.x, self.t)
1282+
1283+
with pytest.raises(ValueError):
1284+
Derivative(self.x, self.y, self.t)
1285+
1286+
with pytest.raises(ValueError):
1287+
Derivative(self.x, (self.x, 0))

0 commit comments

Comments
 (0)