MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_initial_keyword

Method test_initial_keyword

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

Source from the content-addressed store, hash-verified

1049
1050 # test correctness of keyword usage of `initial` in `reduce`
1051 def test_initial_keyword(self):
1052 def add(x, y):
1053 return x + y
1054 self.assertEqual(
1055 self.reduce(add, ['a', 'b', 'c'], ''),
1056 self.reduce(add, ['a', 'b', 'c'], initial=''),
1057 )
1058 self.assertEqual(
1059 self.reduce(add, [['a', 'c'], [], ['d', 'w']], []),
1060 self.reduce(add, [['a', 'c'], [], ['d', 'w']], initial=[]),
1061 )
1062 self.assertEqual(
1063 self.reduce(lambda x, y: x*y, range(2,8), 1),
1064 self.reduce(lambda x, y: x*y, range(2,8), initial=1),
1065 )
1066 self.assertEqual(
1067 self.reduce(lambda x, y: x*y, range(2,21), 1),
1068 self.reduce(lambda x, y: x*y, range(2,21), initial=1),
1069 )
1070 self.assertRaises(TypeError, self.reduce, add, [0, 1], initial="")
1071 self.assertEqual(self.reduce(42, "", initial="1"), "1") # func is never called with one item
1072
1073
1074@unittest.skipUnless(c_functools, 'requires the C _functools module')

Callers

nothing calls this directly

Calls 3

assertEqualMethod · 0.45
reduceMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected