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

Method test_reverse_stability

Lib/test/test_sort.py:267–281  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

265 self.assertEqual(data, list(range(99,-1,-1)))
266
267 def test_reverse_stability(self):
268 data = [(random.randrange(100), i) for i in range(200)]
269 copy1 = data[:]
270 copy2 = data[:]
271 def my_cmp(x, y):
272 x0, y0 = x[0], y[0]
273 return (x0 > y0) - (x0 < y0)
274 def my_cmp_reversed(x, y):
275 x0, y0 = x[0], y[0]
276 return (y0 > x0) - (y0 < x0)
277 data.sort(key=cmp_to_key(my_cmp), reverse=True)
278 copy1.sort(key=cmp_to_key(my_cmp_reversed))
279 self.assertEqual(data, copy1)
280 copy2.sort(key=lambda x: x[0], reverse=True)
281 self.assertEqual(data, copy2)
282
283#==============================================================================
284def check_against_PyObject_RichCompareBool(self, L):

Callers

nothing calls this directly

Calls 4

cmp_to_keyFunction · 0.90
randrangeMethod · 0.80
sortMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected