+ self.x = Expression({'x': 1})
+ self.y = Expression({'y': 1})
+ self.z = Expression({'z': 1})
+ self.zero = Expression(constant=0)
+ self.one = Expression(constant=1)
+ self.pi = Expression(constant=Fraction(22, 7))
+ self.expr = self.x - 2*self.y + 3
+
+ def test_new_subclass(self):
+ self.assertIsInstance(self.x, Symbol)
+ self.assertIsInstance(self.pi, Constant)
+ self.assertNotIsInstance(self.x + self.pi, Symbol)
+ self.assertNotIsInstance(self.x + self.pi, Constant)
+ xx = Expression({'x': 2})
+ self.assertNotIsInstance(xx, Symbol)
+
+ def test_new_types(self):
+ with self.assertRaises(TypeError):
+ Expression('x + y', 2)
+ self.assertEqual(Expression({'x': 2}), Expression({self.x: 2}))
+ with self.assertRaises(TypeError):
+ Expression({0: 2})
+ with self.assertRaises(TypeError):
+ Expression({'x': '2'})
+ self.assertEqual(Expression(constant=1), Expression(constant=self.one))
+ with self.assertRaises(TypeError):
+ Expression(constant='1')