示例#1
0
    def testSumStringFunctions(self):
        for i in xrange(11):
            left, right = self.simple[:i], self.simple[i:]

            leftSumming = Sum("_ + 1")
            rightSumming = Sum("datum + 1")

            for _ in left:
                leftSumming.fill(_)
            for _ in right:
                rightSumming.fill(_)

            self.assertAlmostEqual(leftSumming.sum, sum(left) + len(left))
            self.assertAlmostEqual(rightSumming.sum, sum(right) + len(right))

            finalResult = leftSumming + rightSumming

            self.assertAlmostEqual(finalResult.sum,
                                   sum(self.simple) + len(self.simple))

            self.checkScaling(leftSumming)
            self.checkScaling(leftSumming.toImmutable())
            self.checkJson(leftSumming)
            self.checkPickle(leftSumming)
            self.checkName(leftSumming)
示例#2
0
    def testSum(self):
        for i in xrange(11):
            left, right = self.simple[:i], self.simple[i:]

            leftSumming = Sum(named("something", lambda x: x))
            rightSumming = Sum(named("something", lambda x: x))

            for _ in left:
                leftSumming.fill(_)
            for _ in right:
                rightSumming.fill(_)

            self.assertAlmostEqual(leftSumming.sum, sum(left))
            self.assertAlmostEqual(rightSumming.sum, sum(right))

            finalResult = leftSumming + rightSumming

            self.assertAlmostEqual(finalResult.sum, sum(self.simple))

            self.checkScaling(leftSumming)
            self.checkScaling(leftSumming.toImmutable())
            self.checkJson(leftSumming)
            self.checkPickle(leftSumming)
            self.checkName(leftSumming)