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

Method test_lookups_with_key_function

Lib/test/test_bisect.py:203–234  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

201 self.assertEqual(data, [10, 20, 25, 25, 25, 30, 40, 50])
202
203 def test_lookups_with_key_function(self):
204 mod = self.module
205
206 # Invariant: Index with a keyfunc on an array
207 # should match the index on an array where
208 # key function has already been applied.
209
210 keyfunc = abs
211 arr = sorted([2, -4, 6, 8, -10], key=keyfunc)
212 precomputed_arr = list(map(keyfunc, arr))
213 for x in precomputed_arr:
214 self.assertEqual(
215 mod.bisect_left(arr, x, key=keyfunc),
216 mod.bisect_left(precomputed_arr, x)
217 )
218 self.assertEqual(
219 mod.bisect_right(arr, x, key=keyfunc),
220 mod.bisect_right(precomputed_arr, x)
221 )
222
223 keyfunc = str.casefold
224 arr = sorted('aBcDeEfgHhiIiij', key=keyfunc)
225 precomputed_arr = list(map(keyfunc, arr))
226 for x in precomputed_arr:
227 self.assertEqual(
228 mod.bisect_left(arr, x, key=keyfunc),
229 mod.bisect_left(precomputed_arr, x)
230 )
231 self.assertEqual(
232 mod.bisect_right(arr, x, key=keyfunc),
233 mod.bisect_right(precomputed_arr, x)
234 )
235
236 def test_insort(self):
237 from random import shuffle

Callers

nothing calls this directly

Calls 2

listClass · 0.85
assertEqualMethod · 0.45

Tested by

no test coverage detected