示例#1
0
 def testAdd(self):
     z = formalsum.ListFormalSum([('x', 1), ('y', 1)])
     d = formalsum.ListFormalSum([('x', 2)])
     self.assertEqual(z, self.x + self.y)
     self.assertEqual(d, self.x + self.x)
     self.assertEqual(self.x, self.x + self.zero)
     self.assertEqual(self.x, self.zero + self.x)
示例#2
0
 def testCoefficientMap(self):
     double = lambda x: 2 * x
     two_x = formalsum.ListFormalSum([("x", 2)])
     self.assertEqual(two_x, self.x.coefficients_map(double))
示例#3
0
 def testScalarMul(self):
     d = formalsum.ListFormalSum([('x', 2)])
     self.assertEqual(d, self.x * 2)
     self.assertEqual(d, 2 * self.x)
示例#4
0
 def testNested(self):
     n = formalsum.ListFormalSum([(self.x, self.x)])
     self.assertEqual(self.x, n[self.x])
示例#5
0
 def testSubtract(self):
     z = formalsum.ListFormalSum([('x', 1), ('y', -1)])
     self.assertEqual(z, self.x - self.y)
     self.assertEqual(-z, self.y - self.x)
示例#6
0
 def testNeg(self):
     mx = formalsum.ListFormalSum([('x', -1)])
     self.assertEqual(mx, -self.x)
示例#7
0
 def setUp(self):
     self.x = formalsum.ListFormalSum([("x", 1)])
     self.y = formalsum.ListFormalSum([("y", 1)])
     self.zero = formalsum.ListFormalSum([])