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)
def testCoefficientMap(self): double = lambda x: 2 * x two_x = formalsum.ListFormalSum([("x", 2)]) self.assertEqual(two_x, self.x.coefficients_map(double))
def testScalarMul(self): d = formalsum.ListFormalSum([('x', 2)]) self.assertEqual(d, self.x * 2) self.assertEqual(d, 2 * self.x)
def testNested(self): n = formalsum.ListFormalSum([(self.x, self.x)]) self.assertEqual(self.x, n[self.x])
def testSubtract(self): z = formalsum.ListFormalSum([('x', 1), ('y', -1)]) self.assertEqual(z, self.x - self.y) self.assertEqual(-z, self.y - self.x)
def testNeg(self): mx = formalsum.ListFormalSum([('x', -1)]) self.assertEqual(mx, -self.x)
def setUp(self): self.x = formalsum.ListFormalSum([("x", 1)]) self.y = formalsum.ListFormalSum([("y", 1)]) self.zero = formalsum.ListFormalSum([])