MCPcopy Index your code
hub / github.com/python/cpython / test_initial_keyword

Method test_initial_keyword

Lib/test/test_functools.py:1115–1135  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1113
1114 # test correctness of keyword usage of `initial` in `reduce`
1115 def test_initial_keyword(self):
1116 def add(x, y):
1117 return x + y
1118 self.assertEqual(
1119 self.reduce(add, ['a', 'b', 'c'], ''),
1120 self.reduce(add, ['a', 'b', 'c'], initial=''),
1121 )
1122 self.assertEqual(
1123 self.reduce(add, [['a', 'c'], [], ['d', 'w']], []),
1124 self.reduce(add, [['a', 'c'], [], ['d', 'w']], initial=[]),
1125 )
1126 self.assertEqual(
1127 self.reduce(lambda x, y: x*y, range(2,8), 1),
1128 self.reduce(lambda x, y: x*y, range(2,8), initial=1),
1129 )
1130 self.assertEqual(
1131 self.reduce(lambda x, y: x*y, range(2,21), 1),
1132 self.reduce(lambda x, y: x*y, range(2,21), initial=1),
1133 )
1134 self.assertRaises(TypeError, self.reduce, add, [0, 1], initial="")
1135 self.assertEqual(self.reduce(42, "", initial="1"), "1") # func is never called with one item
1136
1137
1138@unittest.skipUnless(c_functools, 'requires the C _functools module')

Callers

nothing calls this directly

Calls 3

reduceMethod · 0.80
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected