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

Method test_small_stability

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

Source from the content-addressed store, hash-verified

129 check("stability", x, s)
130
131 def test_small_stability(self):
132 from itertools import product
133 from operator import itemgetter
134
135 # Exhaustively test stability across all lists of small lengths
136 # and only a few distinct elements.
137 # This can provoke edge cases that randomization is unlikely to find.
138 # But it can grow very expensive quickly, so don't overdo it.
139 NELTS = 3
140 MAXSIZE = 9
141
142 pick0 = itemgetter(0)
143 for length in range(MAXSIZE + 1):
144 # There are NELTS ** length distinct lists.
145 for t in product(range(NELTS), repeat=length):
146 xs = list(zip(t, range(length)))
147 # Stability forced by index in each element.
148 forced = sorted(xs)
149 # Use key= to hide the index from compares.
150 native = sorted(xs, key=pick0)
151 self.assertEqual(forced, native)
152#==============================================================================
153
154class TestBugs(unittest.TestCase):

Callers

nothing calls this directly

Calls 3

itemgetterClass · 0.90
listClass · 0.85
assertEqualMethod · 0.45

Tested by

no test coverage detected