예제 #1
0
    def minmax_y(self):
        def r(accu, item):
            min_y = min(accu[0], item[0])
            max_y = max(accu[1], item[1])
            return min_y, max_y

        minmax_accu = transduce(transducer=pipe(
            mapping(lambda p: p.minmax_y()), reducing(r)),
                                reducer=expecting_single(),
                                iterable=self.paths)

        return minmax_accu
예제 #2
0
 def test_counting_with_predicate(self):
     result = transduce(transducer=counting(lambda w: 'o' in w),
                        reducer=expecting_single(),
                        iterable="The quick brown fox jumped".split())
     self.assertEqual(result, 2)
예제 #3
0
 def test_counting(self):
     result = transduce(transducer=counting(),
                        reducer=expecting_single(),
                        iterable="The quick brown fox jumped".split())
     self.assertEqual(result, 5)
예제 #4
0
 def test_last_with_predicate(self):
     result = transduce(transducer=last(lambda x: x < 7),
                        reducer=expecting_single(),
                        iterable=[2, 4, 6, 8, 10])
     self.assertEqual(result, 6)
예제 #5
0
 def test_last(self):
     result = transduce(transducer=last(),
                        reducer=expecting_single(),
                        iterable=[2, 4, 6, 8, 10])
     self.assertEqual(result, 10)
예제 #6
0
 def test_element_at_too_short(self):
     with self.assertRaises(IndexError):
         transduce(transducer=element_at(3),
                   reducer=expecting_single(),
                   iterable=[1, 3, 5])
예제 #7
0
 def test_element_at_validation(self):
     with self.assertRaises(IndexError):
         transduce(transducer=element_at(-1),
                            reducer=expecting_single(),
                            iterable=[1, 3, 5, 7, 9])
예제 #8
0
 def test_exactly_one_item(self):
     result = transduce(mapping(lambda x: x*x),
                        expecting_single(),
                        [42])
     self.assertEqual(result, 1764)
예제 #9
0
 def test_reducing_with_init(self):
     result = transduce(transducer=reducing(operator.add, 10),
                        reducer=expecting_single(),
                        iterable=range(10))
     self.assertEqual(result, 55)
예제 #10
0
 def test_counting_with_predicate(self):
     result = transduce(transducer=counting(lambda w: 'o' in w),
                        reducer=expecting_single(),
                        iterable="The quick brown fox jumped".split())
     self.assertEqual(result, 2)
예제 #11
0
 def test_counting(self):
     result = transduce(transducer=counting(),
                        reducer=expecting_single(),
                        iterable="The quick brown fox jumped".split())
     self.assertEqual(result, 5)
예제 #12
0
 def test_last_with_predicate(self):
     result = transduce(transducer=last(lambda x: x < 7),
                        reducer=expecting_single(),
                        iterable=[2, 4, 6, 8, 10])
     self.assertEqual(result, 6)
예제 #13
0
 def test_last(self):
     result = transduce(transducer=last(),
                        reducer=expecting_single(),
                        iterable=[2, 4, 6, 8, 10])
     self.assertEqual(result, 10)
예제 #14
0
 def test_element_at_too_short(self):
     with self.assertRaises(IndexError):
         transduce(transducer=element_at(3),
                   reducer=expecting_single(),
                   iterable=[1, 3, 5])
예제 #15
0
 def test_reducing_with_init(self):
     result = transduce(transducer=reducing(operator.add, 10),
                        reducer=expecting_single(),
                        iterable=range(10))
     self.assertEqual(result, 55)
예제 #16
0
 def test_element_at(self):
     result = transduce(transducer=element_at(3),
                        reducer=expecting_single(),
                        iterable=[1, 3, 5, 7, 9])
     self.assertEqual(result, 7)
예제 #17
0
 def test_element_at_validation(self):
     with self.assertRaises(IndexError):
         transduce(transducer=element_at(-1),
                   reducer=expecting_single(),
                   iterable=[1, 3, 5, 7, 9])
예제 #18
0
 def test_too_many_items(self):
     with self.assertRaises(RuntimeError):
         transduce(mapping(lambda x: x*x),
                   expecting_single(),
                   [])
예제 #19
0
 def test_element_at(self):
     result = transduce(transducer=element_at(3),
                        reducer=expecting_single(),
                        iterable=[1, 3, 5, 7, 9])
     self.assertEqual(result, 7)