def test_dict_form(self):
     test_spline = csp.CubicSpline([1., 2., 3.], [4., 5., 6.], [7., 8., 9.])
     self.assertEqual(test_spline.dict_form, {
         'xlist': [1., 2., 3.],
         'ylist': [4., 5., 6.],
         'Mlist': [7., 8., 9.]
     })
 def setUp(self):
     """Method executed once before every test."""
     rnd.seed(0)
     self.xvals = [rnd.random() for _ in range(5)]
     self.yvals = [rnd.random() for _ in range(5)]
     self.Mvals = [rnd.random() for _ in range(5)]
     self.test_spline = csp.CubicSpline(self.xvals, self.yvals, self.Mvals)
     print(f"Executing {self._testMethodName}")
 def test_eval_zero_interval(self):
     test_x = [1., 1.]
     test_y = [2., 2.]
     test_M = [3., 3.]
     # Create the spline
     test_spline = csp.CubicSpline(test_x, test_y, test_M)
     # Do the check
     self.assertIsNone(test_spline.eval(5.))
 def test_eval_extrapolation_right(self):
     test_x = [0., 1., 3., 4.5, 5.]
     test_y = [2., -1., 0.5, 3., 1.]
     test_M = [0., 1., 3., 0., -1.]
     # Create the spline
     test_spline = csp.CubicSpline(test_x, test_y, test_M)
     # Do the checks
     self.assertIsInstance(test_spline.eval(6.), float)
 def test_eval_single_point(self):
     test_x = [1.]
     test_y = [1.]
     test_M = [1.]
     # Create the spline
     test_spline = csp.CubicSpline(test_x, test_y, test_M)
     # Do the check
     self.assertEqual(test_spline.eval(4.9), test_x[0])
 def test_eval_empty(self):
     test_x = []
     test_y = []
     test_M = []
     # Create the spline
     test_spline = csp.CubicSpline(test_x, test_y, test_M)
     # Do the check
     self.assertIsNone(test_spline.eval(1.))
 def test_eval(self):
     test_x = [0., 1., 3., 4.5, 5.]
     test_y = [2., -1., 0.5, 3., 1.]
     test_M = [0., 1., 3., 0., -1.]
     test_points = [1., 1.5, 1.7, 2.3, 4.6]
     ref_vals = [-1., -1.3125, -1.3395, -0.9805, 2.608]
     # Create the spline
     test_spline = csp.CubicSpline(test_x, test_y, test_M)
     # Do the checks
     for i, point in enumerate(test_points):
         val = test_spline.eval(point)
         self.assertAlmostEqual(
             val,
             ref_vals[i],
             delta=1e-4,
             msg=
             f"Value in {point} should be {ref_vals[i]}, while it is {val}")