Skip to content

Commit

Permalink
[numerics] Add unit tests for tabulated Func1
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Jan 22, 2020
1 parent 1c48f8a commit 75cee19
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions interfaces/cython/cantera/test/test_func1.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,34 @@ def test_uncopyable(self):
f = ct.Func1(np.sin)
with self.assertRaises(NotImplementedError):
copy.copy(f)


class TestTabulated1(utilities.CanteraTest):
def test_tabulated1(self):
time = [0, 1, 2]
fval = [2, 1, 0]
fcn = ct.TabulatedFcn(time, fval)
for t, f in zip(time, fval):
self.assertNear(f, fcn(t))

def test_tabulated2(self):
time = np.array([0, 1, 2])
fval = np.array([2, 1, 0])
fcn = ct.TabulatedFcn(time, fval)
tt = .5*(time[1:] + time[:-1])
ff = .5*(fval[1:] + fval[:-1])
for t, f in zip(tt, ff):
self.assertNear(f, fcn(t))

def test_tabulated2(self):
time = 0, 1, 2,
fval = 2, 1, 0,
fcn = ct.TabulatedFcn(time, fval)
self.assertNear(fcn(-1), fval[0])
self.assertNear(fcn(3), fval[-1])

def test_failure(self):
with self.assertRaisesRegex(ct.CanteraError, 'do not match'):
ct.TabulatedFcn(range(2), range(3))
with self.assertRaisesRegex(ct.CanteraError, 'must not be empty'):
ct.TabulatedFcn([], [])

0 comments on commit 75cee19

Please sign in to comment.