Example #1
0
 def test_append_III(self):
     """Check that append works properly when starting with an empty spline."""
     spline = CubicSpline([], [], [], [], [])
     spline.coeffs  # Trigger the lazy evaluation of coeffs
     knot = Knot(11 / 3, 2, 1, 4)
     spline.append(knot, None)
     self.assertEqual(spline.q, [knot.pos])
     self.assertEqual(spline.v, [knot.vel])
     self.assertEqual(spline.a, [knot.accel])
     self.assertEqual(spline.j, [])
     self.assertEqual(spline.t, [knot.time])
     self.assertEqual(spline.h, [])
     self.polys_coeffs_check(spline)
Example #2
0
 def test_append_II(self):
     """Similar to test_append, but the evaluation of coeffs is forced prior
     to appending the new knot."""
     spline = CubicSpline([0, 1 / 6, 1], [0, 1 / 2, 1], [0, 1, 0], [1, -1],
                          [0, 1, 2])
     knot = Knot(11 / 3, 2, 1, 4)  # calculated with jerk = 1/2
     spline.coeffs  # Trigger the lazy evaluation of coeffs
     spline.append(knot, 1 / 2)
     self.assertEqual(spline.q, [0, 1 / 6, 1, 11 / 3])
     self.assertEqual(spline.v, [0, 1 / 2, 1, 2])
     self.assertEqual(spline.a, [0, 1, 0, 1])
     self.assertEqual(spline.j, [1, -1, 1 / 2])
     self.assertEqual(spline.t, [0, 1, 2, 4])
     self.assertEqual(spline.h, [1, 1, 2])
     self.polys_coeffs_check(spline)
Example #3
0
    def test_append(self):
        spline = CubicSpline([0, 1 / 6, 1], [0, 1 / 2, 1], [0, 1, 0], [1, -1],
                             [0, 1, 2])
        knot = Knot(11 / 3, 2, 1, 4)  # calculated with jerk = 1/2
        spline.append(knot, 1 / 2)
        self.assertEqual(spline.q, [0, 1 / 6, 1, 11 / 3])
        self.assertEqual(spline.v, [0, 1 / 2, 1, 2])
        self.assertEqual(spline.a, [0, 1, 0, 1])
        self.assertEqual(spline.j, [1, -1, 1 / 2])
        self.assertEqual(spline.t, [0, 1, 2, 4])
        self.assertEqual(spline.h, [1, 1, 2])
        self.polys_coeffs_check(spline)

        bad_knot = Knot(0, 0, 0, 1)  # The time is too early
        self.assertRaises(SplineError, spline.append, bad_knot, None)