Exemplo n.º 1
0
    def test_completing_with_multiplying_four_items(self):

        def multiply(a, b):
            return a * b

        multiplying = completing(multiply, identity=1)

        result = transduce(Transducer,
                           multiplying,
                           [4, 2, 1, 9])
        self.assertEqual(result, 72)
Exemplo n.º 2
0
    def test_completing_with_summing_four_items(self):

        def add(a, b):
            return a + b

        summing = completing(add, identity=0)

        result = transduce(Transducer,
                           summing,
                           [4, 2, 1, 9])
        self.assertEqual(result, 16)
Exemplo n.º 3
0
    def test_completing_with_multiplying_zero_items_returns_identity(self):

        def multiply(a, b):
            return a * b

        multiplying = completing(multiply, identity=1)

        result = transduce(Transducer,
                           multiplying,
                           [])
        self.assertEqual(result, 1)
Exemplo n.º 4
0
    def test_completing_with_summing_zero_items_returns_identity(self):

        def add(a, b):
            return a + b

        summing = completing(add, identity=0)

        result = transduce(Transducer,
                           summing,
                           [])
        self.assertEqual(result, 0)