diff --git a/interfaces/cython/cantera/test/test_func1.py b/interfaces/cython/cantera/test/test_func1.py index b8672d45d42..c7a135a836a 100644 --- a/interfaces/cython/cantera/test/test_func1.py +++ b/interfaces/cython/cantera/test/test_func1.py @@ -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([], [])