self.assertEqual(self.x.subs(self.y, 3), self.x)
self.assertEqual(self.pi.subs(self.x, 3), self.pi)
self.assertEqual(self.expr.subs(self.x, -3), -2 * self.y)
- self.assertEqual(self.expr.subs([(self.x, self.y), (self.y, self.x)]), 3 - self.x)
+ self.assertEqual(self.expr.subs([(self.x, self.y), (self.y, self.x)]), -2*self.x + self.y + 3)
self.assertEqual(self.expr.subs({self.x: self.z, self.y: self.z}), 3 - self.z)
self.assertEqual(self.expr.subs({self.x: self.z, self.y: self.z}), 3 - self.z)
with self.assertRaises(TypeError):
self.assertEqual(LinExpr.fromsympy(sp_x), self.x)
self.assertEqual(LinExpr.fromsympy(sympy.Rational(22, 7)), self.pi)
self.assertEqual(LinExpr.fromsympy(sp_x - 2*sp_y + 3), self.expr)
- with self.assertRaises(ValueError):
+ with self.assertRaises(TypeError):
LinExpr.fromsympy(sp_x*sp_y)
@requires_sympy
self.y = Symbol('y')
def test_new(self):
- self.assertEqual(Symbol(' x '), self.x)
+ self.assertEqual(Symbol('x'), self.x)
with self.assertRaises(TypeError):
Symbol(self.x)
with self.assertRaises(TypeError):
Symbol(1)
+ with self.assertRaises(SyntaxError):
+ Symbol('1')
+ with self.assertRaises(SyntaxError):
+ Symbol('x.1')
+ with self.assertRaises(SyntaxError):
+ Symbol('x 1')
+ Symbol('_')
+ Symbol('_x')
+ Symbol('x_1')
def test_name(self):
self.assertEqual(self.x.name, 'x')