Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_input_discrete(self):
t = np.array( [0, 1, 1, 1, 2])
y = np.array([[0, 0, 4, 3, 3]])
# extrapolate left
v = Input.interpolate(-1, t, y)
self.assertEqual(v, 0, "Expecting first value")
# hit sample
v = Input.interpolate(0, t, y)
self.assertEqual(v, 0, "Expecting value at sample")
# interpolate
v = Input.interpolate(0.5, t, y)
self.assertEqual(v, 0, "Expecting to hold previous value")
# before event
v = Input.interpolate(1, t, y)
self.assertEqual(v, 0, "Expecting value before event")
# after event
v = Input.interpolate(1, t, y, after_event=True)
v1, v2 = Input.interpolate(-1, t, y)
self.assertEqual(v1, 0)
self.assertEqual(v2, -1)
# hit sample
v1, v2 = Input.interpolate(1, t, y)
self.assertEqual(v1, 0)
self.assertEqual(v2, 0)
# interpolate (linear)
v1, v2 = Input.interpolate(1.5, t, y)
self.assertAlmostEqual(v1, 1.5)
self.assertAlmostEqual(v2, 0.5)
# extrapolate right (hold)
v1, v2 = Input.interpolate(4, t, y)
self.assertEqual(v1, 3)
self.assertEqual(v2, 2)
y = np.array([[0, 0, 4, 3, 3]])
# extrapolate left
v = Input.interpolate(-1, t, y)
self.assertEqual(v, 0, "Expecting first value")
# hit sample
v = Input.interpolate(0, t, y)
self.assertEqual(v, 0, "Expecting value at sample")
# interpolate
v = Input.interpolate(0.5, t, y)
self.assertEqual(v, 0, "Expecting to hold previous value")
# before event
v = Input.interpolate(1, t, y)
self.assertEqual(v, 0, "Expecting value before event")
# after event
v = Input.interpolate(1, t, y, after_event=True)
self.assertEqual(v, 3, "Expecting value after event")
# extrapolate right
v = Input.interpolate(3, t, y)
self.assertEqual(v, 3, "Expecting last value")
def test_input_discrete(self):
t = np.array( [0, 1, 1, 1, 2])
y = np.array([[0, 0, 4, 3, 3]])
# extrapolate left
v = Input.interpolate(-1, t, y)
self.assertEqual(v, 0, "Expecting first value")
# hit sample
v = Input.interpolate(0, t, y)
self.assertEqual(v, 0, "Expecting value at sample")
# interpolate
v = Input.interpolate(0.5, t, y)
self.assertEqual(v, 0, "Expecting to hold previous value")
# before event
v = Input.interpolate(1, t, y)
self.assertEqual(v, 0, "Expecting value before event")
# after event
v = Input.interpolate(1, t, y, after_event=True)
self.assertEqual(v, 3, "Expecting value after event")
# extrapolate right
v = Input.interpolate(3, t, y)
self.assertEqual(v, 3, "Expecting last value")
self.assertEqual(v, 0, "Expecting value at sample")
# interpolate
v = Input.interpolate(0.5, t, y)
self.assertEqual(v, 0, "Expecting to hold previous value")
# before event
v = Input.interpolate(1, t, y)
self.assertEqual(v, 0, "Expecting value before event")
# after event
v = Input.interpolate(1, t, y, after_event=True)
self.assertEqual(v, 3, "Expecting value after event")
# extrapolate right
v = Input.interpolate(3, t, y)
self.assertEqual(v, 3, "Expecting last value")
def test_input_continuous(self):
t = np.array( [ 0, 1, 2, 3])
y = np.array([[ 0, 0, 3, 3],
[-1, 0, 1, 2]])
# extrapolate left (hold)
v1, v2 = Input.interpolate(-1, t, y)
self.assertEqual(v1, 0)
self.assertEqual(v2, -1)
# hit sample
v1, v2 = Input.interpolate(1, t, y)
self.assertEqual(v1, 0)
self.assertEqual(v2, 0)
# interpolate (linear)
v1, v2 = Input.interpolate(1.5, t, y)
self.assertAlmostEqual(v1, 1.5)
self.assertAlmostEqual(v2, 0.5)
# extrapolate right (hold)
v1, v2 = Input.interpolate(4, t, y)
self.assertEqual(v1, 3)
self.assertEqual(v, 0, "Expecting first value")
# hit sample
v = Input.interpolate(0, t, y)
self.assertEqual(v, 0, "Expecting value at sample")
# interpolate
v = Input.interpolate(0.5, t, y)
self.assertEqual(v, 0, "Expecting to hold previous value")
# before event
v = Input.interpolate(1, t, y)
self.assertEqual(v, 0, "Expecting value before event")
# after event
v = Input.interpolate(1, t, y, after_event=True)
self.assertEqual(v, 3, "Expecting value after event")
# extrapolate right
v = Input.interpolate(3, t, y)
self.assertEqual(v, 3, "Expecting last value")