New method Expression.subs
[linpy.git] / pypol / tests / test_linexprs.py
index 1606ea0..5862351 100644 (file)
@@ -145,6 +145,18 @@ class TestExpression(unittest.TestCase):
         self.assertEqual((self.x + self.y/2 + self.z/3)._toint(),
                 6*self.x + 3*self.y + 2*self.z)
 
         self.assertEqual((self.x + self.y/2 + self.z/3)._toint(),
                 6*self.x + 3*self.y + 2*self.z)
 
+    def test_subs(self):
+        self.assertEqual(self.x.subs('x', 3), 3)
+        self.assertEqual(self.x.subs('x', self.x), self.x)
+        self.assertEqual(self.x.subs('x', self.y), self.y)
+        self.assertEqual(self.x.subs('x', self.x + self.y), self.x + self.y)
+        self.assertEqual(self.x.subs('y', 3), self.x)
+        self.assertEqual(self.pi.subs('x', 3), self.pi)
+        self.assertEqual(self.expr.subs('x', -3), -2 * self.y)
+        self.assertEqual(self.expr.subs([('x', self.y), ('y', self.x)]), 3 - self.x)
+        self.assertEqual(self.expr.subs({'x': self.y, 'y': self.x}), 3 - self.x)
+        self.assertEqual(self.expr.subs({self.x: self.y, self.y: self.x}), 3 - self.x)
+
     def test_fromstring(self):
         self.assertEqual(Expression.fromstring('x'), self.x)
         self.assertEqual(Expression.fromstring('-x'), -self.x)
     def test_fromstring(self):
         self.assertEqual(Expression.fromstring('x'), self.x)
         self.assertEqual(Expression.fromstring('-x'), -self.x)