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
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)
def test_counting(self): result = transduce(transducer=counting(), reducer=expecting_single(), iterable="The quick brown fox jumped".split()) self.assertEqual(result, 5)
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)
def test_last(self): result = transduce(transducer=last(), reducer=expecting_single(), iterable=[2, 4, 6, 8, 10]) self.assertEqual(result, 10)
def test_element_at_too_short(self): with self.assertRaises(IndexError): transduce(transducer=element_at(3), reducer=expecting_single(), iterable=[1, 3, 5])
def test_element_at_validation(self): with self.assertRaises(IndexError): transduce(transducer=element_at(-1), reducer=expecting_single(), iterable=[1, 3, 5, 7, 9])
def test_exactly_one_item(self): result = transduce(mapping(lambda x: x*x), expecting_single(), [42]) self.assertEqual(result, 1764)
def test_reducing_with_init(self): result = transduce(transducer=reducing(operator.add, 10), reducer=expecting_single(), iterable=range(10)) self.assertEqual(result, 55)
def test_element_at(self): result = transduce(transducer=element_at(3), reducer=expecting_single(), iterable=[1, 3, 5, 7, 9]) self.assertEqual(result, 7)
def test_too_many_items(self): with self.assertRaises(RuntimeError): transduce(mapping(lambda x: x*x), expecting_single(), [])