def test_te_tangent(self): "Test Taylor expansion of tangent(var)" x = Variable('x') self.assertEqual(te_tangent(x, 1), x) self.assertEqual(te_tangent(x, 3), x + x**3 / 3 + 2 * x**5 / 15) self.assertEqual(te_tangent(x, 0), 0) # make sure x was not modified self.assertEqual(x, Variable('x')) # try for VectorVariable too y = VectorVariable(3, 'y') self.assertEqual(te_tangent(y, 1), y) self.assertEqual(te_tangent(y, 3), y + y**3 / 3 + 2 * y**5 / 15) self.assertEqual(te_tangent(y, 0), 0) # make sure y was not modified self.assertEqual(y, VectorVariable(3, 'y')) with self.assertRaises(NotImplementedError): _ = te_tangent(x, 16)
def test_te_tangent(self): "Test Taylor expansion of tangent(var)" x = Variable('x') self.assertEqual(te_tangent(x, 1), x) self.assertEqual(te_tangent(x, 3), x + x**3/3. + 2*x**5/15.) self.assertEqual(te_tangent(x, 0), 0) # make sure x was not modified self.assertEqual(x, Variable('x')) # try for VectorVariable too y = VectorVariable(3, 'y') self.assertEqual(te_tangent(y, 1), y) self.assertEqual(te_tangent(y, 3), y + y**3/3. + 2*y**5/15.) self.assertEqual(te_tangent(y, 0), 0) # make sure y was not modified self.assertEqual(y, VectorVariable(3, 'y'))